[2778] | 1 | #! /usr/bin/env python |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | |
---|
| 4 | # A notifier for PyKota |
---|
| 5 | # |
---|
| 6 | # PyKota - Print Quotas for CUPS and LPRng |
---|
| 7 | # |
---|
| 8 | # (c) 2003, 2004, 2005, 2006 Jerome Alet <alet@librelogiciel.com> |
---|
| 9 | # This program is free software; you can redistribute it and/or modify |
---|
| 10 | # it under the terms of the GNU General Public License as published by |
---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | # (at your option) any later version. |
---|
| 13 | # |
---|
| 14 | # This program is distributed in the hope that it will be useful, |
---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | # GNU General Public License for more details. |
---|
| 18 | # |
---|
| 19 | # You should have received a copy of the GNU General Public License |
---|
| 20 | # along with this program; if not, write to the Free Software |
---|
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 22 | # |
---|
| 23 | # $Id$ |
---|
| 24 | # |
---|
| 25 | # |
---|
| 26 | |
---|
| 27 | import sys |
---|
| 28 | import os |
---|
| 29 | import popen2 |
---|
| 30 | |
---|
| 31 | from pykota.tool import Tool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ |
---|
| 32 | |
---|
| 33 | __doc__ = N_("""pknotify v%(__version__)s (c) %(__years__)s %(__author__)s |
---|
| 34 | |
---|
| 35 | Notifies or ask questions to end users who launched the PyKotIcon application. |
---|
| 36 | |
---|
| 37 | command line usage : |
---|
| 38 | |
---|
| 39 | pknotify [options] [arguments] |
---|
| 40 | |
---|
| 41 | options : |
---|
| 42 | |
---|
| 43 | -v | --version Prints pkbanner's version number then exits. |
---|
| 44 | -h | --help Prints this message then exits. |
---|
| 45 | |
---|
| 46 | """) |
---|
| 47 | |
---|
| 48 | class PyKotaNotify(Tool) : |
---|
| 49 | """A class for pknotify.""" |
---|
| 50 | def main(self, arguments, options) : |
---|
| 51 | """Notifies or asks questions to end users through PyKotIcon.""" |
---|
| 52 | pass # TODO : do something ! |
---|
| 53 | |
---|
| 54 | if __name__ == "__main__" : |
---|
| 55 | retcode = 0 |
---|
| 56 | try : |
---|
| 57 | defaults = { \ |
---|
| 58 | } |
---|
| 59 | short_options = "vh" |
---|
| 60 | long_options = ["help", "version"] |
---|
| 61 | |
---|
| 62 | # Initializes the command line tool |
---|
| 63 | notifier = PyKotaNotify(doc=__doc__) |
---|
| 64 | notifier.deferredInit() |
---|
| 65 | |
---|
| 66 | # parse and checks the command line |
---|
| 67 | (options, args) = notifier.parseCommandline(sys.argv[1:], short_options, long_options, allownothing=1) |
---|
| 68 | |
---|
| 69 | # sets long options |
---|
| 70 | options["help"] = options["h"] or options["help"] |
---|
| 71 | options["version"] = options["v"] or options["version"] |
---|
| 72 | |
---|
| 73 | if options["help"] : |
---|
| 74 | notifier.display_usage_and_quit() |
---|
| 75 | elif options["version"] : |
---|
| 76 | notifier.display_version_and_quit() |
---|
| 77 | else : |
---|
| 78 | retcode = notifier.main(args, options) |
---|
| 79 | except KeyboardInterrupt : |
---|
| 80 | sys.stderr.write("\nInterrupted with Ctrl+C !\n") |
---|
| 81 | retcode = -3 |
---|
| 82 | except PyKotaCommandLineError, msg : |
---|
| 83 | sys.stderr.write("%s : %s\n" % (sys.argv[0], msg)) |
---|
| 84 | retcode = -2 |
---|
| 85 | except SystemExit : |
---|
| 86 | pass |
---|
| 87 | except : |
---|
| 88 | try : |
---|
| 89 | notifier.crashed("%s failed" % sys.argv[0]) |
---|
| 90 | except : |
---|
| 91 | crashed("%s failed" % sys.argv[0]) |
---|
| 92 | retcode = -1 |
---|
| 93 | |
---|
| 94 | sys.exit(retcode) |
---|