root / pykota / trunk / setup.py @ 938

Revision 938, 7.6 kB (checked in by jalet, 21 years ago)

Help added during installation.

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