Code

More tweaks to the licensing to make the Debian folks happy :)
[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.45 2003-04-07 03:47:44 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
32     DistributionMetadata.download_url = None
34 from roundup.templates.builder import makeHtmlBase
37 #############################################################################
38 ### Build script files
39 #############################################################################
41 class build_scripts_create(build_scripts):
42     """ Overload the build_scripts command and create the scripts
43         from scratch, depending on the target platform.
45         You have to define the name of your package in an inherited
46         class (due to the delayed instantiation of command classes
47         in distutils, this cannot be passed to __init__).
49         The scripts are created in an uniform scheme: they start the
50         run() function in the module
52             <packagename>.scripts.<mangled_scriptname>
54         The mangling of script names replaces '-' and '/' characters
55         with '-' and '.', so that they are valid module paths. 
56     """
57     package_name = None
59     def copy_scripts(self):
60         """ Create each script listed in 'self.scripts'
61         """
62         if not self.package_name:
63             raise Exception("You have to inherit build_scripts_create and"
64                 " provide a package name")
65         
66         to_module = string.maketrans('-/', '_.')
68         self.mkpath(self.build_dir)
69         for script in self.scripts:
70             outfile = os.path.join(self.build_dir, os.path.basename(script))
72             #if not self.force and not newer(script, outfile):
73             #    self.announce("not copying %s (up-to-date)" % script)
74             #    continue
76             if self.dry_run:
77                 self.announce("would create %s" % outfile)
78                 continue
80             module = os.path.splitext(os.path.basename(script))[0]
81             module = string.translate(module, to_module)
82             script_vars = {
83                 'python': os.path.normpath(sys.executable),
84                 'package': self.package_name,
85                 'module': module,
86             }
88             self.announce("creating %s" % outfile)
89             file = open(outfile, 'w')
91             try:
92                 if sys.platform == "win32":
93                     file.write('@echo off\n'
94                         'if NOT "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n'
95                         'if     "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n'
96                         % script_vars)
97                 else:
98                     file.write('#! %(python)s -O\n'
99                         'from %(package)s.scripts.%(module)s import run\n'
100                         'run()\n'
101                         % script_vars)
102             finally:
103                 file.close()
104                 os.chmod(outfile, 0755)
107 class build_scripts_roundup(build_scripts_create):
108     package_name = 'roundup'
111 def scriptname(path):
112     """ Helper for building a list of script names from a list of
113         module files.
114     """
115     script = os.path.splitext(os.path.basename(path))[0]
116     script = string.replace(script, '_', '-')
117     if sys.platform == "win32":
118         script = script + ".bat"
119     return script
123 #############################################################################
124 ### Main setup stuff
125 #############################################################################
127 def isTemplateDir(dir):
128     return dir[0] != '.' and dir != 'CVS' and os.path.isdir(dir) \
129         and os.path.isfile(os.path.join(dir, '__init__.py'))
131 # use that function to list all the templates
132 templates = map(os.path.basename, filter(isTemplateDir,
133     glob(os.path.join('roundup', 'templates', '*'))))
135 def buildTemplates():
136     for template in templates:
137         tdir = os.path.join('roundup', 'templates', template)
138         makeHtmlBase(tdir)
140 def main():
141     # build list of scripts from their implementation modules
142     roundup_scripts = map(scriptname, glob('roundup/scripts/[!_]*.py'))
144     # template munching
145     templates = map(os.path.basename, filter(isTemplateDir,
146         glob(os.path.join('roundup', 'templates', '*'))))
147     packagelist = [
148         'roundup',
149         'roundup.cgi',
150         'roundup.cgi.PageTemplates',
151         'roundup.cgi.TAL',
152         'roundup.cgi.ZTUtils',
153         'roundup.backends',
154         'roundup.scripts',
155         'roundup.templates'
156     ]
157     installdatafiles = [
158         ('share/roundup/cgi-bin', ['cgi-bin/roundup.cgi']),
159     ] 
161     # install man pages on POSIX platforms
162     if os.name == 'posix':
163         installdatafiles.append(('man/man1', ['doc/roundup-admin.1',
164             'doc/roundup-mailgw.1', 'doc/roundup-server.1']))
166     # munge the template HTML into the htmlbase module
167     buildTemplates()
169     # add the templates to the setup packages and data files lists
170     for template in templates:
171         tdir = os.path.join('roundup', 'templates', template)
173         # add the template package and subpackage
174         packagelist.append('roundup.templates.%s' % template)
175         packagelist.append('roundup.templates.%s.detectors' % template)
177         # scan for data files
178         tfiles = glob(os.path.join(tdir, 'html', '*'))
179         tfiles = filter(os.path.isfile, tfiles)
180         installdatafiles.append(
181             ('share/roundup/templates/%s/html' % template, tfiles)
182         )
184     # perform the setup action
185     from roundup import __version__
186     setup(
187         name = "roundup", 
188         version = __version__,
189         description = "Roundup issue tracking system.",
190         author = "Richard Jones",
191         author_email = "richard@users.sourceforge.net",
192         url = 'http://sourceforge.net/projects/roundup/',
193         download_url = 'http://sourceforge.net/project/showfiles.php?group_id=31577',
194         packages = packagelist,
195         classifiers = [
196             'Development Status :: 4 - Beta',
197             'Environment :: Console',
198             'Environment :: Web Environment',
199             'Intended Audience :: End Users/Desktop',
200             'Intended Audience :: Developers',
201             'Intended Audience :: System Administrators',
202             'License :: OSI Approved :: Python Software Foundation License',
203             'Operating System :: MacOS :: MacOS X',
204             'Operating System :: Microsoft :: Windows',
205             'Operating System :: POSIX',
206             'Programming Language :: Python',
207             'Topic :: Communications :: Email',
208             'Topic :: Office/Business',
209             'Topic :: Software Development :: Bug Tracking',
210         ],
212         # Override certain command classes with our own ones
213         cmdclass = {
214             'build_scripts': build_scripts_roundup,
215         },
216         scripts = roundup_scripts,
218         data_files =  installdatafiles
219     )
221 def install_demo():
222     ''' Install a demo server for users to play with for instant gratification.
224         Sets up the web service on localhost port 8080. Disables nosy lists.
225     '''
226     import shutil, socket, errno, BaseHTTPServer
228     # create the instance
229     home = os.path.abspath('demo')
230     try:
231         shutil.rmtree(home)
232     except os.error, error:
233         if error.errno != errno.ENOENT:
234             raise
235     from roundup import init, instance, password
236     init.install(home, 'classic')
237     # don't have email flying around
238     os.remove(os.path.join(home, 'detectors', 'nosyreaction.py'))
239     init.write_select_db(home, 'anydbm')
241     # figure basic params for server
242     hostname = socket.gethostname()
243     port = 8080
244     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
245     s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
246     while 1:
247         print 'Trying to set up web server on port %d ...'%port,
248         try:
249             s.bind((hostname, port))
250         except socket.error, error:
251             if error.errno != errno.EADDRINUSE:
252                 raise
253             print 'already in use.'
254             port += 100
255         else:
256             print 'should be ok.'
257             break
258     url = 'http://%s:%s/demo/'%(hostname, port)
260     # write the config
261     f = open(os.path.join(home, 'config.py'), 'r')
262     s = f.read().replace('http://tracker.example/cgi-bin/roundup.cgi/bugs/',
263         url)
264     f.close()
265     f = open(os.path.join(home, 'config.py'), 'w')
266     f.write(s)
267     f.close()
269     # initialise the database
270     init.initialise(home, 'admin')
272     # add the "demo" user
273     tracker = instance.open(home)
274     db = tracker.open('admin')
275     db.user.create(username='demo', password=password.Password('demo'),
276         realname='Demo User', roles='User')
277     db.commit()
278     db.close()
280     # ok, so start up the server
281     from roundup.scripts.roundup_server import RoundupRequestHandler
282     RoundupRequestHandler.TRACKER_HOMES = {'demo': home}
283     httpd = BaseHTTPServer.HTTPServer((hostname, port), RoundupRequestHandler)
284     print 'Server running - connect to:\n  %s'%url
285     print 'You may log in as "demo"/"demo" or "admin"/"admin".'
286     try:
287         httpd.serve_forever()
288     except KeyboardInterrupt:
289         print 'Keyboard Interrupt: exiting'
291 if __name__ == '__main__':
292     if len(sys.argv) > 1 and sys.argv[1] == 'demo':
293         install_demo()
294     else:
295         main()
297 # vim: set filetype=python ts=4 sw=4 et si