00001 """
00002 distutils classes to override default install, build commands
00003 genarates and installs man file
00004 """
00005
00006 __copyright__ = """
00007 Copyright 2008 Sean Ross-Ross
00008 """
00009 __license__ = """
00010 This file is part of SLIMpy .
00011
00012 SLIMpy is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as published by
00014 the Free Software Foundation, either version 3 of the License, or
00015 (at your option) any later version.
00016
00017 SLIMpy is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021
00022 You should have received a copy of the GNU Lesser General Public License
00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00024 """
00025
00026
00027 from distutils.command.build import build
00028 from distutils.command.install import install
00029 from distutils.core import Command, setup
00030 from distutils.errors import DistutilsOptionError
00031 from os.path import join, exists
00032 from slimproj_core.manfile_gen import genorate_man
00033
00034 class install_man( Command ):
00035 """
00036 installs manfile
00037 """
00038
00039
00040 description = "install an automatially genarated slimproj manfile"
00041
00042
00043
00044 user_options = [( 'dir=', 'd',
00045 "path to install man too" ),
00046 ( 'slimpy-tools=', None,
00047 "additional tools to include in man" ), ]
00048
00049
00050
00051 def initialize_options ( self ):
00052 self.dir = None
00053 self.slimpy_tools = ""
00054
00055
00056
00057 def finalize_options ( self ):
00058 if self.dir is None:
00059 raise DistutilsOptionError, "must supply '--dir' option"
00060
00061
00062 def run ( self ):
00063 from os.path import pathsep,split,splitext
00064 from sys import path as sys_path
00065 if self.slimpy_tools:
00066 for py_module in self.slimpy_tools.split(pathsep):
00067 path,name = split( py_module )
00068 base,ext = splitext(name)
00069 sys_path.insert(0,path)
00070 exec "import %(base)s" %vars()
00071 del sys_path[0]
00072
00073
00074 print " Generateing man contents from slimproj ..."
00075 content = genorate_man()
00076 slimproj_manfile = join( self.dir, 'slimproj.1' )
00077 print " Writing contents to '%s'" %slimproj_manfile
00078 open_manfile = open( slimproj_manfile , 'w' )
00079 open_manfile.write( content )
00080
00081
00082
00083 class build_with_man( build ):
00084 '''
00085 builds man file to 'build_base'/man/
00086 '''
00087
00088 def initialize_options ( self ):
00089 'initialize options'
00090 build.initialize_options( self )
00091
00092
00093 def finalize_options ( self ):
00094 build.finalize_options( self )
00095
00096 self.build_man = join( self.build_base, 'man' )
00097
00098 def run( self ):
00099
00100 build.run( self )
00101 self._run_build_man()
00102
00103
00104 def _run_build_man( self ):
00105 import os
00106
00107 slimproj_manfile = join( self.build_man, 'slimproj.1' )
00108
00109 if not exists( slimproj_manfile ):
00110 if not exists( self.build_man ):
00111 os.makedirs( self.build_man )
00112
00113 print " Generateing man contents from slimproj ..."
00114 content = genorate_man()
00115 print " Writing contents to '%s'" %slimproj_manfile
00116 open_manfile = open( slimproj_manfile , 'w' )
00117 open_manfile.write( content )
00118 return
00119
00120 class install_with_man( install ):
00121 user_options = install.user_options + [( 'install-man=', None, "path to install man too" )]
00122
00123 def initialize_options ( self ):
00124 install.initialize_options( self )
00125 self.install_man = None
00126
00127 def finalize_options ( self ):
00128 install.finalize_options( self )
00129
00130 if self.install_man is None:
00131 install_man = join( self.prefix, 'share', 'man', 'man1' )
00132 self.install_man = install_man
00133
00134
00135 def run( self ):
00136
00137 install.run( self )
00138 build_man = join( self.build_base, 'man' )
00139
00140 self.copy_tree( build_man, self.install_man )
00141
00142
00143
00144 if __name__ == '__main__':
00145 setup( cmdclass={ 'install_man': install_man } )
00146
00147