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

Revision 415, 13.9 kB (checked in by arjanmol, 4 years ago)

*** empty log message ***

  • 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 = 6
11 MICRO_VERSION = 0
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, 2]:
32     raise SystemExit, \
33         "Python 2.2 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, 0))
73         self.module_check('gtk', ('gtk_version', (2, 0)),
74                                  ('pygtk_version', (2, 0)))
75         self.module_check('gnome')
76         self.module_check('gnome.canvas')
77         #self.module_check('gconf')
78         self.module_check('diacanvas', ('diacanvas_version', (0, 13, 0)))
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 = 'USER'
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         self.generate_version(self.install_dir, self.install_data)
215         install_lib.run(self)
216
217
218 class install_schemas(Command):
219     """Do something like this:
220
221         GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
222             gconftool --makefile-install-rule data/gaphor.schemas
223
224     in a pythonic way.
225     """
226
227     description = "Install a configuration (using GConf)."
228
229     user_options = [
230         ('install-data=', None, 'installation directory for data files'),
231         ('gconftool', None, 'The gconftool to use for installation'),
232         ('gconf-config-source', None, 'Overrule the GConf config source'),
233         ('force', 'f', 'force installation (overwrite existing keys)')
234     ]
235
236     boolean_options = ['force']
237
238     def initialize_options(self):
239         self.install_data = None
240         self.gconftool = 'gconftool-2'
241         self.gconf_config_source = ''
242         self.force = None
243         self.schemas_file = 'data/gaphor.schemas'
244
245     def finalize_options(self):
246         self.set_undefined_options('install',
247                                    ('force', 'force'),
248                                    ('install_data', 'install_data'))
249
250     def run(self):
251         getstatus('GCONF_CONFIG_SOURCE="%s" %s --makefile-install-rule %s' % (self.gconf_config_source, self.gconftool, self.schemas_file))
252
253         self._set_value('/schemas/apps/gaphor/data_dir', self.install_data, 'string')
254
255     def _set_value(self, key, value, type):
256         print "setting gconf value '%s' to '%s'" % (key, value)
257         #apply(getattr(self.gconf_client, 'set_' + type),
258         #      (GCONF_DOMAIN + key, value))
259         getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value))
260
261 #install.sub_commands.append(('install_schemas', None))
262
263
264 class run_Gaphor(Command):
265
266     description = 'Launch Gaphor from the local directory'
267
268     user_options = [
269         ('build-dir=', None, ''),
270         ('command=', 'c', 'execute command'),
271         ('file=', 'f', 'execute file'),
272         ('testfile=', 't', 'execute unittest file'),
273     ]
274
275     def initialize_options(self):
276         self.build_lib = None
277         self.command = None
278         self.file = None
279         self.testfile = None
280         self.verbosity = 2
281
282     def finalize_options(self):
283         self.set_undefined_options('build',
284                                    ('build_lib', 'build_lib'))
285
286     def run(self):
287         print 'Starting gaphor...'
288         self.run_command('build')
289
290         import os.path
291         import gaphor
292         #os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
293         if self.command:
294             print 'Executing command: %s...' % self.command
295             exec self.command
296         elif self.testfile:
297             # Running a unit test is done by opening the unit test file
298             # as a module and running the tests within that module.
299             print 'Running test cases in unittest file: %s...' % self.testfile
300             import imp, unittest
301             fp = open(self.testfile)
302             test_module = imp.load_source('gaphor_test', self.testfile, fp)
303             test_suite = unittest.TestLoader().loadTestsFromModule(test_module)
304             test_runner = unittest.TextTestRunner(verbosity=self.verbosity)
305             result = test_runner.run(test_suite)
306             sys.exit(not result.wasSuccessful())
307         elif self.file:
308             print 'Executing file: %s...' % self.file
309             dir, f = os.path.split(self.file)
310             print 'Extending PYTHONPATH with %s' % dir
311             sys.path.append(dir)
312             execfile(self.file, {})
313         else:
314             print 'Launching Gaphor...'
315             gaphor.main()
316
317 #try:
318 #    from dsextras import TemplateExtension, BuildExt, GLOBAL_INC
319 #except ImportError:
320 #    import pygtk
321 #    pygtk.require('2.0')
322 #    from gtk.dsextras import TemplateExtension, BuildExt, GLOBAL_INC
323
324 #pygtkincludedir = getoutput('pkg-config --variable pygtkincludedir pygtk-2.0')
325 #codegendir = getoutput('pkg-config --variable codegendir pygtk-2.0')
326 #defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0')
327
328 #sys.path.append(codegendir)
329
330 #GLOBAL_INC.append(pygtkincludedir)
331 #GLOBAL_INC.append('.')
332 #GTKDEFS = [os.path.join(defsdir, 'gtk-types.defs')]
333
334 #ext_modules = []
335 #gtkwrapbox = TemplateExtension(name='wrapbox',
336 #                               pkc_name='gtk+-2.0',
337 #                               pkc_version='2.0.0',
338 #                               output='gaphor.misc.wrapbox',
339 #                               defs='src/wrapbox.defs',
340 #                               sources=['src/gtkwrapbox.c',
341 #                                        'src/gtkhwrapbox.c',
342 #                                        'src/gtkvwrapbox.c',
343 #                                        'src/wrapbox.c',
344 #                                        'src/wrapboxmodule.c'],
345 #                               register=GTKDEFS,
346 #                               override='src/wrapbox.override')
347
348 #if gtkwrapbox.can_build():
349 #    ext_modules.append(gtkwrapbox)
350 #else:
351 #    pass
352
353 def plugin_data(name):
354     return 'plugins/%s' % name, glob('data/plugins/%s/*.*' % name)
355
356 setup(name='gaphor',
357       version=VERSION,
358       description="Gaphor is a UML modeling tool",
359       url='http://gaphor.sourceforge.net',
360       author='Arjan J. Molenaar',
361       author_email='arjanmol@users.sourceforge.net',
362       license="GNU General Public License (GPL, see COPYING)",
363       long_description="Gaphor is a UML modeling tool written in Python. "
364       "It uses the GNOME2 environment for user interaction.",
365       platforms=['GNOME2'],
366       all_linguas=['nl'],
367       packages=['gaphor',
368                 'gaphor.UML',
369                 'gaphor.diagram',
370                 'gaphor.ui',
371                 'gaphor.misc'
372       ],
373 #      ext_modules=ext_modules,
374       # data files are relative to <prefix>/share/gaphor (see setup.cfg)
375       data_files=[('', ['data/icons.xml']),
376                   ('pixmaps', glob('data/pixmaps/*.png')),
377                   plugin_data('plugineditor'),
378                   plugin_data('checkmetamodel'),
379                   plugin_data('diagramlayout'),
380                   plugin_data('liveobjectbrowser'),
381                   plugin_data('pynsource')
382       ],
383       scripts=['bin/gaphor'],
384
385       distclass=Distribution,
386       cmdclass={'config': config_Gaphor,
387                 'build_py': build_py_Gaphor,
388                 #'install_schemas': install_schemas,
389                 'build': build_Gaphor,
390 #                'build_ext': BuildExt,
391                 'build_mo': build_mo,
392                 'build_pot': build_pot,
393                 'install': install,
394                 'install_lib': install_lib_Gaphor,
395                 'install_mo': install_mo,
396                 'run': run_Gaphor
397       }
398 )
399
Note: See TracBrowser for help on using the browser.