root / pykota / trunk / setup.py @ 939

Revision 939, 7.8 kB (checked in by jalet, 21 years ago)

Better help

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