Changeset 1139

Show
Ignore:
Timestamp:
02/28/07 05:11:22 (2 years ago)
Author:
arjanmol
Message:

Cleanup and formalized setup.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/MANIFEST.in

    r751 r1139  
    11include COPYING INSTALL NEWS README TODO AUTHORS run-gaphor.sh 
    22include bin/gaphor 
    3 recursive-include doc usecases.txt ui-design.txt diagram-in-python.txt 
    43recursive-include gaphor *.py 
    54include gaphor/UML/uml2.gaphor 
  • gaphor/trunk/esetup.py

    r1135 r1139  
    4343        # 'PyGTK >= 2.8.0', - Exclude, since it will not build anyway 
    4444        'gaphas >= 0.1.0', 
    45         'zope.interface >= 3.3.0', # - won't compile on windows. 
     45        'zope.component >= 3.3.0', # - won't compile on windows. 
    4646    ], 
    4747 
  • gaphor/trunk/setup.py

    r1127 r1139  
    5151from distutils.command.install_lib import install_lib 
    5252from distutils.dep_util import newer 
     53from distutils.util import byte_compile 
     54from distutils.dir_util import mkpath 
    5355from utils.build_mo import build, build_mo 
    5456from utils.build_pot import build_pot 
     
    150152 
    151153 
    152 class build_Gaphor(build): 
    153  
    154     def run(self): 
    155         self.run_command('config') 
    156         build.run(self) 
    157  
    158  
    159 class version_py: 
    160  
    161     def generate_version(self, dir, data_dir): 
    162         """Create a file gaphor/version.py which contains the current version. 
     154build.sub_commands.insert(0, ('config', None)) 
     155 
     156#class build_Gaphor(build): 
     157
     158#    def run(self): 
     159#        self.run_command('config') 
     160#        build.run(self) 
     161
     162 
     163def generate_version(dir, data_dir): 
     164    """ 
     165    Create a file gaphor/version.py which contains the current version. 
     166    """ 
     167    outfile = os.path.join(dir, 'gaphor', 'version.py') 
     168    print 'generating %s' % outfile, dir, data_dir 
     169    mkpath(os.path.dirname(outfile)) 
     170    f = open(outfile, 'w') 
     171    f.write('"""\nVersion information generated by setup.py. DO NOT EDIT.\n"""\n\n') 
     172    f.write('VERSION=\'%s\'\n' % VERSION) 
     173    # expand backspaces 
     174    f.write('DATA_DIR=\'%s\'\n' % data_dir.replace('\\', '\\\\')) 
     175    if os.name == 'nt': 
     176        home = 'USERPROFILE' 
     177    else: 
     178        home = 'HOME' 
     179    f.write('import os\n') 
     180    f.write('USER_DATA_DIR=os.path.join(os.getenv(\'%s\'), \'.gaphor\')\n' % home) 
     181    f.write('del os\n') 
     182    f.close() 
     183    byte_compile([outfile]) 
     184 
     185 
     186class build_version(Command): 
     187 
     188    user_options = [ 
     189        ('build-lib=','b', "build directory (where to install from)"), 
     190        ('force', 'f', "force installation (overwrite existing files)"), 
     191        ('data-dir', None, "data directory (where images and plugins reside)"), 
     192        ] 
     193    boolean_options = [ 'force' ] 
     194 
     195    def initialize_options(self): 
     196        self.build_lib = None 
     197        self.force = 0 
     198        self.data_dir = None 
     199 
     200    def finalize_options(self): 
     201            self.set_undefined_options('build', 
     202                                       ('build_purelib', 'build_lib'), 
     203                                       ('force', 'force')) 
     204            self.data_dir = os.path.join(os.getcwd(), 'data') 
     205 
     206    def run(self): 
     207        generate_version(self.build_lib, self.data_dir) 
     208 
     209build.sub_commands.insert(0, ('build_version', None)) 
     210 
     211class build_uml(Command): 
     212 
     213    description = "Generate gaphor/UML/uml2.py." 
     214 
     215    user_options = [ 
     216        ('build-lib=','b', "build directory (where to install from)"), 
     217        ('force', 'f', "force installation (overwrite existing files)"), 
     218        ] 
     219 
     220    boolean_options = [ 'force' ] 
     221 
     222    def initialize_options(self): 
     223        self.build_lib = None 
     224        self.force = 0 
     225        self.data_dir = None 
     226 
     227    def finalize_options(self): 
     228            self.set_undefined_options('build', 
     229                                       ('build_lib', 'build_lib'), 
     230                                       ('force', 'force')) 
     231 
     232    def run(self): 
     233        sys.path.insert(0, self.build_lib) 
     234        self.generate_uml2() 
     235 
     236    def generate_uml2(self): 
    163237        """ 
    164         outfile = os.path.join(dir, 'gaphor', 'version.py') 
    165         print 'generating %s' % outfile, dir, data_dir 
    166         self.mkpath(os.path.dirname(outfile)) 
    167         f = open(outfile, 'w') 
    168         f.write('"""\nVersion information generated by setup.py. DO NOT EDIT.\n"""\n\n') 
    169         f.write('VERSION=\'%s\'\n' % VERSION) 
    170         # expand backspaces 
    171         f.write('DATA_DIR=\'%s\'\n' % data_dir.replace('\\', '\\\\')) 
    172         if os.name == 'nt': 
    173             home = 'USERPROFILE' 
    174         else: 
    175             home = 'HOME' 
    176         f.write('import os\n') 
    177         f.write('USER_DATA_DIR=os.path.join(os.getenv(\'%s\'), \'.gaphor\')\n' % home) 
    178         f.write('del os\n') 
    179         f.close() 
    180         self.byte_compile([outfile]) 
    181  
    182  
    183 class build_py_Gaphor(build_py, version_py): 
    184  
    185     description = "build_py and generate gaphor/UML/uml2.py." 
    186  
    187     def run(self): 
    188         build_py.run(self) 
    189         sys.path.insert(0, self.build_lib) 
    190         # All data is stored in the local data directory 
    191         data_dir = os.path.join(os.getcwd(), 'data') 
    192         #data_dir = "os.path.join(os.getcwd(), 'data')" 
    193         self.generate_version(self.build_lib, data_dir) 
    194         self.generate_uml2() 
    195  
    196     def generate_uml2(self): 
    197         """Generate gaphor/UML/uml2.py in the build directory.""" 
     238        Generate gaphor/UML/uml2.py in the build directory. 
     239        """ 
    198240        import utils.genUML2 
    199241        gen = os.path.join('utils', 'genUML2.py') 
     
    211253        else: 
    212254            print 'not generating %s (up-to-date)' % py_model 
    213         self.byte_compile([outfile]) 
    214  
    215  
    216 class install_lib_Gaphor(install_lib, version_py): 
     255        byte_compile([outfile]) 
     256 
     257build.sub_commands.append(('build_uml', None)) 
     258 
     259 
     260class install_version(Command): 
     261 
     262    user_options = [ 
     263        ('install-dir=', 'd', "directory to install to"), 
     264        ('install-data=', 'd', "directory where data files are installed"), 
     265        ] 
     266 
    217267 
    218268    def initialize_options(self): 
    219269        install_lib.initialize_options(self) 
     270        self.install_dir= None 
    220271        self.install_data= None 
    221272 
    222273    def finalize_options(self): 
    223274        install_lib.finalize_options(self) 
     275        self.set_undefined_options('install_lib', 
     276                                   ('install_dir', 'install_dir')) 
    224277        self.set_undefined_options('install_data', 
    225                                    ('install_dir', 'install_data')) 
     278                                   ('install_data', 'install_dir')) 
    226279 
    227280    def run(self): 
     
    233286        skip = len(self.get_finalized_command('install').root or '') 
    234287 
    235         self.generate_version(self.install_dir, self.install_data[skip:]) 
    236         install_lib.run(self) 
    237  
    238  
    239 class install_schemas(Command): 
    240     """Do something like this: 
    241  
    242         GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \ 
    243             gconftool --makefile-install-rule data/gaphor.schemas 
    244  
    245     in a pythonic way. 
    246     """ 
    247  
    248     description = "Install a configuration (using GConf)." 
    249  
    250     user_options = [ 
    251         ('install-data=', None, 'installation directory for data files'), 
    252         ('gconftool', None, 'The gconftool to use for installation'), 
    253         ('gconf-config-source', None, 'Overrule the GConf config source'), 
    254         ('force', 'f', 'force installation (overwrite existing keys)') 
    255     ] 
    256  
    257     boolean_options = ['force'] 
    258  
    259     def initialize_options(self): 
    260         self.install_data = None 
    261         self.gconftool = 'gconftool-2' 
    262         self.gconf_config_source = '' 
    263         self.force = None 
    264         self.schemas_file = 'data/gaphor.schemas' 
    265  
    266     def finalize_options(self): 
    267         self.set_undefined_options('install', 
    268                                    ('force', 'force'), 
    269                                    ('install_data', 'install_data')) 
    270  
    271     def run(self): 
    272         getstatus('GCONF_CONFIG_SOURCE="%s" %s --makefile-install-rule %s' % (self.gconf_config_source, self.gconftool, self.schemas_file)) 
    273  
    274         self._set_value('/schemas/apps/gaphor/data_dir', self.install_data, 'string') 
    275  
    276     def _set_value(self, key, value, type): 
    277         print "setting gconf value '%s' to '%s'" % (key, value) 
    278         #apply(getattr(self.gconf_client, 'set_' + type), 
    279         #      (GCONF_DOMAIN + key, value)) 
    280         getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value)) 
    281  
    282 #install.sub_commands.append(('install_schemas', None)) 
     288        generate_version(self.install_dir, self.install_data[skip:]) 
    283289 
    284290 
     
    314320        print 'Starting Gaphor...' 
    315321        print 'Starting with model file', self.model 
    316         self.run_command('build') 
     322        for cmd_name in self.get_sub_commands(): 
     323            self.run_command(cmd_name) 
    317324 
    318325        import os.path 
     
    377384            print 'Launching Gaphor...' 
    378385            gaphor.main(self.model) 
     386 
     387    sub_commands = [('build', None)] 
     388 
    379389 
    380390class tests_Gaphor(Command): 
     
    459469      scripts=['bin/gaphor', 'bin/gaphorconvert'], 
    460470 
    461 #      distclass=Distribution, 
    462471      cmdclass={'config': config_Gaphor, 
    463                 'build_py': build_py_Gaphor, 
    464                 #'install_schemas': install_schemas, 
    465                 'build': build_Gaphor, 
    466 #                'build_ext': BuildExt, 
     472                'build_uml': build_uml, 
     473                'build_version': build_version, 
    467474                'build_mo': build_mo, 
    468475                'build_pot': build_pot, 
    469                 'install': install, 
    470                 'install_lib': install_lib_Gaphor, 
    471476                'install_mo': install_mo, 
    472477                'run': run_Gaphor, 
  • gaphor/trunk/utils/build_mo.py

    r1124 r1139  
    1010    from distutils.core import Command 
    1111from distutils.dep_util import newer 
    12 from distutils.command.build import build as _build 
    1312import os.path 
    1413import msgfmt 
    1514 
    16 class build(_build): 
    17     description = "New build class, which adds the property to add locales." 
    18  
    19     def initialize_options(self): 
    20         _build.initialize_options(self) 
    21         self.build_locales = None 
    22  
    23     def finalize_options(self): 
    24         _build.finalize_options(self) 
    25         if not self.build_locales: 
    26             self.build_locales = os.path.join(self.build_base, 'locale') 
    27  
    28 build.sub_commands.append(('build_mo', None)) 
    2915 
    3016class build_mo(Command): 
     
    4935    def finalize_options (self): 
    5036        self.set_undefined_options('build', 
    51                                    ('build_locales', 'build_dir'), 
    5237                                   ('force', 'force')) 
     38        if self.build_dir is None: 
     39            self.set_undefined_options('build', 
     40                                       ('build_base', 'build_dir')) 
     41            self.build_dir = os.path.join(self.build_dir, 'linguas') 
     42 
    5343        self.all_linguas = self.all_linguas.split(',') 
    5444 
     
    6858                print 'not converting %s (output up-to-date)' % pofile 
    6959 
     60from distutils.command.build import build 
     61build.sub_commands.append(('build_mo', None)) 
     62 
     63 
     64 
  • gaphor/trunk/utils/build_pot.py

    r1124 r1139  
    141141 
    142142    def create_pot_file(self): 
    143         """Create a new .pot file. This is basically a rework of the 
     143        """ 
     144        Create a new .pot file. This is basically a rework of the 
    144145        main function of pygettext. 
    145146        """ 
  • gaphor/trunk/utils/genUML2.py

    r1121 r1139  
    302302        redefines = l[0] 
    303303 
    304     print 'found', subsets, redefines 
     304    #print 'found', subsets, redefines 
    305305    return subsets, redefines 
    306306 
  • gaphor/trunk/utils/install_mo.py

    r1124 r1139  
    1414except ImportError: 
    1515    from distutils.core import Command 
    16 from distutils.command.install import install as _install 
    1716from distutils.util import change_root 
    1817import os.path 
    1918 
    20 class install(_install): 
    21  
    22     def initialize_options(self): 
    23         _install.initialize_options(self) 
    24         self.install_locales = None 
    25  
    26     def finalize_options(self): 
    27         _install.finalize_options(self) 
    28         #if not self.install_locales: 
    29         self.install_locales = os.path.join(self.install_base, 'share', 'locale') 
    30  
    31 install.sub_commands.append(('install_mo', None)) 
    3219 
    3320class install_mo(Command): 
     
    4330        self.install_dir = None 
    4431        self.build_dir = None 
    45         self.root = None 
    4632        self.all_linguas = None 
    4733 
    4834    def finalize_options(self): 
    49         self.set_undefined_options('build', 
    50                                    ('build_locales', 'build_dir')) 
    51         self.set_undefined_options('install', 
    52                                    ('install_locales', 'install_dir'), 
    53                                    ('root', 'root')) 
     35        self.set_undefined_options('build_mo', 
     36                                   ('build_dir', 'build_dir')) 
     37        if self.install_dir is None: 
     38            self.set_undefined_options('install', 
     39                                       ('prefix', 'install_dir')) 
     40            self.install_dir = os.path.join(self.install_dir, 'share') 
    5441 
    5542        self.name = self.distribution.get_name() 
    5643        self.all_linguas = self.all_linguas.split(',') 
    57  
    58         if self.root: 
    59             self.install_dir = change_root(self.root, self.install_dir) 
    6044 
    6145    def run(self): 
     
    6347            return 
    6448 
    65         for lingua in self.all_linguas: 
    66             mofile = os.path.join(self.build_dir, '%s.mo' % lingua
    67             path = os.path.join(self.install_dir, lingua, 'LC_MESSAGES') 
     49        for lang in self.all_linguas: 
     50            mofile = os.path.join(self.build_dir, '%s.mo' % lang
     51            path = os.path.join(self.install_dir, lang, 'LC_MESSAGES') 
    6852            self.mkpath(path) 
    6953            outfile = os.path.join(path, '%s.mo' % self.name) 
    7054            self.copy_file(mofile, outfile) 
    7155 
     56from distutils.command.install import install 
     57install.sub_commands.append(('install_mo', None))