root / pykota / trunk / setup.py @ 996

Revision 996, 9.6 kB (checked in by jalet, 21 years ago)

Dies gracefully if DistUtils? is not present.

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