[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$ |
---|
[870] | 19 | # Revision 1.4 2003/03/29 09:47:00 jalet |
---|
| 20 | # More powerful installation script. |
---|
| 21 | # |
---|
[869] | 22 | # Revision 1.3 2003/03/26 17:48:36 jalet |
---|
| 23 | # First shot at trying to detect the availability of the needed software |
---|
| 24 | # during the installation. |
---|
| 25 | # |
---|
[839] | 26 | # Revision 1.2 2003/03/09 16:49:04 jalet |
---|
| 27 | # The installation script installs the man pages too now. |
---|
| 28 | # |
---|
[695] | 29 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
| 30 | # Initial import into CVS |
---|
| 31 | # |
---|
| 32 | # |
---|
| 33 | # |
---|
| 34 | |
---|
| 35 | import sys |
---|
| 36 | import glob |
---|
| 37 | import os |
---|
| 38 | from distutils.core import setup |
---|
| 39 | |
---|
| 40 | sys.path.insert(0, "pykota") |
---|
| 41 | from pykota.version import __version__, __doc__ |
---|
| 42 | |
---|
[870] | 43 | ACTION_CONTINUE = 0 |
---|
| 44 | ACTION_ABORT = 1 |
---|
| 45 | |
---|
| 46 | def checkModule(module) : |
---|
| 47 | """Checks if a Python module is available or not.""" |
---|
[869] | 48 | try : |
---|
[870] | 49 | exec "import %s" % module |
---|
[869] | 50 | except ImportError : |
---|
[870] | 51 | return 0 |
---|
| 52 | else : |
---|
| 53 | return 1 |
---|
| 54 | |
---|
| 55 | def checkCommand(command) : |
---|
| 56 | """Checks if a command is available or not.""" |
---|
| 57 | input = os.popen("type %s 2>/dev/null" % command) |
---|
| 58 | result = input.read().strip() |
---|
| 59 | input.close() |
---|
| 60 | return result |
---|
| 61 | |
---|
| 62 | def checkWithPrompt(prompt, module=None, command=None) : |
---|
| 63 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
| 64 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
| 65 | sys.stdout.flush() |
---|
| 66 | if command is not None : |
---|
| 67 | result = checkCommand(command) |
---|
| 68 | elif module is not None : |
---|
| 69 | result = checkModule(module) |
---|
| 70 | if result : |
---|
| 71 | sys.stdout.write("OK\n") |
---|
| 72 | return ACTION_CONTINUE |
---|
| 73 | else : |
---|
| 74 | sys.stdout.write("NO.\n") |
---|
| 75 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
| 76 | answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt) |
---|
| 77 | if answer[0:1].upper() == 'Y' : |
---|
| 78 | return ACTION_CONTINUE |
---|
| 79 | else : |
---|
| 80 | return ACTION_ABORT |
---|
| 81 | |
---|
| 82 | if "install" in sys.argv : |
---|
| 83 | if not (sys.version > "2.1") : |
---|
| 84 | sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
[869] | 85 | sys.exit(-1) |
---|
[870] | 86 | |
---|
| 87 | modulestocheck = [("PygreSQL", "pg"), ("mxDateTime", "mx.DateTime")] |
---|
| 88 | commandstocheck = [("SNMP Tools", "snmpget")] |
---|
| 89 | for (name, module) in modulestocheck : |
---|
| 90 | action = checkWithPrompt(name, module=module) |
---|
| 91 | if action == ACTION_ABORT : |
---|
| 92 | sys.stderr.write("Aborted !\n") |
---|
[869] | 93 | sys.exit(-1) |
---|
| 94 | |
---|
[870] | 95 | for (name, command) in commandstocheck : |
---|
| 96 | action = checkWithPrompt(name, command=command) |
---|
| 97 | if action == ACTION_ABORT : |
---|
| 98 | sys.stderr.write("Aborted !\n") |
---|
| 99 | sys.exit(-1) |
---|
| 100 | |
---|
[695] | 101 | data_files = [] |
---|
| 102 | mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"])) |
---|
| 103 | for mofile in mofiles : |
---|
| 104 | lang = mofile.split(os.sep)[1] |
---|
| 105 | directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"]) |
---|
| 106 | data_files.append((directory, [ mofile ])) |
---|
[839] | 107 | |
---|
| 108 | directory = os.sep.join(["share", "man", "man1"]) |
---|
| 109 | manpages = glob.glob(os.sep.join(["man", "*.1"])) |
---|
| 110 | data_files.append((directory, manpages)) |
---|
[695] | 111 | |
---|
| 112 | setup(name = "pykota", version = __version__, |
---|
| 113 | license = "GNU GPL", |
---|
| 114 | description = __doc__, |
---|
| 115 | author = "Jerome Alet", |
---|
| 116 | author_email = "alet@librelogiciel.com", |
---|
| 117 | url = "http://www.librelogiciel.com/software/", |
---|
| 118 | packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers" ], |
---|
| 119 | scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ], |
---|
| 120 | data_files = data_files) |
---|