Code

included UN*X manual pages from Bastian Kleineidam
[roundup.git] / setup.py
1 #! /usr/bin/env python
2 #
3 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
4 # This module is free software, and you may redistribute it and/or modify
5 # under the same terms as Python, so long as this copyright message and
6 # disclaimer are retained in their original form.
7 #
8 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
9 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
10 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
11 # POSSIBILITY OF SUCH DAMAGE.
12 #
13 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18
19 # $Id: setup.py,v 1.42 2003-02-12 00:24:39 richard Exp $
21 from distutils.core import setup, Extension
22 from distutils.util import get_platform
23 from distutils.command.build_scripts import build_scripts
25 import sys, os, string
26 from glob import glob
28 # patch distutils if it can't cope with the "classifiers" keyword
29 if sys.version < '2.2.3':
30     from distutils.dist import DistributionMetadata
31     DistributionMetadata.classifiers = None
33 from roundup.templates.builder import makeHtmlBase
36 #############################################################################
37 ### Build script files
38 #############################################################################
40 class build_scripts_create(build_scripts):
41     """ Overload the build_scripts command and create the scripts
42         from scratch, depending on the target platform.
44         You have to define the name of your package in an inherited
45         class (due to the delayed instantiation of command classes
46         in distutils, this cannot be passed to __init__).
48         The scripts are created in an uniform scheme: they start the
49         run() function in the module
51             <packagename>.scripts.<mangled_scriptname>
53         The mangling of script names replaces '-' and '/' characters
54         with '-' and '.', so that they are valid module paths. 
55     """
56     package_name = None
58     def copy_scripts(self):
59         """ Create each script listed in 'self.scripts'
60         """
61         if not self.package_name:
62             raise Exception("You have to inherit build_scripts_create and"
63                 " provide a package name")
64         
65         to_module = string.maketrans('-/', '_.')
67         self.mkpath(self.build_dir)
68         for script in self.scripts:
69             outfile = os.path.join(self.build_dir, os.path.basename(script))
71             #if not self.force and not newer(script, outfile):
72             #    self.announce("not copying %s (up-to-date)" % script)
73             #    continue
75             if self.dry_run:
76                 self.announce("would create %s" % outfile)
77                 continue
79             module = os.path.splitext(os.path.basename(script))[0]
80             module = string.translate(module, to_module)
81             script_vars = {
82                 'python': os.path.normpath(sys.executable),
83                 'package': self.package_name,
84                 'module': module,
85             }
87             self.announce("creating %s" % outfile)
88             file = open(outfile, 'w')
90             try:
91                 if sys.platform == "win32":
92                     file.write('@echo off\n'
93                         'if NOT "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n'
94                         'if     "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n'
95                         % script_vars)
96                 else:
97                     file.write('#! %(python)s -O\n'
98                         'from %(package)s.scripts.%(module)s import run\n'
99                         'run()\n'
100                         % script_vars)
101             finally:
102                 file.close()
103                 os.chmod(outfile, 0755)
106 class build_scripts_roundup(build_scripts_create):
107     package_name = 'roundup'
110 def scriptname(path):
111     """ Helper for building a list of script names from a list of
112         module files.
113     """
114     script = os.path.splitext(os.path.basename(path))[0]
115     script = string.replace(script, '_', '-')
116     if sys.platform == "win32":
117         script = script + ".bat"
118     return script
122 #############################################################################
123 ### Main setup stuff
124 #############################################################################
126 def isTemplateDir(dir):
127     return dir[0] != '.' and dir != 'CVS' and os.path.isdir(dir) \
128         and os.path.isfile(os.path.join(dir, '__init__.py'))
130 # use that function to list all the templates
131 templates = map(os.path.basename, filter(isTemplateDir,
132     glob(os.path.join('roundup', 'templates', '*'))))
134 def buildTemplates():
135     for template in templates:
136         tdir = os.path.join('roundup', 'templates', template)
137         makeHtmlBase(tdir)
139 if __name__ == '__main__':
140     # build list of scripts from their implementation modules
141     roundup_scripts = map(scriptname, glob('roundup/scripts/[!_]*.py'))
143     # template munching
144     templates = map(os.path.basename, filter(isTemplateDir,
145         glob(os.path.join('roundup', 'templates', '*'))))
146     packagelist = [
147         'roundup',
148         'roundup.cgi',
149         'roundup.cgi.PageTemplates',
150         'roundup.cgi.TAL',
151         'roundup.cgi.ZTUtils',
152         'roundup.backends',
153         'roundup.scripts',
154         'roundup.templates'
155     ]
156     installdatafiles = [
157         ('share/roundup/cgi-bin', ['cgi-bin/roundup.cgi']),
158     ] 
160     # install man pages on POSIX platforms
161     if os.name == 'posix':
162         installdatafiles.append(('man/man1', ['doc/roundup-admin.1',
163             'doc/roundup-mailgw.1', 'doc/roundup-server.1']))
165     # munge the template HTML into the htmlbase module
166     buildTemplates()
168     # add the templates to the setup packages and data files lists
169     for template in templates:
170         tdir = os.path.join('roundup', 'templates', template)
172         # add the template package and subpackage
173         packagelist.append('roundup.templates.%s' % template)
174         packagelist.append('roundup.templates.%s.detectors' % template)
176         # scan for data files
177         tfiles = glob(os.path.join(tdir, 'html', '*'))
178         tfiles = filter(os.path.isfile, tfiles)
179         installdatafiles.append(
180             ('share/roundup/templates/%s/html' % template, tfiles)
181         )
183     # perform the setup action
184     from roundup import __version__
185     setup(
186         name = "roundup", 
187         version = __version__,
188         description = "Roundup issue tracking system.",
189         author = "Richard Jones",
190         author_email = "richard@users.sourceforge.net",
191         url = 'http://sourceforge.net/projects/roundup/',
192         packages = packagelist,
193         classifiers = [
194             'Development Status :: 4 - Beta',
195             'Environment :: Console',
196             'Environment :: Web Environment',
197             'Intended Audience :: End Users/Desktop',
198             'Intended Audience :: Developers',
199             'Intended Audience :: System Administrators',
200             'License :: OSI Approved :: Python Software Foundation License',
201             'Operating System :: MacOS :: MacOS X',
202             'Operating System :: Microsoft :: Windows',
203             'Operating System :: POSIX',
204             'Programming Language :: Python',
205             'Topic :: Communications :: Email',
206             'Topic :: Office/Business',
207             'Topic :: Software Development :: Bug Tracking',
208         ],
210         # Override certain command classes with our own ones
211         cmdclass = {
212             'build_scripts': build_scripts_roundup,
213         },
214         scripts = roundup_scripts,
216         data_files =  installdatafiles
217     )
219 # vim: set filetype=python ts=4 sw=4 et si