root / pykota / trunk / setup.py @ 997

Revision 997, 9.8 kB (checked in by jalet, 21 years ago)

Also outputs the original import error message.

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