Code

run python in optimise mode
[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.39 2002-09-23 08:17:50 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 from roundup.templates.builder import makeHtmlBase
31 #############################################################################
32 ### Build script files
33 #############################################################################
35 class build_scripts_create(build_scripts):
36     """ Overload the build_scripts command and create the scripts
37         from scratch, depending on the target platform.
39         You have to define the name of your package in an inherited
40         class (due to the delayed instantiation of command classes
41         in distutils, this cannot be passed to __init__).
43         The scripts are created in an uniform scheme: they start the
44         run() function in the module
46             <packagename>.scripts.<mangled_scriptname>
48         The mangling of script names replaces '-' and '/' characters
49         with '-' and '.', so that they are valid module paths. 
50     """
51     package_name = None
53     def copy_scripts(self):
54         """ Create each script listed in 'self.scripts'
55         """
56         if not self.package_name:
57             raise Exception("You have to inherit build_scripts_create and"
58                 " provide a package name")
59         
60         to_module = string.maketrans('-/', '_.')
62         self.mkpath(self.build_dir)
63         for script in self.scripts:
64             outfile = os.path.join(self.build_dir, os.path.basename(script))
66             #if not self.force and not newer(script, outfile):
67             #    self.announce("not copying %s (up-to-date)" % script)
68             #    continue
70             if self.dry_run:
71                 self.announce("would create %s" % outfile)
72                 continue
74             module = os.path.splitext(os.path.basename(script))[0]
75             module = string.translate(module, to_module)
76             script_vars = {
77                 'python': os.path.normpath(sys.executable),
78                 'package': self.package_name,
79                 'module': module,
80             }
82             self.announce("creating %s" % outfile)
83             file = open(outfile, 'w')
85             try:
86                 if sys.platform == "win32":
87                     file.write('@echo off\n'
88                         'if NOT "%%_4ver%%" == "" %(python)s -O -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n'
89                         'if     "%%_4ver%%" == "" %(python)s -O -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n'
90                         % script_vars)
91                 else:
92                     file.write('#! %(python)s -O\n'
93                         'from %(package)s.scripts.%(module)s import run\n'
94                         'run()\n'
95                         % script_vars)
96             finally:
97                 file.close()
98                 os.chmod(outfile, 0755)
101 class build_scripts_roundup(build_scripts_create):
102     package_name = 'roundup'
105 def scriptname(path):
106     """ Helper for building a list of script names from a list of
107         module files.
108     """
109     script = os.path.splitext(os.path.basename(path))[0]
110     script = string.replace(script, '_', '-')
111     if sys.platform == "win32":
112         script = script + ".bat"
113     return script
117 #############################################################################
118 ### Main setup stuff
119 #############################################################################
121 def isTemplateDir(dir):
122     return dir[0] != '.' and dir != 'CVS' and os.path.isdir(dir) \
123         and os.path.isfile(os.path.join(dir, '__init__.py'))
125 # use that function to list all the templates
126 templates = map(os.path.basename, filter(isTemplateDir,
127     glob(os.path.join('roundup', 'templates', '*'))))
129 def buildTemplates():
130     for template in templates:
131         tdir = os.path.join('roundup', 'templates', template)
132         makeHtmlBase(tdir)
134 if __name__ == '__main__':
135     # build list of scripts from their implementation modules
136     roundup_scripts = map(scriptname, glob('roundup/scripts/[!_]*.py'))
138     # template munching
139     templates = map(os.path.basename, filter(isTemplateDir,
140         glob(os.path.join('roundup', 'templates', '*'))))
141     packagelist = [
142         'roundup',
143         'roundup.cgi',
144         'roundup.cgi.PageTemplates',
145         'roundup.cgi.TAL',
146         'roundup.cgi.ZTUtils',
147         'roundup.backends',
148         'roundup.scripts',
149         'roundup.templates'
150     ]
151     installdatafiles = [
152         ('share/roundup/cgi-bin', ['cgi-bin/roundup.cgi']),
153     ] 
155     # munge the template HTML into the htmlbase module
156     buildTemplates()
158     # add the templates to the setup packages and data files lists
159     for template in templates:
160         tdir = os.path.join('roundup', 'templates', template)
162         # add the template package and subpackage
163         packagelist.append('roundup.templates.%s' % template)
164         packagelist.append('roundup.templates.%s.detectors' % template)
166         # scan for data files
167         tfiles = glob(os.path.join(tdir, 'html', '*'))
168         tfiles = filter(os.path.isfile, tfiles)
169         installdatafiles.append(
170             ('share/roundup/templates/%s/html' % template, tfiles)
171         )
173     # perform the setup action
174     from roundup import __version__
175     setup(
176         name = "roundup", 
177         version = __version__,
178         description = "Roundup issue tracking system.",
179         author = "Richard Jones",
180         author_email = "richard@users.sourceforge.net",
181         url = 'http://sourceforge.net/projects/roundup/',
182         packages = packagelist,
184         # Override certain command classes with our own ones
185         cmdclass = {
186             'build_scripts': build_scripts_roundup,
187         },
188         scripts = roundup_scripts,
190         data_files =  installdatafiles
191     )
193 # vim: set filetype=python ts=4 sw=4 et si