root / pykota / trunk / setup.py @ 1112

Revision 1111, 15.6 kB (checked in by jalet, 21 years ago)

Added configurable LDAP mail attribute support

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