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.41 2002-12-10 00:11:13 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")
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 # munge the template HTML into the htmlbase module
161 buildTemplates()
163 # add the templates to the setup packages and data files lists
164 for template in templates:
165 tdir = os.path.join('roundup', 'templates', template)
167 # add the template package and subpackage
168 packagelist.append('roundup.templates.%s' % template)
169 packagelist.append('roundup.templates.%s.detectors' % template)
171 # scan for data files
172 tfiles = glob(os.path.join(tdir, 'html', '*'))
173 tfiles = filter(os.path.isfile, tfiles)
174 installdatafiles.append(
175 ('share/roundup/templates/%s/html' % template, tfiles)
176 )
178 # perform the setup action
179 from roundup import __version__
180 setup(
181 name = "roundup",
182 version = __version__,
183 description = "Roundup issue tracking system.",
184 author = "Richard Jones",
185 author_email = "richard@users.sourceforge.net",
186 url = 'http://sourceforge.net/projects/roundup/',
187 packages = packagelist,
188 classifiers = [
189 'Development Status :: 4 - Beta',
190 'Environment :: Console',
191 'Environment :: Web Environment',
192 'Intended Audience :: End Users/Desktop',
193 'Intended Audience :: Developers',
194 'Intended Audience :: System Administrators',
195 'License :: OSI Approved :: Python Software Foundation License',
196 'Operating System :: MacOS :: MacOS X',
197 'Operating System :: Microsoft :: Windows',
198 'Operating System :: POSIX',
199 'Programming Language :: Python',
200 'Topic :: Communications :: Email',
201 'Topic :: Office/Business',
202 'Topic :: Software Development :: Bug Tracking',
203 ],
205 # Override certain command classes with our own ones
206 cmdclass = {
207 'build_scripts': build_scripts_roundup,
208 },
209 scripts = roundup_scripts,
211 data_files = installdatafiles
212 )
214 # vim: set filetype=python ts=4 sw=4 et si