root / pykota / trunk / setup.py @ 1095

Revision 1095, 14.4 kB (checked in by jalet, 21 years ago)

waitprinter.sh is now included to prevent PyKota from asking the
printer's internal page counter while a job is still being printer.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2#
3# PyKota
4#
5# PyKota : Print Quotas for CUPS and LPRng
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.20  2003/07/23 16:51:32  jalet
26# waitprinter.sh is now included to prevent PyKota from asking the
27# printer's internal page counter while a job is still being printer.
28#
29# Revision 1.19  2003/07/16 21:53:07  jalet
30# Really big modifications wrt new configuration file's location and content.
31#
32# Revision 1.18  2003/07/03 09:44:00  jalet
33# Now includes the pykotme utility
34#
35# Revision 1.17  2003/06/30 12:46:15  jalet
36# Extracted reporting code.
37#
38# Revision 1.16  2003/06/06 20:49:15  jalet
39# Very latest schema. UNTESTED.
40#
41# Revision 1.15  2003/05/17 16:32:30  jalet
42# Also outputs the original import error message.
43#
44# Revision 1.14  2003/05/17 16:31:38  jalet
45# Dies gracefully if DistUtils is not present.
46#
47# Revision 1.13  2003/04/29 18:37:54  jalet
48# Pluggable accounting methods (actually doesn't support external scripts)
49#
50# Revision 1.12  2003/04/23 22:13:56  jalet
51# Preliminary support for LPRng added BUT STILL UNTESTED.
52#
53# Revision 1.11  2003/04/17 13:49:29  jalet
54# Typo
55#
56# Revision 1.10  2003/04/17 13:48:39  jalet
57# Better help
58#
59# Revision 1.9  2003/04/17 13:47:28  jalet
60# Help added during installation.
61#
62# Revision 1.8  2003/04/15 17:49:29  jalet
63# Installation script now checks the presence of Netatalk
64#
65# Revision 1.7  2003/04/03 20:03:37  jalet
66# Installation script now allows to install the sample configuration file.
67#
68# Revision 1.6  2003/03/29 13:45:26  jalet
69# GPL paragraphs were incorrectly (from memory) copied into the sources.
70# Two README files were added.
71# Upgrade script for PostgreSQL pre 1.01 schema was added.
72#
73# Revision 1.5  2003/03/29 13:08:28  jalet
74# Configuration is now expected to be found in /etc/pykota.conf instead of
75# in /etc/cups/pykota.conf
76# Installation script can move old config files to the new location if needed.
77# Better error handling if configuration file is absent.
78#
79# Revision 1.4  2003/03/29 09:47:00  jalet
80# More powerful installation script.
81#
82# Revision 1.3  2003/03/26 17:48:36  jalet
83# First shot at trying to detect the availability of the needed software
84# during the installation.
85#
86# Revision 1.2  2003/03/09 16:49:04  jalet
87# The installation script installs the man pages too now.
88#
89# Revision 1.1  2003/02/05 21:28:17  jalet
90# Initial import into CVS
91#
92#
93#
94
95import sys
96import glob
97import os
98import shutil
99try :
100    from distutils.core import setup
101except ImportError, msg :   
102    sys.stderr.write("%s\n" % msg)
103    sys.stderr.write("You need the DistUtils Python module.\nunder Debian, you may have to install the python-dev package.\nOf course, YMMV.\n")
104    sys.exit(-1)
105
106sys.path.insert(0, "pykota")
107from pykota.version import __version__, __doc__
108
109ACTION_CONTINUE = 0
110ACTION_ABORT = 1
111
112def checkModule(module) :
113    """Checks if a Python module is available or not."""
114    try :
115        exec "import %s" % module
116    except ImportError :   
117        return 0
118    else :   
119        return 1
120       
121def checkCommand(command) :
122    """Checks if a command is available or not."""
123    input = os.popen("type %s 2>/dev/null" % command)
124    result = input.read().strip()
125    input.close()
126    return result
127   
128def checkWithPrompt(prompt, module=None, command=None, helper=None) :
129    """Tells the user what will be checked, and asks him what to do if something is absent."""
130    sys.stdout.write("Checking for %s availability : " % prompt)
131    sys.stdout.flush()
132    if command is not None :
133        result = checkCommand(command)
134    elif module is not None :   
135        result = checkModule(module)
136    if result :   
137        sys.stdout.write("OK\n")
138        return ACTION_CONTINUE
139    else :   
140        sys.stdout.write("NO.\n")
141        sys.stderr.write("ERROR : %s not available !\n" % prompt)
142        if helper is not None :
143            sys.stdout.write("%s\n" % helper)
144            sys.stdout.write("You may continue safely if you don't need this functionnality.\n")
145        answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt)
146        if answer[0:1].upper() == 'Y' :
147            return ACTION_CONTINUE
148        else :
149            return ACTION_ABORT
150   
151if "install" in sys.argv :
152    # checks if Python version is correct, we need >= 2.1
153    if not (sys.version > "2.1") :
154        sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n")
155        sys.exit(-1)
156       
157    # checks if a configuration file is present in the new location
158    if not os.path.isfile("/etc/pykota/pykota.conf") :
159        if not os.path.isdir("/etc/pykota") :
160            try :
161                os.mkdir("/etc/pykota")
162            except OSError, msg :   
163                sys.stderr.write("An error occured while creating the /etc/pykota directory.\n%s\n" % msg)
164                sys.exit(-1)
165               
166        if os.path.isfile("/etc/pykota.conf") :
167            # upgrade from pre-1.14 to 1.14 and above
168            sys.stdout.write("From version 1.14 on, PyKota expects to find its configuration\nfile in /etc/pykota/ instead of /etc/\n")
169            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")
170            answer = raw_input("Do you want to move /etc/pykota.conf to /etc/pykota/pykota.conf (y/N) ? ")
171            if answer[0:1].upper() == 'Y' :
172                try :
173                    os.rename("/etc/pykota.conf", "/etc/pykota/pykota.conf")
174                except OSError :   
175                    sys.stderr.write("ERROR : An error occured while moving /etc/pykota.conf to /etc/pykota/pykota.conf\nAborted !\n")
176                    sys.exit(-1)
177                else :   
178                    sys.stdout.write("Configuration file /etc/pykota.conf moved to /etc/pykota/pykota.conf.\n")
179            else :
180                sys.stderr.write("WARNING : Configuration file /etc/pykota.conf won't be used ! Move it to /etc/pykota/ instead.\n")
181                sys.stderr.write("PyKota installation will continue anyway,\nbut the software won't run until you put a proper configuration file in /etc/pykota/\n")
182            dummy = raw_input("Please press ENTER when you have read the message above. ")
183        else :
184            # first installation
185            if os.path.isfile("conf/pykota.conf.sample") :
186                answer = raw_input("Do you want to install\n\tconf/pykota.conf.sample as /etc/pykota/pykota.conf (y/N) ? ")
187                if answer[0:1].upper() == 'Y' :
188                    try :
189                        shutil.copy("conf/pykota.conf.sample", "/etc/pykota/pykota.conf")       
190                        shutil.copy("conf/pykotadmin.conf.sample", "/etc/pykota/pykotadmin.conf")       
191                    except IOError, msg :   
192                        sys.stderr.write("WARNING : Problem while installing sample configuration files in /etc/pykota/, please do it manually.\n%s\n" % msg)
193                    else :   
194                        sys.stdout.write("Configuration file /etc/pykota/pykota.conf and /etc/pykota/pykotadmin.conf installed.\nDon't forget to adapt these files to your needs.\n")
195                else :       
196                    sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n")
197            else :       
198                # Problem ?
199                sys.stderr.write("WARNING : PyKota's sample configuration file cannot be found.\nWhat you have downloaded seems to be incomplete,\nor you are not in the pykota directory.\nPlease double check, and restart the installation procedure.\n")
200            dummy = raw_input("Please press ENTER when you have read the message above. ")
201    else :   
202        # already at 1.14 or above, nothing to be done.
203        pass
204       
205    # Second stage, we will fail if onfiguration is incorrect for security reasons
206    from pykota.config import PyKotaConfig,PyKotaConfigError
207    try :
208        conf = PyKotaConfig("/etc/pykota/")
209    except PyKotaConfigError, msg :   
210        sys.stedrr.write("%s\nINSTALLATION ABORTED !\nPlease restart installation.\n" % msg)
211        sys.exit(-1)
212    else :
213        hasadmin = conf.getGlobalOption("storageadmin", ignore=1)
214        hasadminpw = conf.getGlobalOption("storageadminpw", ignore=1)
215        hasuser = conf.getGlobalOption("storageuser", ignore=1)
216        if hasadmin or hasadminpw : 
217            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf doesn't contain the Quota Storage Administrator's name and optional password.\n")
218            sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykotadmin.conf\n")
219            sys.stderr.write("Then replace these values with 'storageuser' and 'storageuserpw' in /etc/pykota/pykota.conf\n")
220            sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n")
221            sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n")
222            sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n")
223            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n")
224            sys.exit(-1)
225        if not hasuser :
226            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password.\n")
227            sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykota.conf\n")
228            sys.stderr.write("These fields are respectively named 'storageuser' and 'storageuserpw'.\n")
229            sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n")
230            sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n")
231            sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n")
232            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n")
233            sys.exit(-1)
234           
235        sb = conf.getStorageBackend()
236        if (sb.get("storageadmin") is None) or (sb.get("storageuser") is None) :
237            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password which gives READONLY access to the Print Quota DataBase,")
238            sys.stderr.write("and that /etc/pykota/pykotadmin.conf contains the Quota Storage Administrator's name and optional password which gives READ/WRITE access to the Print Quota DataBase.\n")
239            sys.stderr.write("Your configuration doesn't seem to be OK, please modify your configuration files in /etc/pykota/\n")
240            sys.stderr.write("AND RESTART THE INSTALLATION.\n")
241            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n")
242            sys.exit(-1)
243       
244    # change files permissions   
245    os.chmod("/etc/pykota/pykota.conf", 0644)
246    os.chmod("/etc/pykota/pykotadmin.conf", 0640)
247   
248    # WARNING MESSAGE   
249    sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.14 TO 1.14 OR ABOVE\n")
250    sys.stdout.write("AND USE THE POSTGRESQL BACKEND, THEN YOU HAVE TO MODIFY YOUR\n")
251    sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.14.sql\n")
252    sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n")
253    sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION.\n\n")
254    dummy = raw_input("Please press ENTER when you have read the message above. ")
255   
256    # checks if some needed Python modules are there or not.
257    modulestocheck = [ ("PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota storage backend."),                                           
258                       ("mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work."), 
259                       ("Python-LDAP", "ldap", "Python-LDAP is mandatory if you plan to use an LDAP\ndirectory as the quota storage backend.")
260                     ]
261    commandstocheck = [("SNMP Tools", "snmpget", "SNMP Tools are needed if you want to use SNMP enabled printers."), ("Netatalk", "pap", "Netatalk is needed if you want to use AppleTalk enabled printers.")]
262    for (name, module, helper) in modulestocheck :
263        action = checkWithPrompt(name, module=module, helper=helper)
264        if action == ACTION_ABORT :
265            sys.stderr.write("Aborted !\n")
266            sys.exit(-1)
267           
268    # checks if some software are there or not.
269    for (name, command, helper) in commandstocheck :
270        action = checkWithPrompt(name, command=command, helper=helper)
271        if action == ACTION_ABORT :
272            sys.stderr.write("Aborted !\n")
273            sys.exit(-1)
274           
275data_files = []
276mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"]))
277for mofile in mofiles :
278    lang = mofile.split(os.sep)[1]
279    directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"])
280    data_files.append((directory, [ mofile ]))
281   
282directory = os.sep.join(["share", "man", "man1"])
283manpages = glob.glob(os.sep.join(["man", "*.1"]))   
284data_files.append((directory, manpages))
285
286setup(name = "pykota", version = __version__,
287      license = "GNU GPL",
288      description = __doc__,
289      author = "Jerome Alet",
290      author_email = "alet@librelogiciel.com",
291      url = "http://www.librelogiciel.com/software/",
292      packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
293      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme", "bin/waitprinter.sh" ],
294      data_files = data_files)
Note: See TracBrowser for help on using the browser.