root / pykota / trunk / setup.py @ 884

Revision 884, 7.2 kB (checked in by jalet, 21 years ago)

Installation script now allows to install the sample configuration file.

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