root/gaphor/tags/gaphor-0.12.0/utils/command/build_uml.py

Revision 1238, 2.0 kB (checked in by arj..@yirdis.nl, 2 years ago)

Changed run target to use load_entry_point. UML file is now generated in the source directory, that way setuptools can handle it better.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env python
2 """
3 This file provides the code generator which transforms gaphor/UML/uml2.gaphor
4 into gaphor/UML/uml2.py.
5
6 Also a distutils tool, build_uml, is provided.
7 """
8
9 ##
10 ## The Command
11 ##
12
13 import os.path
14 from distutils.core import Command
15 from distutils.command.build import build
16 from distutils.util import byte_compile
17 from distutils.dep_util import newer
18
19
20 class build_uml(Command):
21
22     description = "Generate gaphor/UML/uml2.py."
23
24     user_options = [
25         ('build-lib=','b', "build directory (where to install from)"),
26         ('force', 'f', "force installation (overwrite existing files)"),
27         ]
28
29     boolean_options = [ 'force' ]
30
31     def initialize_options(self):
32         #self.build_lib = None
33         self.force = 0
34         self.data_dir = None
35
36     def finalize_options(self):
37             self.set_undefined_options('build',
38                                        #('build_lib', 'build_lib'),
39                                        ('force', 'force'))
40
41     def run(self):
42         import sys
43         #sys.path.insert(0, self.build_lib)
44         self.generate_uml2()
45
46     def generate_uml2(self):
47         """
48         Generate gaphor/UML/uml2.py in the build directory.
49         """
50         gen = os.path.join('utils', 'command', 'gen_uml.py')
51         overrides = os.path.join('gaphor', 'UML', 'uml2.override')
52         model = os.path.join('gaphor', 'UML', 'uml2.gaphor')
53         py_model = os.path.join('gaphor', 'UML', 'uml2.py')
54         outfile = py_model #os.path.join(self.build_lib, py_model)
55         self.mkpath(os.path.dirname(outfile))
56         if self.force or newer(model, outfile) \
57                       or newer(overrides, outfile) \
58                       or newer(gen, outfile):
59             print 'generating %s from %s...' % (py_model, model)
60             print '  (warnings can be ignored)'
61             import gen_uml
62             gen_uml.generate(model, outfile, overrides)
63         else:
64             print 'not generating %s (up-to-date)' % py_model
65         byte_compile([outfile])
66
67 build.sub_commands.append(('build_uml', None))
68
69
70 # vim:sw=4:et
Note: See TracBrowser for help on using the browser.