2003-03-04 05:08:40 +00:00
#!/usr/bin/env python
#
# setup.py for Gaphor
#
# vim:sw=4:et
""" Gaphor
"""
MAJOR_VERSION = 0
2004-06-26 18:12:59 +00:00
MINOR_VERSION = 5
2004-09-10 13:41:08 +00:00
MICRO_VERSION = 2
2003-03-04 05:08:40 +00:00
VERSION = ' %d . %d . %d ' % ( MAJOR_VERSION , MINOR_VERSION , MICRO_VERSION )
GCONF_DOMAIN = ' /apps/gaphor/ ' # don't forget trailing slash
import sys , os
from glob import glob
2003-10-13 07:14:46 +00:00
from commands import getoutput , getstatus , getstatusoutput
2003-03-04 05:08:40 +00:00
from distutils . core import setup , Command
from distutils . command . build_py import build_py
2003-10-13 07:14:46 +00:00
from distutils . command . install_lib import install_lib
2003-03-04 05:08:40 +00:00
from distutils . dep_util import newer
2003-03-11 18:02:11 +00:00
from utils . build_mo import build , build_mo
2003-11-27 20:07:10 +00:00
from utils . build_pot import build_pot
2003-03-11 18:02:11 +00:00
from utils . install_mo import install , install_mo
from utils . dist_mo import Distribution
2003-03-04 05:08:40 +00:00
str_version = sys . version [ : 3 ]
version = map ( int , str_version . split ( ' . ' ) )
if version < [ 2 , 2 ] :
raise SystemExit , \
2003-05-13 19:31:14 +00:00
" Python 2.2 or higher is required, %s found " % str_version
2003-03-04 05:08:40 +00:00
class config_Gaphor ( Command ) :
description = " Configure Gaphor "
user_options = [
2003-05-13 19:31:14 +00:00
#('pkg-config=', None, 'Path to pkg-config'),
2003-03-04 05:08:40 +00:00
]
2003-04-01 18:33:35 +00:00
#pkg_config_checked=False
config_failed = [ ]
2003-03-04 05:08:40 +00:00
def initialize_options ( self ) :
2003-05-13 19:31:14 +00:00
#self.pkg_config = 'pkg-config'
2003-04-01 18:33:35 +00:00
pass
2003-03-04 05:08:40 +00:00
def finalize_options ( self ) :
2003-05-13 19:31:14 +00:00
# Check for existence of pkg-config
#status, output = getstatusoutput('%s --version' % self.pkg_config)
#if status != 0:
# print 'pkg-config not found.'
# raise SystemExit
#print 'Found pkg-config version %s' % output
2003-04-01 18:33:35 +00:00
pass
2003-03-04 05:08:40 +00:00
def run ( self ) :
2003-06-03 17:59:45 +00:00
import pygtk
pygtk . require ( ' 2.0 ' )
2003-05-13 19:31:14 +00:00
#self.pkg_config_check('gobject-2.0', '2.0.0')
#self.pkg_config_check('gtk+-2.0', '2.0.0')
#self.pkg_config_check('pygtk-2.0', '1.99.15')
#self.pkg_config_check('gconf-2.0', '2.0.0')
#self.pkg_config_check('libbonobo-2.0', '2.0.0')
#self.pkg_config_check('libbonoboui-2.0', '2.0.0')
#self.pkg_config_check('diacanvas2', '0.9.1')
self . module_check ( ' xml.parsers.expat ' )
#self.module_check('gobject', 'glib_version', (2, 0))
self . module_check ( ' gtk ' , ( ' gtk_version ' , ( 2 , 0 ) ) ,
2004-05-13 11:20:17 +00:00
( ' pygtk_version ' , ( 2 , 0 ) ) )
2003-05-13 19:31:14 +00:00
self . module_check ( ' gnome ' )
self . module_check ( ' gnome.canvas ' )
2004-04-07 10:49:27 +00:00
#self.module_check('gconf')
2004-05-30 18:52:35 +00:00
self . module_check ( ' diacanvas ' , ( ' diacanvas_version ' , ( 0 , 13 , 0 ) ) )
2003-03-04 05:08:40 +00:00
2003-04-01 18:33:35 +00:00
print ' '
2003-05-13 19:31:14 +00:00
if self . config_failed :
print ' Config failed. '
2003-04-01 18:33:35 +00:00
print ' The following modules can not be found or are to old: '
print ' ' , str ( self . config_failed ) [ 1 : - 1 ]
print ' '
2003-05-13 19:31:14 +00:00
raise SystemExit
2003-04-01 18:33:35 +00:00
else :
print ' Config succeeded. '
2003-03-04 05:08:40 +00:00
def pkg_config_check ( self , package , version ) :
2003-05-13 19:31:14 +00:00
""" Check for availability of a package via pkg-config. """
retval = os . system ( ' %s --exists %s ' % ( self . pkg_config , package ) )
if retval :
print ' !!! Required package %s not found. ' % package
self . config_failed . append ( package )
return
pkg_version_str = getoutput ( ' %s --modversion %s ' % ( self . pkg_config , package ) )
pkg_version = map ( int , pkg_version_str . split ( ' . ' ) )
req_version = map ( int , version . split ( ' . ' ) )
if pkg_version > = req_version :
print " Found ' %s ' , version %s . " % ( package , pkg_version_str )
else :
print " !!! Package ' %s ' has version %s , should have at least version %s . " % ( package , pkg_version_str , version )
self . config_failed . append ( package )
2003-04-01 18:33:35 +00:00
def module_check ( self , module , * version_checks ) :
""" Check for the availability of a module.
2003-03-04 05:08:40 +00:00
2003-04-01 18:33:35 +00:00
version_checks is a set of ket / version pairs that should be true .
"""
2003-05-03 07:15:44 +00:00
import string
2003-05-13 19:31:14 +00:00
try :
mod = __import__ ( module )
except ImportError :
print " !!! Required module ' %s ' not found. " % module
self . config_failed . append ( module )
else :
print " Module ' %s ' found. " % module
2003-05-03 07:15:44 +00:00
for key , ver in version_checks :
s_ver = string . join ( map ( str , ver ) , ' . ' )
print " Checking key ' %s . %s ' >= %s ... " % ( module , key , s_ver ) ,
try :
modver = getattr ( mod , key )
except :
print " Not found. " % key
self . config_failed . append ( module )
else :
s_modver = string . join ( map ( str , modver ) , ' . ' )
if modver > = ver :
print " Okay ( %s ). " % s_modver
else :
print " Failed ( %s ) " % s_modver
self . config_failed . append ( module )
2003-04-01 18:33:35 +00:00
2003-03-04 05:08:40 +00:00
2003-10-13 07:14:46 +00:00
class version_py :
def generate_version ( self , dir , data_dir ) :
""" Create a file gaphor/version.py which contains the current version.
"""
outfile = os . path . join ( dir , ' gaphor ' , ' version.py ' )
2004-06-22 19:33:22 +00:00
print ' generating %s ' % outfile , dir , data_dir
2003-10-13 07:14:46 +00:00
self . mkpath ( os . path . dirname ( outfile ) )
f = open ( outfile , ' w ' )
2004-09-01 07:37:28 +00:00
f . write ( ' import os \n ' )
2003-10-13 07:14:46 +00:00
f . write ( ' VERSION= \' %s \' \n ' % VERSION )
2004-09-01 07:37:28 +00:00
# expand backspaces
f . write ( ' DATA_DIR= \' %s \' \n ' % data_dir . replace ( ' \\ ' , ' \\ \\ ' ) )
if os . name == ' nt ' :
home = ' USERPROFILE '
else :
home = ' USER '
2003-10-13 07:14:46 +00:00
f . write ( ' DATA_DIR= \' %s \' \n ' % data_dir )
2004-06-22 19:33:22 +00:00
f . write ( ' import os \n ' )
2004-09-01 07:37:28 +00:00
f . write ( ' USER_DATA_DIR=os.path.join(os.getenv( \' %s \' ), \' .gaphor \' ) \n ' % home )
2004-06-22 19:33:22 +00:00
f . write ( ' del os \n ' )
2003-10-13 07:14:46 +00:00
f . close ( )
self . byte_compile ( [ outfile ] )
class build_py_Gaphor ( build_py , version_py ) :
2003-03-04 05:08:40 +00:00
2003-05-03 07:15:44 +00:00
description = " build_py and generate gaphor/UML/uml2.py. "
2003-03-04 05:08:40 +00:00
def run ( self ) :
2004-09-03 06:58:21 +00:00
self . run_command ( ' config ' )
2003-03-04 05:08:40 +00:00
build_py . run ( self )
2003-05-03 07:15:44 +00:00
sys . path . insert ( 0 , self . build_lib )
2003-10-13 07:14:46 +00:00
# All data is stored in the local data directory
data_dir = os . path . join ( os . getcwd ( ) , ' data ' )
2004-09-01 07:37:28 +00:00
#data_dir = "os.path.join(os.getcwd(), 'data')"
2003-10-13 07:14:46 +00:00
self . generate_version ( self . build_lib , data_dir )
2003-05-03 07:15:44 +00:00
self . generate_uml2 ( )
def generate_uml2 ( self ) :
""" Generate gaphor/UML/uml2.py in the build directory. """
import utils . genUML2
2004-05-13 11:20:17 +00:00
gen = os . path . join ( ' utils ' , ' genUML2.py ' )
overrides = os . path . join ( ' gaphor ' , ' UML ' , ' uml2.override ' )
model = os . path . join ( ' gaphor ' , ' UML ' , ' uml2.gaphor ' )
py_model = os . path . join ( ' gaphor ' , ' UML ' , ' uml2.py ' )
2003-05-03 07:15:44 +00:00
outfile = os . path . join ( self . build_lib , py_model )
2003-03-06 19:28:38 +00:00
self . mkpath ( os . path . dirname ( outfile ) )
2003-09-01 18:29:59 +00:00
if self . force or newer ( model , outfile ) \
or newer ( overrides , outfile ) \
or newer ( gen , outfile ) :
2003-05-03 07:15:44 +00:00
print ' generating %s from %s ... ' % ( py_model , model )
2004-05-13 11:20:17 +00:00
print ' (warnings can be ignored) '
2003-05-13 19:31:14 +00:00
utils . genUML2 . generate ( model , outfile , overrides )
2003-03-04 05:08:40 +00:00
else :
2003-05-03 07:15:44 +00:00
print ' not generating %s (up-to-date) ' % py_model
2003-03-06 19:28:38 +00:00
self . byte_compile ( [ outfile ] )
2003-03-04 05:08:40 +00:00
2003-10-13 07:14:46 +00:00
class install_lib_Gaphor ( install_lib , version_py ) :
def initialize_options ( self ) :
install_lib . initialize_options ( self )
self . install_data = None
def finalize_options ( self ) :
install_lib . finalize_options ( self )
self . set_undefined_options ( ' install_data ' ,
( ' install_dir ' , ' install_data ' ) )
def run ( self ) :
# Install a new version.py with install_data as data_dir:
self . generate_version ( self . install_dir , self . install_data )
2004-06-22 19:33:22 +00:00
install_lib . run ( self )
2003-03-04 05:08:40 +00:00
2003-10-13 07:14:46 +00:00
class install_schemas ( Command ) :
""" Do something like this:
GCONF_CONFIG_SOURCE = ` gconftool - 2 - - get - default - source ` \
gconftool - - makefile - install - rule data / gaphor . schemas
in a pythonic way .
"""
2003-03-04 05:08:40 +00:00
description = " Install a configuration (using GConf). "
user_options = [
2003-05-13 19:31:14 +00:00
( ' install-data= ' , None , ' installation directory for data files ' ) ,
2003-10-13 07:14:46 +00:00
( ' gconftool ' , None , ' The gconftool to use for installation ' ) ,
( ' gconf-config-source ' , None , ' Overrule the GConf config source ' ) ,
2003-05-13 19:31:14 +00:00
( ' force ' , ' f ' , ' force installation (overwrite existing keys) ' )
2003-03-04 05:08:40 +00:00
]
boolean_options = [ ' force ' ]
def initialize_options ( self ) :
2003-05-13 19:31:14 +00:00
self . install_data = None
2003-10-13 07:14:46 +00:00
self . gconftool = ' gconftool-2 '
self . gconf_config_source = ' '
2003-05-13 19:31:14 +00:00
self . force = None
2003-10-13 07:14:46 +00:00
self . schemas_file = ' data/gaphor.schemas '
2003-03-04 05:08:40 +00:00
def finalize_options ( self ) :
2003-05-13 19:31:14 +00:00
self . set_undefined_options ( ' install ' ,
( ' force ' , ' force ' ) ,
( ' install_data ' , ' install_data ' ) )
2003-03-04 05:08:40 +00:00
def run ( self ) :
2003-10-13 07:14:46 +00:00
getstatus ( ' GCONF_CONFIG_SOURCE= " %s " %s --makefile-install-rule %s ' % ( self . gconf_config_source , self . gconftool , self . schemas_file ) )
self . _set_value ( ' /schemas/apps/gaphor/data_dir ' , self . install_data , ' string ' )
2003-03-04 05:08:40 +00:00
def _set_value ( self , key , value , type ) :
2003-03-11 18:02:11 +00:00
print " setting gconf value ' %s ' to ' %s ' " % ( key , value )
2003-10-13 07:14:46 +00:00
#apply(getattr(self.gconf_client, 'set_' + type),
# (GCONF_DOMAIN + key, value))
getstatus ( ' %s --type= %s --set %s %s ' % ( self . gconftool , type , key , value ) )
2003-03-04 05:08:40 +00:00
2003-10-13 07:14:46 +00:00
#install.sub_commands.append(('install_schemas', None))
2003-03-04 05:08:40 +00:00
2003-03-11 18:02:11 +00:00
2003-03-06 19:28:38 +00:00
class run_Gaphor ( Command ) :
2003-03-11 18:02:11 +00:00
description = ' Launch Gaphor from the local directory '
2003-05-03 07:15:44 +00:00
user_options = [
( ' build-dir= ' , None , ' ' ) ,
( ' command= ' , ' c ' , ' execute command ' ) ,
( ' file= ' , ' f ' , ' execute file ' ) ,
2003-06-01 18:25:59 +00:00
( ' testfile= ' , ' t ' , ' execute unittest file ' ) ,
2003-05-03 07:15:44 +00:00
]
2003-03-11 18:02:11 +00:00
def initialize_options ( self ) :
self . build_lib = None
2003-05-03 07:15:44 +00:00
self . command = None
self . file = None
2003-06-01 18:25:59 +00:00
self . testfile = None
self . verbosity = 2
2003-03-11 18:02:11 +00:00
def finalize_options ( self ) :
self . set_undefined_options ( ' build ' ,
( ' build_lib ' , ' build_lib ' ) )
2003-03-06 19:28:38 +00:00
def run ( self ) :
2003-03-11 18:02:11 +00:00
print ' Starting gaphor... '
self . run_command ( ' build ' )
2003-05-03 07:15:44 +00:00
import os . path
2003-11-05 19:36:18 +00:00
import gaphor
2003-10-13 07:14:46 +00:00
#os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
2003-05-03 07:15:44 +00:00
if self . command :
2003-05-13 19:31:14 +00:00
print ' Executing command: %s ... ' % self . command
2003-05-03 07:15:44 +00:00
exec self . command
2003-06-01 18:25:59 +00:00
elif self . testfile :
# Running a unit test is done by opening the unit test file
# as a module and running the tests within that module.
print ' Running test cases in unittest file: %s ... ' % self . testfile
import imp , unittest
fp = open ( self . testfile )
test_module = imp . load_source ( ' gaphor_test ' , self . testfile , fp )
test_suite = unittest . TestLoader ( ) . loadTestsFromModule ( test_module )
test_runner = unittest . TextTestRunner ( verbosity = self . verbosity )
result = test_runner . run ( test_suite )
sys . exit ( not result . wasSuccessful ( ) )
2003-05-03 07:15:44 +00:00
elif self . file :
2003-06-01 18:25:59 +00:00
print ' Executing file: %s ... ' % self . file
2003-05-13 19:31:14 +00:00
execfile ( self . file , { } )
2003-05-03 07:15:44 +00:00
else :
2003-11-27 20:07:10 +00:00
print ' Launching Gaphor... '
2003-11-05 19:36:18 +00:00
gaphor . main ( )
2003-03-06 19:28:38 +00:00
2004-05-10 07:38:37 +00:00
#try:
# from dsextras import TemplateExtension, BuildExt, GLOBAL_INC
#except ImportError:
# import pygtk
# pygtk.require('2.0')
# from gtk.dsextras import TemplateExtension, BuildExt, GLOBAL_INC
#pygtkincludedir = getoutput('pkg-config --variable pygtkincludedir pygtk-2.0')
#codegendir = getoutput('pkg-config --variable codegendir pygtk-2.0')
#defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0')
#sys.path.append(codegendir)
#GLOBAL_INC.append(pygtkincludedir)
#GLOBAL_INC.append('.')
#GTKDEFS = [os.path.join(defsdir, 'gtk-types.defs')]
#ext_modules = []
#gtkwrapbox = TemplateExtension(name='wrapbox',
# pkc_name='gtk+-2.0',
# pkc_version='2.0.0',
# output='gaphor.misc.wrapbox',
# defs='src/wrapbox.defs',
# sources=['src/gtkwrapbox.c',
# 'src/gtkhwrapbox.c',
# 'src/gtkvwrapbox.c',
# 'src/wrapbox.c',
# 'src/wrapboxmodule.c'],
# register=GTKDEFS,
# override='src/wrapbox.override')
#if gtkwrapbox.can_build():
# ext_modules.append(gtkwrapbox)
#else:
# pass
2004-03-22 15:15:14 +00:00
2003-03-04 05:08:40 +00:00
setup ( name = ' gaphor ' ,
version = VERSION ,
2003-03-11 18:02:11 +00:00
description = " Gaphor is a UML modeling tool " ,
2003-03-04 05:08:40 +00:00
url = ' http://gaphor.sourceforge.net ' ,
author = ' Arjan J. Molenaar ' ,
author_email = ' arjanmol@users.sourceforge.net ' ,
2003-03-11 18:02:11 +00:00
license = " GNU General Public License (GPL, see COPYING) " ,
2003-10-13 07:14:46 +00:00
long_description = " Gaphor is a UML modeling tool written in Python. "
" It uses the GNOME2 environment for user interaction. " ,
2003-03-11 18:02:11 +00:00
platforms = [ ' GNOME2 ' ] ,
all_linguas = [ ' nl ' ] ,
2003-03-04 05:08:40 +00:00
packages = [ ' gaphor ' ,
2003-05-13 19:31:14 +00:00
' gaphor.UML ' ,
' gaphor.diagram ' ,
' gaphor.ui ' ,
' gaphor.misc '
2003-03-04 05:08:40 +00:00
] ,
2004-05-10 07:38:37 +00:00
# ext_modules=ext_modules,
2003-03-11 18:02:11 +00:00
# data files are relative to <prefix>/share/gaphor (see setup.cfg)
2004-05-26 08:59:12 +00:00
data_files = [ ( ' ' , [ ' data/icons.xml ' ] ) ,
2004-06-22 19:33:22 +00:00
( ' pixmaps ' , glob ( ' data/pixmaps/*.png ' ) ) ,
2004-09-01 07:31:14 +00:00
( ' plugins/plugineditor ' , glob ( ' data/plugins/plugineditor/*.* ' ) ) ,
2004-09-10 13:41:08 +00:00
( ' plugins/liveobjectbrowser ' , glob ( ' data/plugins/liveobjectbrowser/*.* ' ) ) ,
2004-09-01 07:31:14 +00:00
( ' plugins/checkmetamodel ' , glob ( ' data/plugins/checkmetamodel/*.* ' ) )
2003-03-06 19:28:38 +00:00
] ,
2003-03-11 18:02:11 +00:00
scripts = [ ' bin/gaphor ' ] ,
distclass = Distribution ,
2003-03-04 05:08:40 +00:00
cmdclass = { ' config ' : config_Gaphor ,
' build_py ' : build_py_Gaphor ,
2003-10-13 07:14:46 +00:00
#'install_schemas': install_schemas,
2003-03-11 18:02:11 +00:00
' build ' : build ,
2004-05-10 07:43:23 +00:00
# 'build_ext': BuildExt,
2003-03-11 18:02:11 +00:00
' build_mo ' : build_mo ,
2003-11-27 20:07:10 +00:00
' build_pot ' : build_pot ,
2003-03-11 18:02:11 +00:00
' install ' : install ,
2003-10-13 07:14:46 +00:00
' install_lib ' : install_lib_Gaphor ,
2003-03-11 18:02:11 +00:00
' install_mo ' : install_mo ,
2003-03-06 19:28:38 +00:00
' run ' : run_Gaphor
2003-03-04 05:08:40 +00:00
}
)