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.34 2002-05-29 01:16:16 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.templatebuilder 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")
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 -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n'
89 'if "%%_4ver%%" == "" %(python)s -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n'
90 % script_vars)
91 else:
92 file.write('#! %(python)s\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.backends',
144 'roundup.scripts',
145 'roundup.templates'
146 ]
147 installdatafiles = [
148 ('share/roundup/cgi-bin', ['cgi-bin/roundup.cgi']),
149 ]
151 # munge the template HTML into the htmlbase module
152 buildTemplates()
154 # add the templates to the setup packages and data files lists
155 for template in templates:
156 tdir = os.path.join('roundup', 'templates', template)
158 # add the template package and subpackage
159 packagelist.append('roundup.templates.%s' % template)
160 packagelist.append('roundup.templates.%s.detectors' % template)
162 # scan for data files
163 tfiles = glob(os.path.join(tdir, 'html', '*'))
164 tfiles = filter(os.path.isfile, tfiles)
165 installdatafiles.append(
166 ('share/roundup/templates/%s/html' % template, tfiles)
167 )
169 # perform the setup action
170 setup(
171 name = "roundup",
172 version = "0.4.1",
173 description = "Roundup issue tracking system.",
174 author = "Richard Jones",
175 author_email = "richard@users.sourceforge.net",
176 url = 'http://sourceforge.net/projects/roundup/',
177 packages = packagelist,
179 # Override certain command classes with our own ones
180 cmdclass = {
181 'build_scripts': build_scripts_roundup,
182 },
183 scripts = roundup_scripts,
185 data_files = installdatafiles
186 )
189 #
190 # $Log: not supported by cvs2svn $
191 # Revision 1.33 2002/04/03 05:53:03 richard
192 # Didn't get around to committing these after the last release.
193 #
194 # Revision 1.32 2002/03/27 23:47:58 jhermann
195 # Fix for scripts running under CMD.EXE
196 #
197 # Revision 1.31 2002/03/22 18:36:00 jhermann
198 # chmod +x for scripts
199 #
200 # Revision 1.30 2002/01/29 20:07:15 jhermann
201 # Conversion to generated script stubs
202 #
203 # Revision 1.29 2002/01/23 06:05:36 richard
204 # prep work for release
205 #
206 # Revision 1.28 2002/01/11 03:24:15 richard
207 # minor changes for 0.4.0b2
208 #
209 # Revision 1.27 2002/01/05 02:09:46 richard
210 # make setup abort if tests fail
211 #
212 # Revision 1.26 2001/12/08 07:06:20 jhermann
213 # Install html template files to share/roundup/templates
214 #
215 # Revision 1.25 2001/11/21 23:42:54 richard
216 # Some version number and documentation fixes.
217 #
218 # Revision 1.24 2001/11/06 22:32:15 jhermann
219 # Install roundup.cgi to share/roundup
220 #
221 # Revision 1.23 2001/10/17 06:04:00 richard
222 # Beginnings of an interactive mode for roundup-admin
223 #
224 # Revision 1.22 2001/10/11 05:01:28 richard
225 # Prep for pre-release #2
226 #
227 # Revision 1.21 2001/10/10 04:18:38 richard
228 # Getting ready for a preview release for 0.3.0.
229 #
230 # Revision 1.20 2001/10/08 21:49:30 richard
231 # Minor pre- 0.3.0 changes
232 #
233 # Revision 1.19 2001/09/10 09:48:35 richard
234 # Started changes log for 0.2.9
235 #
236 # Revision 1.18 2001/08/30 06:01:17 richard
237 # Fixed missing import in mailgw :(
238 #
239 # Revision 1.17 2001/08/08 03:29:35 richard
240 # Next release is 0.2.6
241 #
242 # Revision 1.16 2001/08/07 00:24:42 richard
243 # stupid typo
244 #
245 # Revision 1.15 2001/08/07 00:15:51 richard
246 # Added the copyright/license notice to (nearly) all files at request of
247 # Bizar Software.
248 #
249 # Revision 1.14 2001/08/06 23:57:20 richard
250 # Am now bundling unittest with the package so that everyone can use the unit
251 # tests.
252 #
253 # Revision 1.13 2001/08/03 07:18:57 richard
254 # updated version number for 0.2.6
255 #
256 # Revision 1.12 2001/08/03 02:51:06 richard
257 # detect unit tests
258 #
259 # Revision 1.11 2001/08/03 01:54:58 richard
260 # Started stuff off for the 0.2.5 release
261 #
262 # Revision 1.10 2001/07/30 07:17:44 richard
263 # Just making sure we've got the right version in there for development.
264 #
265 # Revision 1.9 2001/07/29 23:34:26 richard
266 # Added unit tests so they're run whenever we package/install/whatever.
267 #
268 # Revision 1.8 2001/07/29 09:43:46 richard
269 # Make sure that the htmlbase is up-to-date when we build a source dist.
270 #
271 # Revision 1.7 2001/07/29 08:37:58 richard
272 # changes
273 #
274 # Revision 1.6 2001/07/29 07:01:39 richard
275 # Added vim command to all source so that we don't get no steenkin' tabs :)
276 #
277 # Revision 1.5 2001/07/28 00:39:18 richard
278 # changes for the 0.2.1 distribution build.
279 #
280 # Revision 1.4 2001/07/27 07:20:17 richard
281 # Makefile is now obsolete - setup does what it used to do.
282 #
283 # Revision 1.3 2001/07/27 06:56:25 richard
284 # Added scripts to the setup and added the config so the default script
285 # install dir is /usr/local/bin.
286 #
287 # Revision 1.2 2001/07/26 07:14:27 richard
288 # Made setup.py executable, added id and log.
289 #
290 #
291 #
292 # vim: set filetype=python ts=4 sw=4 et si