2003-03-04 05:08:40 +00:00
#!/usr/bin/env python
#
# setup.py for Gaphor
#
# vim:sw=4:et
""" Gaphor
"""
MAJOR_VERSION = 0
MINOR_VERSION = 2
MICRO_VERSION = 0
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
from commands import getoutput , getstatusoutput
from distutils . core import setup , Command
from distutils . command . build_py import build_py
2003-03-11 18:02:11 +00:00
#from distutils.command.install import install
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
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 ) ) ,
2003-05-03 07:15:44 +00:00
( ' pygtk_version ' , ( 1 , 99 , 16 ) ) )
2003-05-13 19:31:14 +00:00
self . module_check ( ' gnome ' )
self . module_check ( ' gnome.ui ' )
self . module_check ( ' gnome.canvas ' )
self . module_check ( ' bonobo ' )
self . module_check ( ' bonobo.ui ' )
self . module_check ( ' gconf ' )
self . module_check ( ' diacanvas ' , ( ' diacanvas_version ' , ( 0 , 9 , 2 ) ) )
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. '
print ' You can run Gaphor by typing: python setup.py run '
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
class build_py_Gaphor ( build_py ) :
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 ) :
build_py . run ( self )
2003-05-03 07:15:44 +00:00
sys . path . insert ( 0 , self . build_lib )
2003-03-06 19:28:38 +00:00
self . generate_version ( )
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
gen = ' utils/genUML2.py '
2003-05-13 19:31:14 +00:00
overrides = ' gaphor/UML/uml2.override '
2003-05-03 07:15:44 +00:00
model = ' doc/UML2.gaphor '
py_model = ' gaphor/UML/uml2.py '
outfile = os . path . join ( self . build_lib , py_model )
2003-03-06 19:28:38 +00:00
self . mkpath ( os . path . dirname ( outfile ) )
2003-05-03 07:15:44 +00:00
if self . force or newer ( model , outfile ) or newer ( gen , outfile ) :
print ' generating %s from %s ... ' % ( py_model , model )
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-03-06 19:28:38 +00:00
def generate_version ( self ) :
2003-03-11 18:02:11 +00:00
""" Create a file gaphor/version.py which contains the current version.
"""
2003-05-03 07:15:44 +00:00
print ' generating gaphor/version.py '
2003-03-06 19:28:38 +00:00
outfile = os . path . join ( self . build_lib , ' gaphor/version.py ' )
self . mkpath ( os . path . dirname ( outfile ) )
f = open ( outfile , ' w ' )
f . write ( ' VERSION= \' %s \' ' % VERSION )
f . close ( )
self . byte_compile ( [ outfile ] )
2003-03-04 05:08:40 +00:00
class install_config ( Command ) :
description = " Install a configuration (using GConf). "
user_options = [
2003-05-13 19:31:14 +00:00
( ' install-data= ' , None , ' installation directory for data files ' ) ,
( ' 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
self . force = None
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-05-13 19:31:14 +00:00
import gconf
self . gconf_client = gconf . client_get_default ( )
self . _set_value ( ' datadir ' , 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 )
apply ( getattr ( self . gconf_client , ' set_ ' + type ) ,
( GCONF_DOMAIN + key , value ) )
2003-03-04 05:08:40 +00:00
install . sub_commands . append ( ( ' install_config ' , None ) )
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-03-11 18:02:11 +00:00
from gaphor import Gaphor
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 :
Gaphor ( ) . main ( )
2003-03-06 19:28:38 +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) " ,
long_description = """
Gaphor is a UML modeling tool written in Python . It uses the GNOME2
environment for user interaction . """ ,
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.ui.command ' ,
' gaphor.misc '
2003-03-04 05:08:40 +00:00
] ,
2003-03-11 18:02:11 +00:00
# data files are relative to <prefix>/share/gaphor (see setup.cfg)
data_files = [ ( ' ' , [ ' data/gaphor-main-ui.xml ' ,
2003-05-13 19:31:14 +00:00
' data/gaphor-diagram-ui.xml ' ,
' data/gaphor-editor-ui.xml ' ,
' data/gaphor.dtd ' ] ) ,
( ' pixmaps ' , glob ( ' data/pixmaps/*.png ' ) )
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 ,
' install_config ' : install_config ,
2003-03-11 18:02:11 +00:00
' build ' : build ,
' build_mo ' : build_mo ,
' install ' : install ,
' install_mo ' : install_mo ,
2003-03-06 19:28:38 +00:00
' run ' : run_Gaphor
2003-03-04 05:08:40 +00:00
}
)