<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import os <EOL> import re <EOL> import shutil <EOL> import stat <EOL> import SCons . Action <EOL> from SCons . Util import make_path_relative <EOL> _INSTALLED_FILES = [ ] <EOL> _UNIQUE_INSTALLED_FILES = None <EOL> class CopytreeError ( EnvironmentError ) : <EOL> pass <EOL> def scons_copytree ( src , dst , symlinks = False ) : <EOL> """<STR_LIT>""" <EOL> names = os . listdir ( src ) <EOL> if not os . path . exists ( dst ) : <EOL> os . makedirs ( dst ) <EOL> errors = [ ] <EOL> for name in names : <EOL> srcname = os . path . join ( src , name ) <EOL> dstname = os . path . join ( dst , name ) <EOL> try : <EOL> if symlinks and os . path . islink ( srcname ) : <EOL> linkto = os . readlink ( srcname ) <EOL> os . symlink ( linkto , dstname ) <EOL> elif os . path . isdir ( srcname ) : <EOL> scons_copytree ( srcname , dstname , symlinks ) <EOL> else : <EOL> shutil . copy2 ( srcname , dstname ) <EOL> except ( IOError , os . error ) , why : <EOL> errors . append ( ( srcname , dstname , str ( why ) ) ) <EOL> except CopytreeError , err : <EOL> errors . extend ( err . args [ <NUM_LIT:0> ] ) <EOL> try : <EOL> shutil . copystat ( src , dst ) <EOL> except WindowsError : <EOL> pass <EOL> except OSError , why : <EOL> errors . extend ( ( src , dst , str ( why ) ) ) <EOL> if errors : <EOL> raise CopytreeError , errors <EOL> def copyFunc ( dest , source , env ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isdir ( source ) : <EOL> if os . path . exists ( dest ) : <EOL> if not os . path . isdir ( dest ) : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % ( str ( dest ) , str ( source ) ) ) <EOL> else : <EOL> parent = os . path . split ( dest ) [ <NUM_LIT:0> ] <EOL> if not os . path . exists ( parent ) : <EOL> os . makedirs ( parent ) <EOL> scons_copytree ( source , dest ) <EOL> else : <EOL> shutil . copy2 ( source , dest ) <EOL> st = os . stat ( source ) <EOL> os . chmod ( dest , stat . S_IMODE ( st [ stat . ST_MODE ] ) | stat . S_IWRITE ) <EOL> return <NUM_LIT:0> <EOL> def copyFuncVersionedLib ( dest , source , env ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isdir ( source ) : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % str ( source ) ) <EOL> else : <EOL> try : <EOL> os . remove ( dest ) <EOL> except : <EOL> pass <EOL> shutil . copy2 ( source , dest ) <EOL> st = os . stat ( source ) <EOL> os . chmod ( dest , stat . S_IMODE ( st [ stat . ST_MODE ] ) | stat . S_IWRITE ) <EOL> versionedLibLinks ( dest , source , env ) <EOL> return <NUM_LIT:0> <EOL> def versionedLibVersion ( dest , env ) : <EOL> """<STR_LIT>""" <EOL> Verbose = False <EOL> platform = env . subst ( '<STR_LIT>' ) <EOL> if not ( platform == '<STR_LIT>' or platform == '<STR_LIT>' ) : <EOL> return ( None , None , None ) <EOL> libname = os . path . basename ( dest ) <EOL> install_dir = os . path . dirname ( dest ) <EOL> shlib_suffix = env . subst ( '<STR_LIT>' ) <EOL> result = False <EOL> version_re = re . compile ( "<STR_LIT>" ) <EOL> version_File = None <EOL> if platform == '<STR_LIT>' : <EOL> versioned_re = re . compile ( re . escape ( shlib_suffix + '<STR_LIT:.>' ) + "<STR_LIT>" ) <EOL> result = versioned_re . findall ( libname ) <EOL> if result : <EOL> version_File = version_re . findall ( versioned_re . findall ( libname ) [ - <NUM_LIT:1> ] ) [ - <NUM_LIT:1> ] <EOL> elif platform == '<STR_LIT>' : <EOL> versioned_re = re . compile ( "<STR_LIT>" + re . escape ( shlib_suffix ) ) <EOL> result = versioned_re . findall ( libname ) <EOL> if result : <EOL> version_File = version_re . findall ( versioned_re . findall ( libname ) [ - <NUM_LIT:1> ] ) [ - <NUM_LIT:1> ] <EOL> if Verbose : <EOL> print "<STR_LIT>" , version_File <EOL> if not result : <EOL> return ( None , libname , install_dir ) <EOL> version = None <EOL> try : <EOL> version = env . subst ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> version = None <EOL> if version != version_File : <EOL> print "<STR_LIT>" % ( version , version_File ) <EOL> version = version_File <EOL> return ( version , libname , install_dir ) <EOL> def versionedLibLinks ( dest , source , env ) : <EOL> """<STR_LIT>""" <EOL> Verbose = False <EOL> linknames = [ ] <EOL> version , libname , install_dir = versionedLibVersion ( dest , env ) <EOL> if version != None : <EOL> linknames = SCons . Tool . VersionShLibLinkNames ( version , libname , env ) <EOL> if Verbose : <EOL> print "<STR_LIT>" , linknames <EOL> lib_ver = libname <EOL> for count in range ( len ( linknames ) ) : <EOL> linkname = linknames [ count ] <EOL> fulllinkname = os . path . join ( install_dir , linkname ) <EOL> if Verbose : <EOL> print "<STR_LIT>" , fulllinkname <EOL> if count > <NUM_LIT:0> : <EOL> try : <EOL> os . remove ( lastlinkname ) <EOL> except : <EOL> pass <EOL> os . symlink ( os . path . basename ( fulllinkname ) , lastlinkname ) <EOL> if Verbose : <EOL> print "<STR_LIT>" % ( lastlinkname , os . path . basename ( fulllinkname ) ) <EOL> lastlinkname = fulllinkname <EOL> if len ( linknames ) > <NUM_LIT:0> : <EOL> try : <EOL> os . remove ( lastlinkname ) <EOL> except : <EOL> pass <EOL> os . symlink ( lib_ver , lastlinkname ) <EOL> if Verbose : <EOL> print "<STR_LIT>" % ( lib_ver , lastlinkname ) <EOL> return <EOL> def installFunc ( target , source , env ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> install = env [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> raise SCons . Errors . UserError ( '<STR_LIT>' ) <EOL> assert len ( target ) == len ( source ) , "<STR_LIT>" % ( list ( map ( str , source ) ) , list ( map ( str , target ) ) ) <EOL> for t , s in zip ( target , source ) : <EOL> if install ( t . get_path ( ) , s . get_path ( ) , env ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def installFuncVersionedLib ( target , source , env ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> install = env [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> raise SCons . Errors . UserError ( '<STR_LIT>' ) <EOL> assert len ( target ) == len ( source ) , "<STR_LIT>" % ( list ( map ( str , source ) ) , list ( map ( str , target ) ) ) <EOL> for t , s in zip ( target , source ) : <EOL> if install ( t . get_path ( ) , s . get_path ( ) , env ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def stringFunc ( target , source , env ) : <EOL> installstr = env . get ( '<STR_LIT>' ) <EOL> if installstr : <EOL> return env . subst_target_source ( installstr , <NUM_LIT:0> , target , source ) <EOL> target = str ( target [ <NUM_LIT:0> ] ) <EOL> source = str ( source [ <NUM_LIT:0> ] ) <EOL> if os . path . isdir ( source ) : <EOL> type = '<STR_LIT>' <EOL> else : <EOL> type = '<STR_LIT:file>' <EOL> return '<STR_LIT>' % ( type , source , target ) <EOL> def add_targets_to_INSTALLED_FILES ( target , source , env ) : <EOL> """<STR_LIT>""" <EOL> global _INSTALLED_FILES , _UNIQUE_INSTALLED_FILES <EOL> _INSTALLED_FILES . extend ( target ) <EOL> _UNIQUE_INSTALLED_FILES = None <EOL> return ( target , source ) <EOL> def add_versioned_targets_to_INSTALLED_FILES ( target , source , env ) : <EOL> """<STR_LIT>""" <EOL> global _INSTALLED_FILES , _UNIQUE_INSTALLED_FILES <EOL> Verbose = False <EOL> _INSTALLED_FILES . extend ( target ) <EOL> if Verbose : <EOL> print "<STR_LIT>" , repr ( target ) <EOL> version , libname , install_dir = versionedLibVersion ( target [ <NUM_LIT:0> ] . path , env ) <EOL> if version != None : <EOL> linknames = SCons . Tool . VersionShLibLinkNames ( version , libname , env ) <EOL> for linkname in linknames : <EOL> if Verbose : <EOL> print "<STR_LIT>" % os . path . join ( install_dir , linkname ) <EOL> fulllinkname = os . path . join ( install_dir , linkname ) <EOL> env . SideEffect ( fulllinkname , target [ <NUM_LIT:0> ] ) <EOL> env . Clean ( target [ <NUM_LIT:0> ] , fulllinkname ) <EOL> _INSTALLED_FILES . append ( fulllinkname ) <EOL> if Verbose : <EOL> print "<STR_LIT>" , _INSTALLED_FILES <EOL> _UNIQUE_INSTALLED_FILES = None <EOL> return ( target , source ) <EOL> class DESTDIR_factory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , env , dir ) : <EOL> self . env = env <EOL> self . dir = env . arg2nodes ( dir , env . fs . Dir ) [ <NUM_LIT:0> ] <EOL> def Entry ( self , name ) : <EOL> name = make_path_relative ( name ) <EOL> return self . dir . Entry ( name ) <EOL> def Dir ( self , name ) : <EOL> name = make_path_relative ( name ) <EOL> return self . dir . Dir ( name ) <EOL> install_action = SCons . Action . Action ( installFunc , stringFunc ) <EOL> installas_action = SCons . Action . Action ( installFunc , stringFunc ) <EOL> installVerLib_action = SCons . Action . Action ( installFuncVersionedLib , stringFunc ) <EOL> BaseInstallBuilder = None <EOL> def InstallBuilderWrapper ( env , target = None , source = None , dir = None , ** kw ) : <EOL> if target and dir : <EOL> import SCons . Errors <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" ) <EOL> if not dir : <EOL> dir = target <EOL> import SCons . Script <EOL> install_sandbox = SCons . Script . GetOption ( '<STR_LIT>' ) <EOL> if install_sandbox : <EOL> target_factory = DESTDIR_factory ( env , install_sandbox ) <EOL> else : <EOL> target_factory = env . fs <EOL> try : <EOL> dnodes = env . arg2nodes ( dir , target_factory . Dir ) <EOL> except TypeError : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % str ( dir ) ) <EOL> sources = env . arg2nodes ( source , env . fs . Entry ) <EOL> tgt = [ ] <EOL> for dnode in dnodes : <EOL> for src in sources : <EOL> target = env . fs . Entry ( '<STR_LIT:.>' + os . sep + src . name , dnode ) <EOL> tgt . extend ( BaseInstallBuilder ( env , target , src , ** kw ) ) <EOL> return tgt <EOL> def InstallAsBuilderWrapper ( env , target = None , source = None , ** kw ) : <EOL> result = [ ] <EOL> for src , tgt in map ( lambda x , y : ( x , y ) , source , target ) : <EOL> result . extend ( BaseInstallBuilder ( env , tgt , src , ** kw ) ) <EOL> return result <EOL> BaseVersionedInstallBuilder = None <EOL> def InstallVersionedBuilderWrapper ( env , target = None , source = None , dir = None , ** kw ) : <EOL> if target and dir : <EOL> import SCons . Errors <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" ) <EOL> if not dir : <EOL> dir = target <EOL> import SCons . Script <EOL> install_sandbox = SCons . Script . GetOption ( '<STR_LIT>' ) <EOL> if install_sandbox : <EOL> target_factory = DESTDIR_factory ( env , install_sandbox ) <EOL> else : <EOL> target_factory = env . fs <EOL> try : <EOL> dnodes = env . arg2nodes ( dir , target_factory . Dir ) <EOL> except TypeError : <EOL> raise SCons . Errors . UserError ( "<STR_LIT>" % str ( dir ) ) <EOL> sources = env . arg2nodes ( source , env . fs . Entry ) <EOL> tgt = [ ] <EOL> for dnode in dnodes : <EOL> for src in sources : <EOL> target = env . fs . Entry ( '<STR_LIT:.>' + os . sep + src . name , dnode ) <EOL> tgt . extend ( BaseVersionedInstallBuilder ( env , target , src , ** kw ) ) <EOL> return tgt <EOL> added = None <EOL> def generate ( env ) : <EOL> from SCons . Script import AddOption , GetOption <EOL> global added <EOL> if not added : <EOL> added = <NUM_LIT:1> <EOL> AddOption ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> type = "<STR_LIT:string>" , <EOL> action = "<STR_LIT:store>" , <EOL> help = '<STR_LIT>' ) <EOL> global BaseInstallBuilder <EOL> if BaseInstallBuilder is None : <EOL> install_sandbox = GetOption ( '<STR_LIT>' ) <EOL> if install_sandbox : <EOL> target_factory = DESTDIR_factory ( env , install_sandbox ) <EOL> else : <EOL> target_factory = env . fs <EOL> BaseInstallBuilder = SCons . Builder . Builder ( <EOL> action = install_action , <EOL> target_factory = target_factory . Entry , <EOL> source_factory = env . fs . Entry , <EOL> multi = <NUM_LIT:1> , <EOL> emitter = [ add_targets_to_INSTALLED_FILES , ] , <EOL> name = '<STR_LIT>' ) <EOL> global BaseVersionedInstallBuilder <EOL> if BaseVersionedInstallBuilder is None : <EOL> install_sandbox = GetOption ( '<STR_LIT>' ) <EOL> if install_sandbox : <EOL> target_factory = DESTDIR_factory ( env , install_sandbox ) <EOL> else : <EOL> target_factory = env . fs <EOL> BaseVersionedInstallBuilder = SCons . Builder . Builder ( <EOL> action = installVerLib_action , <EOL> target_factory = target_factory . Entry , <EOL> source_factory = env . fs . Entry , <EOL> multi = <NUM_LIT:1> , <EOL> emitter = [ add_versioned_targets_to_INSTALLED_FILES , ] , <EOL> name = '<STR_LIT>' ) <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = InstallBuilderWrapper <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = InstallAsBuilderWrapper <EOL> env [ '<STR_LIT>' ] [ '<STR_LIT>' ] = InstallVersionedBuilderWrapper <EOL> try : <EOL> env [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> env [ '<STR_LIT>' ] = copyFunc <EOL> try : <EOL> env [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> env [ '<STR_LIT>' ] = copyFuncVersionedLib <EOL> def exists ( env ) : <EOL> return <NUM_LIT:1> </s>
