| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
"""Gaphor |
|---|
| 7 |
""" |
|---|
| 8 |
|
|---|
| 9 |
MAJOR_VERSION = 0 |
|---|
| 10 |
MINOR_VERSION = 2 |
|---|
| 11 |
MICRO_VERSION = 0 |
|---|
| 12 |
|
|---|
| 13 |
VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION ) |
|---|
| 14 |
|
|---|
| 15 |
GCONF_DOMAIN='/apps/gaphor/' |
|---|
| 16 |
|
|---|
| 17 |
import sys, os |
|---|
| 18 |
from glob import glob |
|---|
| 19 |
from commands import getoutput, getstatusoutput |
|---|
| 20 |
from distutils.core import setup, Command |
|---|
| 21 |
from distutils.command.build_py import build_py |
|---|
| 22 |
|
|---|
| 23 |
from distutils.dep_util import newer |
|---|
| 24 |
from utils.build_mo import build, build_mo |
|---|
| 25 |
from utils.install_mo import install, install_mo |
|---|
| 26 |
from utils.dist_mo import Distribution |
|---|
| 27 |
|
|---|
| 28 |
str_version = sys.version[:3] |
|---|
| 29 |
version = map(int, str_version.split('.')) |
|---|
| 30 |
if version < [2, 2]: |
|---|
| 31 |
raise SystemExit, \ |
|---|
| 32 |
"Python 2.2 or higher is required, %s found" % str_version |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
class config_Gaphor(Command): |
|---|
| 36 |
description="Configure Gaphor" |
|---|
| 37 |
|
|---|
| 38 |
user_options = [ |
|---|
| 39 |
|
|---|
| 40 |
] |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
config_failed=[] |
|---|
| 44 |
|
|---|
| 45 |
def initialize_options(self): |
|---|
| 46 |
|
|---|
| 47 |
pass |
|---|
| 48 |
|
|---|
| 49 |
def finalize_options(self): |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
pass |
|---|
| 57 |
|
|---|
| 58 |
def run(self): |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
self.module_check('xml.parsers.expat') |
|---|
| 68 |
|
|---|
| 69 |
self.module_check('gtk', 'gtk_version', (2, 0), |
|---|
| 70 |
'pygtk_version', (1, 99, 16)) |
|---|
| 71 |
self.module_check('gnome') |
|---|
| 72 |
self.module_check('gnome.ui') |
|---|
| 73 |
self.module_check('gnome.canvas') |
|---|
| 74 |
self.module_check('bonobo') |
|---|
| 75 |
self.module_check('bonobo.ui') |
|---|
| 76 |
self.module_check('gconf') |
|---|
| 77 |
self.module_check('diacanvas', 'diacanvas_version', (0, 9, 2)) |
|---|
| 78 |
|
|---|
| 79 |
print '' |
|---|
| 80 |
if self.config_failed: |
|---|
| 81 |
print 'Config failed.' |
|---|
| 82 |
print 'The following modules can not be found or are to old:' |
|---|
| 83 |
print ' ', str(self.config_failed)[1:-1] |
|---|
| 84 |
print '' |
|---|
| 85 |
raise SystemExit |
|---|
| 86 |
else: |
|---|
| 87 |
print 'Config succeeded.' |
|---|
| 88 |
print 'You can run Gaphor by typing: python setup.py run' |
|---|
| 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 |
try: |
|---|
| 112 |
mod = __import__(module) |
|---|
| 113 |
except ImportError: |
|---|
| 114 |
print "!!! Required module '%s' not found." % module |
|---|
| 115 |
self.config_failed.append(module) |
|---|
| 116 |
else: |
|---|
| 117 |
print "Module '%s' found." % module |
|---|
| 118 |
while version_checks: |
|---|
| 119 |
self.version_check(mod, version_checks[0], version_checks[1]) |
|---|
| 120 |
version_checks = version_checks[2:] |
|---|
| 121 |
|
|---|
| 122 |
def version_check(self, module, key, ver): |
|---|
| 123 |
import string |
|---|
| 124 |
s_ver = string.join(map(str, ver), '.') |
|---|
| 125 |
print " Checking key '%s.%s' >= %s..." % (module.__name__, key, s_ver), |
|---|
| 126 |
try: |
|---|
| 127 |
modver = getattr(module, key) |
|---|
| 128 |
except: |
|---|
| 129 |
print "Not found." % key |
|---|
| 130 |
self.config_failed.append(module.__name__) |
|---|
| 131 |
else: |
|---|
| 132 |
s_modver = string.join(map(str, modver), '.') |
|---|
| 133 |
if modver >= ver: |
|---|
| 134 |
print "Okay (%s)." % s_modver |
|---|
| 135 |
else: |
|---|
| 136 |
print "Failed (%s)" % s_modver |
|---|
| 137 |
self.config_failed.append(module.__name__) |
|---|
| 138 |
|
|---|
| 139 |
class build_py_Gaphor(build_py): |
|---|
| 140 |
|
|---|
| 141 |
description = "build_py and generate gaphor/UML/modelelements.py." |
|---|
| 142 |
|
|---|
| 143 |
def run(self): |
|---|
| 144 |
build_py.run(self) |
|---|
| 145 |
self.generate_modelelements() |
|---|
| 146 |
self.generate_version() |
|---|
| 147 |
|
|---|
| 148 |
def generate_modelelements(self): |
|---|
| 149 |
"""Generate gaphor/UML/modelelements.py in the build directory.""" |
|---|
| 150 |
import utils.genUML |
|---|
| 151 |
gen = 'utils/genUML.py' |
|---|
| 152 |
xmi = 'doc/UmlMetaModel.xmi' |
|---|
| 153 |
outfile = os.path.join(self.build_lib, 'gaphor/UML/modelelements.py') |
|---|
| 154 |
self.mkpath(os.path.dirname(outfile)) |
|---|
| 155 |
if self.force or newer(xmi, outfile) or newer(gen, outfile): |
|---|
| 156 |
utils.genUML.generate(xmi, outfile) |
|---|
| 157 |
else: |
|---|
| 158 |
print 'not generating %s (up-to-date)' % outfile |
|---|
| 159 |
self.byte_compile([outfile]) |
|---|
| 160 |
|
|---|
| 161 |
def generate_version(self): |
|---|
| 162 |
"""Create a file gaphor/version.py which contains the current version. |
|---|
| 163 |
""" |
|---|
| 164 |
outfile = os.path.join(self.build_lib, 'gaphor/version.py') |
|---|
| 165 |
self.mkpath(os.path.dirname(outfile)) |
|---|
| 166 |
f = open(outfile, 'w') |
|---|
| 167 |
f.write('VERSION=\'%s\'' % VERSION) |
|---|
| 168 |
f.close() |
|---|
| 169 |
self.byte_compile([outfile]) |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
class install_config(Command): |
|---|
| 173 |
|
|---|
| 174 |
description = "Install a configuration (using GConf)." |
|---|
| 175 |
|
|---|
| 176 |
user_options = [ |
|---|
| 177 |
('install-data=', None, 'installation directory for data files'), |
|---|
| 178 |
('force', 'f', 'force installation (overwrite existing keys)') |
|---|
| 179 |
] |
|---|
| 180 |
|
|---|
| 181 |
boolean_options = ['force'] |
|---|
| 182 |
|
|---|
| 183 |
def initialize_options(self): |
|---|
| 184 |
self.install_data = None |
|---|
| 185 |
self.force = None |
|---|
| 186 |
|
|---|
| 187 |
def finalize_options(self): |
|---|
| 188 |
self.set_undefined_options('install', |
|---|
| 189 |
('force', 'force'), |
|---|
| 190 |
('install_data', 'install_data')) |
|---|
| 191 |
|
|---|
| 192 |
def run(self): |
|---|
| 193 |
import gconf |
|---|
| 194 |
self.gconf_client = gconf.client_get_default() |
|---|
| 195 |
self._set_value('datadir', self.install_data, 'string') |
|---|
| 196 |
|
|---|
| 197 |
def _set_value(self, key, value, type): |
|---|
| 198 |
print "setting gconf value '%s' to '%s'" % (key, value) |
|---|
| 199 |
apply(getattr(self.gconf_client, 'set_' + type), |
|---|
| 200 |
(GCONF_DOMAIN + key, value)) |
|---|
| 201 |
|
|---|
| 202 |
install.sub_commands.append(('install_config', None)) |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
class run_Gaphor(Command): |
|---|
| 206 |
|
|---|
| 207 |
description = 'Launch Gaphor from the local directory' |
|---|
| 208 |
|
|---|
| 209 |
user_options = [('build-dir', None, '')] |
|---|
| 210 |
|
|---|
| 211 |
def initialize_options(self): |
|---|
| 212 |
self.build_lib = None |
|---|
| 213 |
|
|---|
| 214 |
def finalize_options(self): |
|---|
| 215 |
self.set_undefined_options('build', |
|---|
| 216 |
('build_lib', 'build_lib')) |
|---|
| 217 |
|
|---|
| 218 |
def run(self): |
|---|
| 219 |
print 'Starting gaphor...' |
|---|
| 220 |
import sys, os, os.path |
|---|
| 221 |
self.run_command('build') |
|---|
| 222 |
sys.path.insert(0, self.build_lib) |
|---|
| 223 |
from gaphor import Gaphor |
|---|
| 224 |
os.environ['GAPHOR_DATADIR'] = os.path.abspath('data') |
|---|
| 225 |
Gaphor().main() |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
setup(name='gaphor', |
|---|
| 229 |
version=VERSION, |
|---|
| 230 |
description="Gaphor is a UML modeling tool", |
|---|
| 231 |
url='http://gaphor.sourceforge.net', |
|---|
| 232 |
author='Arjan J. Molenaar', |
|---|
| 233 |
author_email='arjanmol@users.sourceforge.net', |
|---|
| 234 |
license="GNU General Public License (GPL, see COPYING)", |
|---|
| 235 |
long_description=""" |
|---|
| 236 |
Gaphor is a UML modeling tool written in Python. It uses the GNOME2 |
|---|
| 237 |
environment for user interaction.""", |
|---|
| 238 |
platforms=['GNOME2'], |
|---|
| 239 |
all_linguas=['nl'], |
|---|
| 240 |
packages=['gaphor', |
|---|
| 241 |
'gaphor.UML', |
|---|
| 242 |
'gaphor.diagram', |
|---|
| 243 |
'gaphor.ui', |
|---|
| 244 |
'gaphor.ui.command', |
|---|
| 245 |
'gaphor.misc' |
|---|
| 246 |
], |
|---|
| 247 |
|
|---|
| 248 |
data_files=[('', ['data/gaphor-main-ui.xml', |
|---|
| 249 |
'data/gaphor-diagram-ui.xml', |
|---|
| 250 |
'data/gaphor-editor-ui.xml', |
|---|
| 251 |
'data/gaphor.dtd']), |
|---|
| 252 |
('pixmaps', glob('data/pixmaps/*.png')) |
|---|
| 253 |
], |
|---|
| 254 |
scripts=['bin/gaphor'], |
|---|
| 255 |
|
|---|
| 256 |
distclass=Distribution, |
|---|
| 257 |
cmdclass={'config': config_Gaphor, |
|---|
| 258 |
'build_py': build_py_Gaphor, |
|---|
| 259 |
'install_config': install_config, |
|---|
| 260 |
'build': build, |
|---|
| 261 |
'build_mo': build_mo, |
|---|
| 262 |
'install': install, |
|---|
| 263 |
'install_mo': install_mo, |
|---|
| 264 |
'run': run_Gaphor |
|---|
| 265 |
} |
|---|
| 266 |
) |
|---|
| 267 |
|
|---|