root / pykota / trunk / setup.py @ 1057

Revision 1057, 10.4 kB (checked in by jalet, 21 years ago)

Now includes the pykotme utility

  • 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.18  2003/07/03 09:44:00  jalet
26# Now includes the pykotme utility
27#
28# Revision 1.17  2003/06/30 12:46:15  jalet
29# Extracted reporting code.
30#
31# Revision 1.16  2003/06/06 20:49:15  jalet
32# Very latest schema. UNTESTED.
33#
34# Revision 1.15  2003/05/17 16:32:30  jalet
35# Also outputs the original import error message.
36#
37# Revision 1.14  2003/05/17 16:31:38  jalet
38# Dies gracefully if DistUtils is not present.
39#
40# Revision 1.13  2003/04/29 18:37:54  jalet
41# Pluggable accounting methods (actually doesn't support external scripts)
42#
43# Revision 1.12  2003/04/23 22:13:56  jalet
44# Preliminary support for LPRng added BUT STILL UNTESTED.
45#
46# Revision 1.11  2003/04/17 13:49:29  jalet
47# Typo
48#
49# Revision 1.10  2003/04/17 13:48:39  jalet
50# Better help
51#
52# Revision 1.9  2003/04/17 13:47:28  jalet
53# Help added during installation.
54#
55# Revision 1.8  2003/04/15 17:49:29  jalet
56# Installation script now checks the presence of Netatalk
57#
58# Revision 1.7  2003/04/03 20:03:37  jalet
59# Installation script now allows to install the sample configuration file.
60#
61# Revision 1.6  2003/03/29 13:45:26  jalet
62# GPL paragraphs were incorrectly (from memory) copied into the sources.
63# Two README files were added.
64# Upgrade script for PostgreSQL pre 1.01 schema was added.
65#
66# Revision 1.5  2003/03/29 13:08:28  jalet
67# Configuration is now expected to be found in /etc/pykota.conf instead of
68# in /etc/cups/pykota.conf
69# Installation script can move old config files to the new location if needed.
70# Better error handling if configuration file is absent.
71#
72# Revision 1.4  2003/03/29 09:47:00  jalet
73# More powerful installation script.
74#
75# Revision 1.3  2003/03/26 17:48:36  jalet
76# First shot at trying to detect the availability of the needed software
77# during the installation.
78#
79# Revision 1.2  2003/03/09 16:49:04  jalet
80# The installation script installs the man pages too now.
81#
82# Revision 1.1  2003/02/05 21:28:17  jalet
83# Initial import into CVS
84#
85#
86#
87
88import sys
89import glob
90import os
91import shutil
92import ConfigParser
93try :
94    from distutils.core import setup
95except ImportError, msg :   
96    sys.stderr.write("%s\n" % msg)
97    sys.stderr.write("You need the DistUtils Python module.\nunder Debian, you may have to install the python-dev package.\nOf course, YMMV.\n")
98    sys.exit(-1)
99
100sys.path.insert(0, "pykota")
101from pykota.version import __version__, __doc__
102
103ACTION_CONTINUE = 0
104ACTION_ABORT = 1
105
106def checkModule(module) :
107    """Checks if a Python module is available or not."""
108    try :
109        exec "import %s" % module
110    except ImportError :   
111        return 0
112    else :   
113        return 1
114       
115def checkCommand(command) :
116    """Checks if a command is available or not."""
117    input = os.popen("type %s 2>/dev/null" % command)
118    result = input.read().strip()
119    input.close()
120    return result
121   
122def checkWithPrompt(prompt, module=None, command=None, helper=None) :
123    """Tells the user what will be checked, and asks him what to do if something is absent."""
124    sys.stdout.write("Checking for %s availability : " % prompt)
125    sys.stdout.flush()
126    if command is not None :
127        result = checkCommand(command)
128    elif module is not None :   
129        result = checkModule(module)
130    if result :   
131        sys.stdout.write("OK\n")
132        return ACTION_CONTINUE
133    else :   
134        sys.stdout.write("NO.\n")
135        sys.stderr.write("ERROR : %s not available !\n" % prompt)
136        if helper is not None :
137            sys.stdout.write("%s\n" % helper)
138            sys.stdout.write("You may continue safely if you don't need this functionnality.\n")
139        answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt)
140        if answer[0:1].upper() == 'Y' :
141            return ACTION_CONTINUE
142        else :
143            return ACTION_ABORT
144   
145if "install" in sys.argv :
146    # checks if Python version is correct, we need >= 2.1
147    if not (sys.version > "2.1") :
148        sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n")
149        sys.exit(-1)
150       
151    # checks if a configuration file is present in the old location
152    if os.path.isfile("/etc/cups/pykota.conf") :
153        if not os.path.isfile("/etc/pykota.conf") :
154            sys.stdout.write("From version 1.02 on, PyKota expects to find its configuration\nfile in /etc instead of /etc/cups.\n")
155            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")
156            answer = raw_input("Do you want to move /etc/cups/pykota.conf to /etc/pykota.conf (y/N) ? ")
157            if answer[0:1].upper() == 'Y' :
158                try :
159                    os.rename("/etc/cups/pykota.conf", "/etc/pykota.conf")
160                except OSError :   
161                    sys.stderr.write("ERROR : An error occured while moving /etc/cups/pykota.conf to /etc/pykota.conf\nAborted !\n")
162                    sys.exit(-1)
163            else :
164                sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf won't be used ! Move it to /etc instead.\n")
165                sys.stderr.write("PyKota installation will continue anyway, but the software won't run until you put a proper configuration file in /etc\n")
166        else :       
167            sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf will not be used !\nThe file /etc/pykota.conf will be used instead.\n")
168    elif not os.path.isfile("/etc/pykota.conf") :       
169        # no configuration file, first installation it seems.
170        if os.path.isfile("conf/pykota.conf.sample") :
171            answer = raw_input("Do you want to install conf/pykota.conf.sample as /etc/pykota.conf (y/N) ? ")
172            if answer[0:1].upper() == 'Y' :
173                try :
174                    shutil.copy("conf/pykota.conf.sample", "/etc/pykota.conf")       
175                except IOError :   
176                    sys.stderr.write("WARNING : Problem while installing /etc/pykota.conf, please do it manually.\n")
177                else :   
178                    sys.stdout.write("Configuration file /etc/pykota.conf installed.\nDon't forget to adapt /etc/pykota.conf to your needs.\n")
179            else :       
180                sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n")
181    else :           
182        # Configuration file already exists. Check if this is an old version or not
183        # if the 'method: lazy' line is present, then the configuration file
184        # has to be updated.
185        oldconf = ConfigParser.ConfigParser()
186        oldconf.read(["/etc/pykota.conf"])
187        try :
188            if oldconf.get("global", "method", raw=1).lower().strip() == "lazy" :
189                sys.stdout.write("You have got an OLD PyKota configuration file !\n")
190                sys.stdout.write("The 'method' statement IS NOT SUPPORTED ANYMORE\nand was replaced with the 'accounter' statement.\n") 
191                sys.stdout.write("You have to manually set an 'accounter' statement,\neither globally or for each printer.\n")
192                sys.stdout.write("Please read the sample configuration file conf/pykota.conf.sample\n")
193                sys.stdout.write("to learn how to MANUALLY apply the modifications needed,\nafter the installation is done.\n")
194                sys.stdout.write("If you don't do this, then PyKota will stop working !\n")
195                answer = raw_input("Please, press ENTER when you'll have read the above paragraph.")
196        except ConfigParser.NoOptionError :
197            # New configuration file, OK
198            pass
199   
200    # checks if some needed Python modules are there or not.
201    modulestocheck = [ ("PygreSQL", "pg", "PygreSQL is mandatory if you want to use PostgreSQL as the quota storage backend."),                                           
202                       ("mxDateTime", "mx.DateTime", "eGenix' mxDateTime is mandatory for PyKota to work."), 
203                       ("Python-LDAP", "ldap", "Python-LDAP is mandatory if you plan to use an LDAP\ndirectory as the quota storage backend.")
204                     ]
205    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.")]
206    for (name, module, helper) in modulestocheck :
207        action = checkWithPrompt(name, module=module, helper=helper)
208        if action == ACTION_ABORT :
209            sys.stderr.write("Aborted !\n")
210            sys.exit(-1)
211           
212    # checks if some software are there or not.
213    for (name, command, helper) in commandstocheck :
214        action = checkWithPrompt(name, command=command, helper=helper)
215        if action == ACTION_ABORT :
216            sys.stderr.write("Aborted !\n")
217            sys.exit(-1)
218           
219data_files = []
220mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"]))
221for mofile in mofiles :
222    lang = mofile.split(os.sep)[1]
223    directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"])
224    data_files.append((directory, [ mofile ]))
225   
226directory = os.sep.join(["share", "man", "man1"])
227manpages = glob.glob(os.sep.join(["man", "*.1"]))   
228data_files.append((directory, manpages))
229
230setup(name = "pykota", version = __version__,
231      license = "GNU GPL",
232      description = __doc__,
233      author = "Jerome Alet",
234      author_email = "alet@librelogiciel.com",
235      url = "http://www.librelogiciel.com/software/",
236      packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers", "pykota.accounters", "pykota.reporters" ],
237      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota", "bin/pykotme" ],
238      data_files = data_files)
Note: See TracBrowser for help on using the browser.