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 | # This program is free software; you can redistribute it and/or modify |
---|
9 | # it under the terms of the GNU General Public License as published by |
---|
10 | # the Free Software Foundation; either version 2 of the License, or |
---|
11 | # (at your option) any later version. |
---|
12 | # |
---|
13 | # This program is distributed in the hope that it will be useful, |
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | # GNU General Public License for more details. |
---|
17 | # |
---|
18 | # You should have received a copy of the GNU General Public License |
---|
19 | # along with this program; if not, write to the Free Software |
---|
20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
21 | # |
---|
22 | # $Id$ |
---|
23 | # |
---|
24 | # $Log$ |
---|
25 | # Revision 1.8 2003/04/15 17:49:29 jalet |
---|
26 | # Installation script now checks the presence of Netatalk |
---|
27 | # |
---|
28 | # Revision 1.7 2003/04/03 20:03:37 jalet |
---|
29 | # Installation script now allows to install the sample configuration file. |
---|
30 | # |
---|
31 | # Revision 1.6 2003/03/29 13:45:26 jalet |
---|
32 | # GPL paragraphs were incorrectly (from memory) copied into the sources. |
---|
33 | # Two README files were added. |
---|
34 | # Upgrade script for PostgreSQL pre 1.01 schema was added. |
---|
35 | # |
---|
36 | # Revision 1.5 2003/03/29 13:08:28 jalet |
---|
37 | # Configuration is now expected to be found in /etc/pykota.conf instead of |
---|
38 | # in /etc/cups/pykota.conf |
---|
39 | # Installation script can move old config files to the new location if needed. |
---|
40 | # Better error handling if configuration file is absent. |
---|
41 | # |
---|
42 | # Revision 1.4 2003/03/29 09:47:00 jalet |
---|
43 | # More powerful installation script. |
---|
44 | # |
---|
45 | # Revision 1.3 2003/03/26 17:48:36 jalet |
---|
46 | # First shot at trying to detect the availability of the needed software |
---|
47 | # during the installation. |
---|
48 | # |
---|
49 | # Revision 1.2 2003/03/09 16:49:04 jalet |
---|
50 | # The installation script installs the man pages too now. |
---|
51 | # |
---|
52 | # Revision 1.1 2003/02/05 21:28:17 jalet |
---|
53 | # Initial import into CVS |
---|
54 | # |
---|
55 | # |
---|
56 | # |
---|
57 | |
---|
58 | import sys |
---|
59 | import glob |
---|
60 | import os |
---|
61 | import shutil |
---|
62 | from distutils.core import setup |
---|
63 | |
---|
64 | sys.path.insert(0, "pykota") |
---|
65 | from pykota.version import __version__, __doc__ |
---|
66 | |
---|
67 | ACTION_CONTINUE = 0 |
---|
68 | ACTION_ABORT = 1 |
---|
69 | |
---|
70 | def checkModule(module) : |
---|
71 | """Checks if a Python module is available or not.""" |
---|
72 | try : |
---|
73 | exec "import %s" % module |
---|
74 | except ImportError : |
---|
75 | return 0 |
---|
76 | else : |
---|
77 | return 1 |
---|
78 | |
---|
79 | def checkCommand(command) : |
---|
80 | """Checks if a command is available or not.""" |
---|
81 | input = os.popen("type %s 2>/dev/null" % command) |
---|
82 | result = input.read().strip() |
---|
83 | input.close() |
---|
84 | return result |
---|
85 | |
---|
86 | def checkWithPrompt(prompt, module=None, command=None) : |
---|
87 | """Tells the user what will be checked, and asks him what to do if something is absent.""" |
---|
88 | sys.stdout.write("Checking for %s availability : " % prompt) |
---|
89 | sys.stdout.flush() |
---|
90 | if command is not None : |
---|
91 | result = checkCommand(command) |
---|
92 | elif module is not None : |
---|
93 | result = checkModule(module) |
---|
94 | if result : |
---|
95 | sys.stdout.write("OK\n") |
---|
96 | return ACTION_CONTINUE |
---|
97 | else : |
---|
98 | sys.stdout.write("NO.\n") |
---|
99 | sys.stderr.write("ERROR : %s not available !\n" % prompt) |
---|
100 | answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt) |
---|
101 | if answer[0:1].upper() == 'Y' : |
---|
102 | return ACTION_CONTINUE |
---|
103 | else : |
---|
104 | return ACTION_ABORT |
---|
105 | |
---|
106 | if "install" in sys.argv : |
---|
107 | # checks if Python version is correct, we need >= 2.1 |
---|
108 | if not (sys.version > "2.1") : |
---|
109 | sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n") |
---|
110 | sys.exit(-1) |
---|
111 | |
---|
112 | # checks if a configuration file is present in the old location |
---|
113 | if os.path.isfile("/etc/cups/pykota.conf") : |
---|
114 | if not os.path.isfile("/etc/pykota.conf") : |
---|
115 | sys.stdout.write("From version 1.02 on, PyKota expects to find its configuration\nfile in /etc instead of /etc/cups.\n") |
---|
116 | sys.stdout.write("It seems that you've got a configuration file in the old location,\nso it will not be used anymore,\nand there's no configuration file in the new location.\n") |
---|
117 | answer = raw_input("Do you want to move /etc/cups/pykota.conf to /etc/pykota.conf (y/N) ? ") |
---|
118 | if answer[0:1].upper() == 'Y' : |
---|
119 | try : |
---|
120 | os.rename("/etc/cups/pykota.conf", "/etc/pykota.conf") |
---|
121 | except OSError : |
---|
122 | sys.stderr.write("ERROR : An error occured while moving /etc/cups/pykota.conf to /etc/pykota.conf\nAborted !\n") |
---|
123 | sys.exit(-1) |
---|
124 | else : |
---|
125 | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf won't be used ! Move it to /etc instead.\n") |
---|
126 | sys.stderr.write("PyKota installation will continue anyway, but the software won't run until you put a proper configuration file in /etc\n") |
---|
127 | else : |
---|
128 | sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf will not be used !\nThe file /etc/pykota.conf will be used instead.\n") |
---|
129 | elif not os.path.isfile("/etc/pykota.conf") : |
---|
130 | # no configuration file, first installation it seems. |
---|
131 | if os.path.isfile("conf/pykota.conf.sample") : |
---|
132 | answer = raw_input("Do you want to install conf/pykota.conf.sample as /etc/pykota.conf (y/N) ? ") |
---|
133 | if answer[0:1].upper() == 'Y' : |
---|
134 | try : |
---|
135 | shutil.copy("conf/pykota.conf.sample", "/etc/pykota.conf") |
---|
136 | except IOError : |
---|
137 | sys.stderr.write("WARNING : Problem while installing /etc/pykota.conf, please do it manually.\n") |
---|
138 | else : |
---|
139 | sys.stdout.write("Configuration file /etc/pykota.conf installed.\nDon't forget to adapt /etc/pykota.conf to your needs.\n") |
---|
140 | else : |
---|
141 | sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n") |
---|
142 | |
---|
143 | # checks if some needed Python modules are there or not. |
---|
144 | modulestocheck = [("PygreSQL", "pg"), ("mxDateTime", "mx.DateTime")] |
---|
145 | commandstocheck = [("SNMP Tools", "snmpget"), ("Netatalk", "pap")] |
---|
146 | for (name, module) in modulestocheck : |
---|
147 | action = checkWithPrompt(name, module=module) |
---|
148 | if action == ACTION_ABORT : |
---|
149 | sys.stderr.write("Aborted !\n") |
---|
150 | sys.exit(-1) |
---|
151 | |
---|
152 | # checks if some software are there or not. |
---|
153 | for (name, command) in commandstocheck : |
---|
154 | action = checkWithPrompt(name, command=command) |
---|
155 | if action == ACTION_ABORT : |
---|
156 | sys.stderr.write("Aborted !\n") |
---|
157 | sys.exit(-1) |
---|
158 | |
---|
159 | data_files = [] |
---|
160 | mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"])) |
---|
161 | for mofile in mofiles : |
---|
162 | lang = mofile.split(os.sep)[1] |
---|
163 | directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"]) |
---|
164 | data_files.append((directory, [ mofile ])) |
---|
165 | |
---|
166 | directory = os.sep.join(["share", "man", "man1"]) |
---|
167 | manpages = glob.glob(os.sep.join(["man", "*.1"])) |
---|
168 | data_files.append((directory, manpages)) |
---|
169 | |
---|
170 | setup(name = "pykota", version = __version__, |
---|
171 | license = "GNU GPL", |
---|
172 | description = __doc__, |
---|
173 | author = "Jerome Alet", |
---|
174 | author_email = "alet@librelogiciel.com", |
---|
175 | url = "http://www.librelogiciel.com/software/", |
---|
176 | packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers" ], |
---|
177 | scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ], |
---|
178 | data_files = data_files) |
---|