[695] | 1 | #! /usr/bin/env python |
---|
| 2 | # |
---|
| 3 | # PyKota |
---|
| 4 | # |
---|
| 5 | # PyKota : Print Quotas for CUPS |
---|
| 6 | # |
---|
| 7 | # (c) 2003 Jerome Alet <alet@librelogiciel.com> |
---|
| 8 | # You're welcome to redistribute this software under the |
---|
| 9 | # terms of the GNU General Public Licence version 2.0 |
---|
| 10 | # or, at your option, any higher version. |
---|
| 11 | # |
---|
| 12 | # You can read the complete GNU GPL in the file COPYING |
---|
| 13 | # which should come along with this software, or visit |
---|
| 14 | # the Free Software Foundation's WEB site http://www.fsf.org |
---|
| 15 | # |
---|
| 16 | # $Id$ |
---|
| 17 | # |
---|
| 18 | # $Log$ |
---|
[872] | 19 | # Revision 1.5 2003/03/29 13:08:28 jalet |
---|
| 20 | # Configuration is now expected to be found in /etc/pykota.conf instead of |
---|
| 21 | # in /etc/cups/pykota.conf |
---|
| 22 | # Installation script can move old config files to the new location if needed. |
---|
| 23 | # Better error handling if configuration file is absent. |
---|
| 24 | # |
---|
[870] | 25 | # Revision 1.4 2003/03/29 09:47:00 jalet |
---|
| 26 | # More powerful installation script. |
---|
| 27 | # |
---|
[869] | 28 | # Revision 1.3 2003/03/26 17:48:36 jalet |
---|
| 29 | # First shot at trying to detect the availability of the needed software |
---|
| 30 | # during the installation. |
---|
| 31 | # |
---|
[839] | 32 | # Revision 1.2 2003/03/09 16:49:04 jalet |
---|
| 33 | # The installation script installs the man pages too now. |
---|
| 34 | # |
---|
[695] | 35 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 36 | # Initial import into CVS |
---|
| 37 | # |
---|
| 38 | # |
---|
| 39 | # |
---|
| 40 | |
---|
| 41 | import sys |
---|
| 42 | import glob |
---|
| 43 | import os |
---|
| 44 | from distutils.core import setup |
---|
| 45 | |
---|
| 46 | sys.path.insert(0, "pykota") |
---|
| 47 | from pykota.version import __version__, __doc__ |
---|
| 48 | |
---|
[870] | 49 | ACTION_CONTINUE = 0 |
---|
| 50 | ACTION_ABORT = 1 |
---|
| 51 | |
---|
| 52 | def checkModule(module) : |
---|
| 53 | """Checks if a Python module is available or not.""" |
---|
[869] | 54 | try : |
---|
[870] | 55 | exec "import %s" % module |
---|
[869] | 56 | except ImportError : |
---|
[870] | 57 | return 0 |
---|
| 58 | else : |
---|
| 59 | return 1 |
---|
| 60 | |
---|
| 61 | def checkCommand(command) : |
---|
| 62 | """Checks if a command is available or not.""" |
---|
| 63 | input = os.popen("type %s 2>/dev/null" % command) |
---|
| 64 | result = input.read().strip() |
---|
| 65 | input.close() |
---|
| 66 | return result |
---|
| 67 | |
---|
| 68 | def checkWithPrompt(prompt, module=None, command=None) : |
---|
| 69 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
| 70 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
| 71 | sys.stdout.flush() |
---|
| 72 | if command is not None : |
---|
| 73 | result = checkCommand(command) |
---|
| 74 | elif module is not None : |
---|
| 75 | result = checkModule(module) |
---|
| 76 | if result : |
---|
| 77 | sys.stdout.write("OK\n") |
---|
| 78 | return ACTION_CONTINUE |
---|
| 79 | else : |
---|
| 80 | sys.stdout.write("NO.\n") |
---|
| 81 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
| 82 | answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt) |
---|
| 83 | if answer[0:1].upper() == 'Y' : |
---|
| 84 | return ACTION_CONTINUE |
---|
| 85 | else : |
---|
| 86 | return ACTION_ABORT |
---|
| 87 | |
---|
| 88 | if "install" in sys.argv : |
---|
[872] | 89 | # checks if Python version is correct, we need >= 2.1 |
---|
[870] | 90 | if not (sys.version > "2.1") : |
---|
| 91 | sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
[869] | 92 | sys.exit(-1) |
---|
[870] | 93 | |
---|
[872] | 94 | # checks if a configuration file is present in the old location |
---|
| 95 | if os.path.isfile("/etc/cups/pykota.conf") : |
---|
| 96 | if not os.path.isfile("/etc/pykota.conf") : |
---|
| 97 | sys.stdout.write("From version 1.02 on, PyKota expects to find its configuration file in /etc instead of /etc/cups.\n") |
---|
| 98 | sys.stdout.write("It seems that you've got a configuration file in the old location, so it will not be used anymore, and no configuration file in the new location.\n") |
---|
| 99 | answer = raw_input("Do you want me to move your configuration file to the new location in /etc (y/N) ? ") |
---|
| 100 | if answer[0:1].upper() == 'Y' : |
---|
| 101 | try : |
---|
| 102 | os.rename("/etc/cups/pykota.conf", "/etc/pykota.conf") |
---|
| 103 | except OSError : |
---|
| 104 | sys.stderr.write("ERROR : An error occured while moving /etc/cups/pykota.conf to /etc/pykota.conf\nAborted !\n") |
---|
| 105 | sys.exit(-1) |
---|
| 106 | else : |
---|
| 107 | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf won't be used ! Move it to /etc instead.\n") |
---|
| 108 | sys.stderr.write("PyKota installation will continue anyway, but the software won't run until you put a proper configuration file in /etc\n") |
---|
| 109 | else : |
---|
| 110 | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf will not be used !\nThe file /etc/pykota.conf will be used instead.\n") |
---|
| 111 | |
---|
| 112 | # checks if some needed Python modules are there or not. |
---|
[870] | 113 | modulestocheck = [("PygreSQL", "pg"), ("mxDateTime", "mx.DateTime")] |
---|
| 114 | commandstocheck = [("SNMP Tools", "snmpget")] |
---|
| 115 | for (name, module) in modulestocheck : |
---|
| 116 | action = checkWithPrompt(name, module=module) |
---|
| 117 | if action == ACTION_ABORT : |
---|
| 118 | sys.stderr.write("Aborted !\n") |
---|
[869] | 119 | sys.exit(-1) |
---|
| 120 | |
---|
[872] | 121 | # checks if some software are there or not. |
---|
[870] | 122 | for (name, command) in commandstocheck : |
---|
| 123 | action = checkWithPrompt(name, command=command) |
---|
| 124 | if action == ACTION_ABORT : |
---|
| 125 | sys.stderr.write("Aborted !\n") |
---|
| 126 | sys.exit(-1) |
---|
| 127 | |
---|
[695] | 128 | data_files = [] |
---|
| 129 | mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"])) |
---|
| 130 | for mofile in mofiles : |
---|
| 131 | lang = mofile.split(os.sep)[1] |
---|
| 132 | directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"]) |
---|
| 133 | data_files.append((directory, [ mofile ])) |
---|
[839] | 134 | |
---|
| 135 | directory = os.sep.join(["share", "man", "man1"]) |
---|
| 136 | manpages = glob.glob(os.sep.join(["man", "*.1"])) |
---|
| 137 | data_files.append((directory, manpages)) |
---|
[695] | 138 | |
---|
| 139 | setup(name = "pykota", version = __version__, |
---|
| 140 | license = "GNU GPL", |
---|
| 141 | description = __doc__, |
---|
| 142 | author = "Jerome Alet", |
---|
| 143 | author_email = "alet@librelogiciel.com", |
---|
| 144 | url = "http://www.librelogiciel.com/software/", |
---|
| 145 | packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers" ], |
---|
| 146 | scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ], |
---|
| 147 | data_files = data_files) |
---|