root / pykota / trunk / setup.py @ 940

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

Typo

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