<s> from setuptools import Command <EOL> from setuptools . archive_util import unpack_archive <EOL> from distutils import log , dir_util <EOL> import os , shutil , pkg_resources <EOL> class install_egg_info ( Command ) : <EOL> """<STR_LIT>""" <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , "<STR_LIT>" ) , <EOL> ] <EOL> def initialize_options ( self ) : <EOL> self . install_dir = None <EOL> def finalize_options ( self ) : <EOL> self . set_undefined_options ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ei_cmd = self . get_finalized_command ( "<STR_LIT>" ) <EOL> basename = pkg_resources . Distribution ( <EOL> None , None , ei_cmd . egg_name , ei_cmd . egg_version <EOL> ) . egg_name ( ) + '<STR_LIT>' <EOL> self . source = ei_cmd . egg_info <EOL> self . target = os . path . join ( self . install_dir , basename ) <EOL> self . outputs = [ self . target ] <EOL> def run ( self ) : <EOL> self . run_command ( '<STR_LIT>' ) <EOL> target = self . target <EOL> if os . path . isdir ( self . target ) and not os . path . islink ( self . target ) : <EOL> dir_util . remove_tree ( self . target , dry_run = self . dry_run ) <EOL> elif os . path . exists ( self . target ) : <EOL> self . execute ( os . unlink , ( self . target , ) , "<STR_LIT>" + self . target ) <EOL> if not self . dry_run : <EOL> pkg_resources . ensure_directory ( self . target ) <EOL> self . execute ( self . copytree , ( ) , <EOL> "<STR_LIT>" % ( self . source , self . target ) <EOL> ) <EOL> self . install_namespaces ( ) <EOL> def get_outputs ( self ) : <EOL> return self . outputs <EOL> def copytree ( self ) : <EOL> def skimmer ( src , dst ) : <EOL> for skip in '<STR_LIT>' , '<STR_LIT>' : <EOL> if src . startswith ( skip ) or '<STR_LIT:/>' + skip in src : <EOL> return None <EOL> self . outputs . append ( dst ) <EOL> log . debug ( "<STR_LIT>" , src , dst ) <EOL> return dst <EOL> unpack_archive ( self . source , self . target , skimmer ) <EOL> def install_namespaces ( self ) : <EOL> nsp = self . _get_all_ns_packages ( ) <EOL> if not nsp : return <EOL> filename , ext = os . path . splitext ( self . target ) <EOL> filename += '<STR_LIT>' ; self . outputs . append ( filename ) <EOL> log . info ( "<STR_LIT>" , filename ) <EOL> if not self . dry_run : <EOL> f = open ( filename , '<STR_LIT>' ) <EOL> for pkg in nsp : <EOL> pkg = str ( pkg ) <EOL> pth = tuple ( pkg . split ( '<STR_LIT:.>' ) ) <EOL> trailer = '<STR_LIT:\n>' <EOL> if '<STR_LIT:.>' in pkg : <EOL> trailer = ( <EOL> "<STR_LIT>" <EOL> % ( '<STR_LIT:.>' . join ( pth [ : - <NUM_LIT:1> ] ) , pth [ - <NUM_LIT:1> ] ) <EOL> ) <EOL> f . write ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % locals ( ) <EOL> ) <EOL> f . close ( ) <EOL> def _get_all_ns_packages ( self ) : <EOL> nsp = { } <EOL> for pkg in self . distribution . namespace_packages or [ ] : <EOL> pkg = pkg . split ( '<STR_LIT:.>' ) <EOL> while pkg : <EOL> nsp [ '<STR_LIT:.>' . join ( pkg ) ] = <NUM_LIT:1> <EOL> pkg . pop ( ) <EOL> nsp = list ( nsp ) <EOL> nsp . sort ( ) <EOL> return nsp </s>
