root / pykota / trunk / setup.py @ 870

Revision 870, 3.8 kB (checked in by jalet, 21 years ago)

More powerful installation script.

  • 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# You're welcome to redistribute this software under the
9# terms of the GNU General Public Licence version 2.0
10# or, at your option, any higher version.
11#
12# You can read the complete GNU GPL in the file COPYING
13# which should come along with this software, or visit
14# the Free Software Foundation's WEB site http://www.fsf.org
15#
16# $Id$
17#
18# $Log$
19# Revision 1.4  2003/03/29 09:47:00  jalet
20# More powerful installation script.
21#
22# Revision 1.3  2003/03/26 17:48:36  jalet
23# First shot at trying to detect the availability of the needed software
24# during the installation.
25#
26# Revision 1.2  2003/03/09 16:49:04  jalet
27# The installation script installs the man pages too now.
28#
29# Revision 1.1  2003/02/05 21:28:17  jalet
30# Initial import into CVS
31#
32#
33#
34
35import sys
36import glob
37import os
38from distutils.core import setup
39
40sys.path.insert(0, "pykota")
41from pykota.version import __version__, __doc__
42
43ACTION_CONTINUE = 0
44ACTION_ABORT = 1
45
46def checkModule(module) :
47    """Checks if a Python module is available or not."""
48    try :
49        exec "import %s" % module
50    except ImportError :   
51        return 0
52    else :   
53        return 1
54       
55def checkCommand(command) :
56    """Checks if a command is available or not."""
57    input = os.popen("type %s 2>/dev/null" % command)
58    result = input.read().strip()
59    input.close()
60    return result
61   
62def checkWithPrompt(prompt, module=None, command=None) :
63    """Tells the user what will be checked, and asks him what to do if something is absent."""
64    sys.stdout.write("Checking for %s availability : " % prompt)
65    sys.stdout.flush()
66    if command is not None :
67        result = checkCommand(command)
68    elif module is not None :   
69        result = checkModule(module)
70    if result :   
71        sys.stdout.write("OK\n")
72        return ACTION_CONTINUE
73    else :   
74        sys.stdout.write("NO.\n")
75        sys.stderr.write("ERROR : %s not available !\n" % prompt)
76        answer = raw_input("%s is missing. Do you want to continue anyway (y/N) ? " % prompt)
77        if answer[0:1].upper() == 'Y' :
78            return ACTION_CONTINUE
79        else :
80            return ACTION_ABORT
81   
82if "install" in sys.argv :
83    if not (sys.version > "2.1") :
84        sys.stderr.write("PyKota needs at least Python v2.1 !\nYour version seems to be older than that, please update.\nAborted !\n")
85        sys.exit(-1)
86       
87    modulestocheck = [("PygreSQL", "pg"), ("mxDateTime", "mx.DateTime")]
88    commandstocheck = [("SNMP Tools", "snmpget")]
89    for (name, module) in modulestocheck :
90        action = checkWithPrompt(name, module=module)
91        if action == ACTION_ABORT :
92            sys.stderr.write("Aborted !\n")
93            sys.exit(-1)
94           
95    for (name, command) in commandstocheck :
96        action = checkWithPrompt(name, command=command)
97        if action == ACTION_ABORT :
98            sys.stderr.write("Aborted !\n")
99            sys.exit(-1)
100           
101data_files = []
102mofiles = glob.glob(os.sep.join(["po", "*", "*.mo"]))
103for mofile in mofiles :
104    lang = mofile.split(os.sep)[1]
105    directory = os.sep.join(["share", "locale", lang, "LC_MESSAGES"])
106    data_files.append((directory, [ mofile ]))
107   
108directory = os.sep.join(["share", "man", "man1"])
109manpages = glob.glob(os.sep.join(["man", "*.1"]))   
110data_files.append((directory, manpages))
111
112setup(name = "pykota", version = __version__,
113      license = "GNU GPL",
114      description = __doc__,
115      author = "Jerome Alet",
116      author_email = "alet@librelogiciel.com",
117      url = "http://www.librelogiciel.com/software/",
118      packages = [ "pykota", "pykota.storages", "pykota.requesters", "pykota.loggers" ],
119      scripts = [ "bin/pykota", "bin/edpykota", "bin/repykota", "bin/warnpykota" ],
120      data_files = data_files)
Note: See TracBrowser for help on using the browser.