| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
"""Gaphor |
|---|
| 7 |
""" |
|---|
| 8 |
|
|---|
| 9 |
MAJOR_VERSION = 0 |
|---|
| 10 |
MINOR_VERSION = 7 |
|---|
| 11 |
MICRO_VERSION = 1 |
|---|
| 12 |
|
|---|
| 13 |
VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION ) |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 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 |
|
|---|
| 41 |
] |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
config_failed=[] |
|---|
| 45 |
|
|---|
| 46 |
def initialize_options(self): |
|---|
| 47 |
|
|---|
| 48 |
pass |
|---|
| 49 |
|
|---|
| 50 |
def finalize_options(self): |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
pass |
|---|
| 58 |
|
|---|
| 59 |
def run(self): |
|---|
| 60 |
import pygtk |
|---|
| 61 |
pygtk.require('2.0') |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
self.module_check('xml.parsers.expat') |
|---|
| 72 |
|
|---|
| 73 |
self.module_check('gtk', ('gtk_version', (2, 3)), |
|---|
| 74 |
('pygtk_version', (2, 3))) |
|---|
| 75 |
|
|---|
| 76 |
self.module_check('gnomecanvas') |
|---|
| 77 |
|
|---|
| 78 |
self.module_check('diacanvas', ('diacanvas_version', (0, 14, 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 |
|
|---|
| 155 |
f.write('DATA_DIR=\'%s\'\n' % data_dir.replace('\\', '\\\\')) |
|---|
| 156 |
if os.name == 'nt': |
|---|
| 157 |
home = 'USERPROFILE' |
|---|
| 158 |
else: |
|---|
| 159 |
home = 'HOME' |
|---|
| 160 |
|
|---|
| 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 |
|
|---|
| 176 |
data_dir = os.path.join(os.getcwd(), 'data') |
|---|
| 177 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 258 |
|
|---|
| 259 |
getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value)) |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 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 |
('model=', 'm', 'load a model file'), |
|---|
| 274 |
] |
|---|
| 275 |
|
|---|
| 276 |
def initialize_options(self): |
|---|
| 277 |
self.build_lib = None |
|---|
| 278 |
self.command = None |
|---|
| 279 |
self.file = None |
|---|
| 280 |
self.testfile = None |
|---|
| 281 |
self.model = None |
|---|
| 282 |
self.verbosity = 2 |
|---|
| 283 |
|
|---|
| 284 |
def finalize_options(self): |
|---|
| 285 |
self.set_undefined_options('build', |
|---|
| 286 |
('build_lib', 'build_lib')) |
|---|
| 287 |
|
|---|
| 288 |
def run(self): |
|---|
| 289 |
print 'Starting gaphor...' |
|---|
| 290 |
print 'Starting with model file', self.model |
|---|
| 291 |
self.run_command('build') |
|---|
| 292 |
|
|---|
| 293 |
import os.path |
|---|
| 294 |
import gaphor |
|---|
| 295 |
|
|---|
| 296 |
if self.command: |
|---|
| 297 |
print 'Executing command: %s...' % self.command |
|---|
| 298 |
exec self.command |
|---|
| 299 |
elif self.testfile: |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
print 'Running test cases in unittest file: %s...' % self.testfile |
|---|
| 303 |
import imp, unittest |
|---|
| 304 |
fp = open(self.testfile) |
|---|
| 305 |
test_module = imp.load_source('gaphor_test', self.testfile, fp) |
|---|
| 306 |
test_suite = unittest.TestLoader().loadTestsFromModule(test_module) |
|---|
| 307 |
test_runner = unittest.TextTestRunner(verbosity=self.verbosity) |
|---|
| 308 |
result = test_runner.run(test_suite) |
|---|
| 309 |
sys.exit(not result.wasSuccessful()) |
|---|
| 310 |
elif self.file: |
|---|
| 311 |
print 'Executing file: %s...' % self.file |
|---|
| 312 |
dir, f = os.path.split(self.file) |
|---|
| 313 |
print 'Extending PYTHONPATH with %s' % dir |
|---|
| 314 |
sys.path.append(dir) |
|---|
| 315 |
execfile(self.file, {}) |
|---|
| 316 |
else: |
|---|
| 317 |
print 'Launching Gaphor...' |
|---|
| 318 |
gaphor.main(self.model) |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
def plugin_data(name): |
|---|
| 357 |
return 'plugins/%s' % name, glob('data/plugins/%s/*.*' % name) |
|---|
| 358 |
|
|---|
| 359 |
setup(name='gaphor', |
|---|
| 360 |
version=VERSION, |
|---|
| 361 |
description="Gaphor is a UML modeling tool", |
|---|
| 362 |
url='http://gaphor.sourceforge.net', |
|---|
| 363 |
author='Arjan J. Molenaar', |
|---|
| 364 |
author_email='arjanmol@users.sourceforge.net', |
|---|
| 365 |
license="GNU General Public License (GPL, see COPYING)", |
|---|
| 366 |
long_description="Gaphor is a UML modeling tool written in Python. " |
|---|
| 367 |
"It uses the GNOME2 environment for user interaction.", |
|---|
| 368 |
platforms=['GNOME2'], |
|---|
| 369 |
all_linguas=['nl', 'es'], |
|---|
| 370 |
packages=['gaphor', |
|---|
| 371 |
'gaphor.UML', |
|---|
| 372 |
'gaphor.diagram', |
|---|
| 373 |
'gaphor.ui', |
|---|
| 374 |
'gaphor.misc' |
|---|
| 375 |
], |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
data_files=[('', ['data/icons.xml']), |
|---|
| 379 |
('pixmaps', glob('data/pixmaps/*.png')), |
|---|
| 380 |
plugin_data('plugineditor'), |
|---|
| 381 |
plugin_data('alignment'), |
|---|
| 382 |
plugin_data('checkmetamodel'), |
|---|
| 383 |
plugin_data('diagramlayout'), |
|---|
| 384 |
plugin_data('liveobjectbrowser'), |
|---|
| 385 |
plugin_data('pngexport'), |
|---|
| 386 |
plugin_data('pynsource'), |
|---|
| 387 |
plugin_data('svgexport'), |
|---|
| 388 |
plugin_data('xmiexport') |
|---|
| 389 |
], |
|---|
| 390 |
scripts=['bin/gaphor'], |
|---|
| 391 |
|
|---|
| 392 |
distclass=Distribution, |
|---|
| 393 |
cmdclass={'config': config_Gaphor, |
|---|
| 394 |
'build_py': build_py_Gaphor, |
|---|
| 395 |
|
|---|
| 396 |
'build': build_Gaphor, |
|---|
| 397 |
|
|---|
| 398 |
'build_mo': build_mo, |
|---|
| 399 |
'build_pot': build_pot, |
|---|
| 400 |
'install': install, |
|---|
| 401 |
'install_lib': install_lib_Gaphor, |
|---|
| 402 |
'install_mo': install_mo, |
|---|
| 403 |
'run': run_Gaphor |
|---|
| 404 |
} |
|---|
| 405 |
) |
|---|
| 406 |
|
|---|