root / pykota / trunk / setup.py @ 968

Revision 952, 7.9 kB (checked in by jalet, 22 years ago)

Preliminary support for LPRng added BUT STILL UNTESTED.

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