root / pykota / trunk / setup.py @ 880

Revision 873, 6.2 kB (checked in by jalet, 22 years ago)

GPL paragraphs were incorrectly (from memory) copied into the sources.
Two README files were added.
Upgrade script for PostgreSQL pre 1.01 schema was added.

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