root/gaphor/tags/gaphor-0.8.1/setup.py

Revision 770, 14.7 kB (checked in by wrobell, 3 years ago)

- ver. 0.8.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env python
2 #
3 # setup.py for Gaphor
4 #
5 # vim:sw=4:et
6 """Gaphor
7 """
8
9 MAJOR_VERSION = 0
10 MINOR_VERSION = 8
11 MICRO_VERSION = 1
12
13 VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION )
14
15 #GCONF_DOMAIN='/apps/gaphor/' # don't forget trailing slash
16
17 import sys, os
18 from glob import glob
19 from commands import getoutput, getstatus, getstatusoutput
20 from distutils.core import setup, Command
21 from distutils.command.build_py import build_py
22 from distutils.command.install_lib import install_lib
23 from distutils.dep_util import newer
24 from utils.build_mo import build, build_mo
25 from utils.build_pot import build_pot
26 from utils.install_mo import install, install_mo
27 from utils.dist_mo import Distribution
28
29 str_version = sys.version[:3]
30 version = map(int, str_version.split('.'))
31 if version < [2, 4]:
32     raise SystemExit, \
33         "Python 2.4 or higher is required, %s found" % str_version
34
35
36 class config_Gaphor(Command):
37     description="Configure Gaphor"
38
39     user_options = [
40         #('pkg-config=', None, 'Path to pkg-config'),
41     ]
42
43     #pkg_config_checked=False
44     config_failed=[]
45
46     def initialize_options(self):
47         #self.pkg_config = 'pkg-config'
48         pass
49
50     def finalize_options(self):
51         # Check for existence of pkg-config
52         #status, output = getstatusoutput('%s --version' % self.pkg_config)
53         #if status != 0:
54         #    print 'pkg-config not found.'
55         #    raise SystemExit
56         #print 'Found pkg-config version %s' % output
57         pass
58
59     def run(self):
60         import pygtk
61         pygtk.require('2.0')
62
63         #self.pkg_config_check('gobject-2.0', '2.0.0')
64         #self.pkg_config_check('gtk+-2.0', '2.0.0')
65         #self.pkg_config_check('pygtk-2.0', '1.99.15')
66         #self.pkg_config_check('gconf-2.0', '2.0.0')
67         #self.pkg_config_check('libbonobo-2.0', '2.0.0')
68         #self.pkg_config_check('libbonoboui-2.0', '2.0.0')
69         #self.pkg_config_check('diacanvas2', '0.9.1')
70
71         self.module_check('xml.parsers.expat')
72         #self.module_check('gobject', 'glib_version', (2, 8))
73         self.module_check('gtk', ('gtk_version', (2, 8)),
74                                  ('pygtk_version', (2, 8)))
75         #self.module_check('gnome')
76         self.module_check('gnomecanvas')
77         #self.module_check('gconf')
78         self.module_check('diacanvas', ('diacanvas_version', (0, 14, 3)))
79
80         print ''
81         if self.config_failed:
82             print 'Config failed.'
83             print 'The following modules can not be found or are to old:'
84             print ' ', str(self.config_failed)[1:-1]
85             print ''
86             raise SystemExit
87         else:
88             print 'Config succeeded.'
89
90     def pkg_config_check(self, package, version):
91         """Check for availability of a package via pkg-config."""
92         retval = os.system('%s --exists %s' % (self.pkg_config, package))
93         if retval:
94             print '!!! Required package %s not found.' % package
95             self.config_failed.append(package)
96             return
97         pkg_version_str = getoutput('%s --modversion %s' % (self.pkg_config, package))
98         pkg_version = map(int, pkg_version_str.split('.'))
99         req_version = map(int, version.split('.'))
100         if pkg_version >= req_version:
101             print "Found '%s', version %s." % (package, pkg_version_str)
102         else:
103             print "!!! Package '%s' has version %s, should have at least version %s." % ( package, pkg_version_str, version )
104             self.config_failed.append(package)
105
106     def module_check(self, module, *version_checks):
107         """Check for the availability of a module.
108
109         version_checks is a set of ket/version pairs that should be true.
110         """
111         import string
112         try:
113             mod = __import__(module)
114         except ImportError:
115             print "!!! Required module '%s' not found." % module
116             self.config_failed.append(module)
117         else:
118             print "Module '%s' found." % module
119             for key, ver in version_checks:
120                 s_ver = string.join(map(str, ver), '.')
121                 print "  Checking key '%s.%s' >= %s..." % (module, key, s_ver),
122                 try:
123                     modver = getattr(mod, key)
124                 except:
125                     print "Not found." % key
126                     self.config_failed.append(module)
127                 else:
128                     s_modver = string.join(map(str, modver), '.')
129                     if modver >= ver:
130                         print "Okay (%s)." % s_modver
131                     else:
132                         print "Failed (%s)" % s_modver
133                         self.config_failed.append(module)
134
135
136 class build_Gaphor(build):
137
138     def run(self):
139         self.run_command('config')
140         build.run(self)
141
142
143 class version_py:
144
145     def generate_version(self, dir, data_dir):
146         """Create a file gaphor/version.py which contains the current version.
147         """
148         outfile = os.path.join(dir, 'gaphor', 'version.py')
149         print 'generating %s' % outfile, dir, data_dir
150         self.mkpath(os.path.dirname(outfile))
151         f = open(outfile, 'w')
152         f.write('import os\n')
153         f.write('VERSION=\'%s\'\n' % VERSION)
154         # expand backspaces
155         f.write('DATA_DIR=\'%s\'\n' % data_dir.replace('\\', '\\\\'))
156         if os.name == 'nt':
157             home = 'USERPROFILE'
158         else:
159             home = 'HOME'
160         #f.write('DATA_DIR=\'%s\'\n' % data_dir)
161         f.write('import os\n')
162         f.write('USER_DATA_DIR=os.path.join(os.getenv(\'%s\'), \'.gaphor\')\n' % home)
163         f.write('del os\n')
164         f.close()
165         self.byte_compile([outfile])
166
167
168 class build_py_Gaphor(build_py, version_py):
169
170     description = "build_py and generate gaphor/UML/uml2.py."
171
172     def run(self):
173         build_py.run(self)
174         sys.path.insert(0, self.build_lib)
175         # All data is stored in the local data directory
176         data_dir = os.path.join(os.getcwd(), 'data')
177         #data_dir = "os.path.join(os.getcwd(), 'data')"
178         self.generate_version(self.build_lib, data_dir)
179         self.generate_uml2()
180
181     def generate_uml2(self):
182         """Generate gaphor/UML/uml2.py in the build directory."""
183         import utils.genUML2
184         gen = os.path.join('utils', 'genUML2.py')
185         overrides = os.path.join('gaphor', 'UML', 'uml2.override')
186         model = os.path.join('gaphor', 'UML', 'uml2.gaphor')
187         py_model = os.path.join('gaphor', 'UML', 'uml2.py')
188         outfile = os.path.join(self.build_lib, py_model)
189         self.mkpath(os.path.dirname(outfile))
190         if self.force or newer(model, outfile) \
191                       or newer(overrides, outfile) \
192                       or newer(gen, outfile):
193             print 'generating %s from %s...' % (py_model, model)
194             print '  (warnings can be ignored)'
195             utils.genUML2.generate(model, outfile, overrides)
196         else:
197             print 'not generating %s (up-to-date)' % py_model
198         self.byte_compile([outfile])
199
200
201 class install_lib_Gaphor(install_lib, version_py):
202
203     def initialize_options(self):
204         install_lib.initialize_options(self)
205         self.install_data= None
206
207     def finalize_options(self):
208         install_lib.finalize_options(self)
209         self.set_undefined_options('install_data',
210                                    ('install_dir', 'install_data'))
211
212     def run(self):
213         # install a new version.py with install_data as data_dir;
214         # get rid of install root directory
215         skip = len(self.get_finalized_command('install').root)
216
217         self.generate_version(self.install_dir, self.install_data[skip:])
218         install_lib.run(self)
219
220
221 class install_schemas(Command):
222     """Do something like this:
223
224         GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
225             gconftool --makefile-install-rule data/gaphor.schemas
226
227     in a pythonic way.
228     """
229
230     description = "Install a configuration (using GConf)."
231
232     user_options = [
233         ('install-data=', None, 'installation directory for data files'),
234         ('gconftool', None, 'The gconftool to use for installation'),
235         ('gconf-config-source', None, 'Overrule the GConf config source'),
236         ('force', 'f', 'force installation (overwrite existing keys)')
237     ]
238
239     boolean_options = ['force']
240
241     def initialize_options(self):
242         self.install_data = None
243         self.gconftool = 'gconftool-2'
244         self.gconf_config_source = ''
245         self.force = None
246         self.schemas_file = 'data/gaphor.schemas'
247
248     def finalize_options(self):
249         self.set_undefined_options('install',
250                                    ('force', 'force'),
251                                    ('install_data', 'install_data'))
252
253     def run(self):
254         getstatus('GCONF_CONFIG_SOURCE="%s" %s --makefile-install-rule %s' % (self.gconf_config_source, self.gconftool, self.schemas_file))
255
256         self._set_value('/schemas/apps/gaphor/data_dir', self.install_data, 'string')
257
258     def _set_value(self, key, value, type):
259         print "setting gconf value '%s' to '%s'" % (key, value)
260         #apply(getattr(self.gconf_client, 'set_' + type),
261         #      (GCONF_DOMAIN + key, value))
262         getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value))
263
264 #install.sub_commands.append(('install_schemas', None))
265
266
267 class run_Gaphor(Command):
268
269     description = 'Launch Gaphor from the local directory'
270
271     user_options = [
272         ('build-dir=', None, ''),
273         ('command=', 'c', 'execute command'),
274         ('file=', 'f', 'execute file'),
275         ('testfile=', 't', 'execute unittest file'),
276         ('model=', 'm', 'load a model file'),
277     ]
278
279     def initialize_options(self):
280         self.build_lib = None
281         self.command = None
282         self.file = None
283         self.testfile = None
284         self.model = None
285         self.verbosity = 2
286
287     def finalize_options(self):
288         self.set_undefined_options('build',
289                                    ('build_lib', 'build_lib'))
290
291     def run(self):
292         print 'Starting gaphor...'
293         print 'Starting with model file', self.model
294         self.run_command('build')
295
296         import os.path
297         import gaphor
298         #os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
299         if self.command:
300             print 'Executing command: %s...' % self.command
301             exec self.command
302         elif self.testfile:
303             # Running a unit test is done by opening the unit test file
304             # as a module and running the tests within that module.
305             print 'Running test cases in unittest file: %s...' % self.testfile
306             import imp, unittest
307             fp = open(self.testfile)
308             test_module = imp.load_source('gaphor_test', self.testfile, fp)
309             test_suite = unittest.TestLoader().loadTestsFromModule(test_module)
310             test_runner = unittest.TextTestRunner(verbosity=self.verbosity)
311             result = test_runner.run(test_suite)
312             sys.exit(not result.wasSuccessful())
313         elif self.file:
314             print 'Executing file: %s...' % self.file
315             dir, f = os.path.split(self.file)
316             print 'Extending PYTHONPATH with %s' % dir
317             sys.path.append(dir)
318             execfile(self.file, {})
319         else:
320             print 'Launching Gaphor...'
321             gaphor.main(self.model)
322
323 #try:
324 #    from dsextras import TemplateExtension, BuildExt, GLOBAL_INC
325 #except ImportError:
326 #    import pygtk
327 #    pygtk.require('2.0')
328 #    from gtk.dsextras import TemplateExtension, BuildExt, GLOBAL_INC
329
330 #pygtkincludedir = getoutput('pkg-config --variable pygtkincludedir pygtk-2.0')
331 #codegendir = getoutput('pkg-config --variable codegendir pygtk-2.0')
332 #defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0')
333
334 #sys.path.append(codegendir)
335
336 #GLOBAL_INC.append(pygtkincludedir)
337 #GLOBAL_INC.append('.')
338 #GTKDEFS = [os.path.join(defsdir, 'gtk-types.defs')]
339
340 #ext_modules = []
341 #gtkwrapbox = TemplateExtension(name='wrapbox',
342 #                               pkc_name='gtk+-2.0',
343 #                               pkc_version='2.0.0',
344 #                               output='gaphor.misc.wrapbox',
345 #                               defs='src/wrapbox.defs',
346 #                               sources=['src/gtkwrapbox.c',
347 #                                        'src/gtkhwrapbox.c',
348 #                                        'src/gtkvwrapbox.c',
349 #                                        'src/wrapbox.c',
350 #                                        'src/wrapboxmodule.c'],
351 #                               register=GTKDEFS,
352 #                               override='src/wrapbox.override')
353
354 #if gtkwrapbox.can_build():
355 #    ext_modules.append(gtkwrapbox)
356 #else:
357 #    pass
358
359 def plugin_data(name):
360     return 'plugins/%s' % name, glob('data/plugins/%s/*.*' % name)
361
362 setup(name='gaphor',
363       version=VERSION,
364       description="Gaphor is a UML modeling tool",
365       url='http://gaphor.sourceforge.net',
366       author='Arjan J. Molenaar',
367       author_email='arjanmol@users.sourceforge.net',
368       license="GNU General Public License (GPL, see COPYING)",
369       long_description="Gaphor is a UML modeling tool written in Python. "
370       "It uses the GNOME2 environment for user interaction.",
371       platforms=['GNOME2'],
372       all_linguas=['nl', 'es'],
373       packages=['gaphor',
374                 'gaphor.UML',
375                 'gaphor.diagram',
376                 'gaphor.ui',
377                 'gaphor.misc',
378                 'zope',
379                 'zope.interface',
380                 'zope.component.bbb',
381                 'zope.component.bbb.tests',
382                 'zope.interface.common',
383                 'zope.component',
384                 'zope.exceptions',
385                 'zope.deprecation',
386                 'zope.testing',
387                
388       ],
389 #      ext_modules=ext_modules,
390       # data files are relative to <prefix>/share/gaphor (see setup.cfg)
391       data_files=[('', ['data/icons.xml']),
392                   ('pixmaps', glob('data/pixmaps/*.png')),
393                   plugin_data('plugineditor'),
394                   plugin_data('alignment'),
395                   plugin_data('checkmetamodel'),
396                   plugin_data('diagramlayout'),
397                   plugin_data('liveobjectbrowser'),
398                   plugin_data('pngexport'),
399                   plugin_data('pynsource'),
400                   plugin_data('svgexport'),
401                   plugin_data('pdfexport'),
402                   plugin_data('xmiexport')
403       ],
404       scripts=['bin/gaphor', 'bin/gaphorconvert'],
405
406       distclass=Distribution,
407       cmdclass={'config': config_Gaphor,
408                 'build_py': build_py_Gaphor,
409                 #'install_schemas': install_schemas,
410                 'build': build_Gaphor,
411 #                'build_ext': BuildExt,
412                 'build_mo': build_mo,
413                 'build_pot': build_pot,
414                 'install': install,
415                 'install_lib': install_lib_Gaphor,
416                 'install_mo': install_mo,
417                 'run': run_Gaphor
418       }
419 )
420
Note: See TracBrowser for help on using the browser.