| 1 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 33 |
self.force = 0 |
|---|
| 34 |
self.data_dir = None |
|---|
| 35 |
|
|---|
| 36 |
def finalize_options(self): |
|---|
| 37 |
self.set_undefined_options('build', |
|---|
| 38 |
|
|---|
| 39 |
('force', 'force')) |
|---|
| 40 |
|
|---|
| 41 |
def run(self): |
|---|
| 42 |
import sys |
|---|
| 43 |
|
|---|
| 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 |
|---|
| 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 |
|
|---|