root / pykota / trunk / setup.py @ 1048

Revision 1048, 10.3 kB (checked in by jalet, 21 years ago)

Extracted reporting code.

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