<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import os <EOL> import sys <EOL> import shutil <EOL> import tempfile <EOL> import hashlib <EOL> import inspect <EOL> import json <EOL> from glob import glob <EOL> import distutils . command <EOL> from distutils . core import Command <EOL> from distutils . util import convert_path <EOL> import esky . patch <EOL> from esky . util import get_platform , create_zipfile , split_app_version , join_app_version , ESKY_CONTROL_DIR , ESKY_APPDATA_DIR , really_rmtree <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> from esky import winres <EOL> from xml . dom import minidom <EOL> try : <EOL> from esky . bdist_esky import pypyc <EOL> except ImportError , e : <EOL> pypyc = None <EOL> PYPYC_ERROR = e <EOL> COMPILED_BOOTSTRAP_CACHE = None <EOL> else : <EOL> COMPILED_BOOTSTRAP_CACHE = os . path . dirname ( __file__ ) <EOL> if not os . path . isdir ( COMPILED_BOOTSTRAP_CACHE ) : <EOL> COMPILED_BOOTSTRAP_CACHE = None <EOL> try : <EOL> import setuptools <EOL> except ImportError : <EOL> pass <EOL> _FREEZERS = { } <EOL> try : <EOL> from esky . bdist_esky import f_py2exe <EOL> _FREEZERS [ "<STR_LIT>" ] = f_py2exe <EOL> except ImportError : <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> try : <EOL> from esky . bdist_esky import f_py2app <EOL> _FREEZERS [ "<STR_LIT>" ] = f_py2app <EOL> except ImportError : <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> try : <EOL> from esky . bdist_esky import f_bbfreeze <EOL> _FREEZERS [ "<STR_LIT>" ] = f_bbfreeze <EOL> except ImportError : <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> try : <EOL> from esky . bdist_esky import f_cxfreeze <EOL> _FREEZERS [ "<STR_LIT>" ] = f_cxfreeze <EOL> _FREEZERS [ "<STR_LIT>" ] = f_cxfreeze <EOL> _FREEZERS [ "<STR_LIT>" ] = f_cxfreeze <EOL> except ImportError : <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> _FREEZERS [ "<STR_LIT>" ] = None <EOL> class Executable ( unicode ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , script , ** kwds ) : <EOL> if isinstance ( script , basestring ) : <EOL> return unicode . __new__ ( cls , script ) <EOL> else : <EOL> return unicode . __new__ ( cls , __file__ ) <EOL> def __init__ ( self , script , name = None , icon = None , gui_only = None , <EOL> include_in_bootstrap_env = True , ** kwds ) : <EOL> unicode . __init__ ( self ) <EOL> if isinstance ( script , Executable ) : <EOL> script = script . script <EOL> if name is None : <EOL> name = script . name <EOL> if gui_only is None : <EOL> gui_only = script . gui_only <EOL> if not isinstance ( script , basestring ) : <EOL> if name is None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . script = script <EOL> self . include_in_bootstrap_env = include_in_bootstrap_env <EOL> self . icon = icon <EOL> self . _name = name <EOL> self . _gui_only = gui_only <EOL> self . _kwds = kwds <EOL> @ property <EOL> def name ( self ) : <EOL> if self . _name is not None : <EOL> nm = self . _name <EOL> else : <EOL> if not isinstance ( self . script , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> nm = os . path . basename ( self . script ) <EOL> if nm . endswith ( "<STR_LIT>" ) : <EOL> nm = nm [ : - <NUM_LIT:3> ] <EOL> elif nm . endswith ( "<STR_LIT>" ) : <EOL> nm = nm [ : - <NUM_LIT:4> ] <EOL> if sys . platform == "<STR_LIT:win32>" and not nm . endswith ( "<STR_LIT>" ) : <EOL> nm += "<STR_LIT>" <EOL> return nm <EOL> @ property <EOL> def gui_only ( self ) : <EOL> if self . _gui_only is None : <EOL> if not isinstance ( self . script , basestring ) : <EOL> return False <EOL> else : <EOL> return self . script . endswith ( "<STR_LIT>" ) <EOL> else : <EOL> return self . _gui_only <EOL> class bdist_esky ( Command ) : <EOL> """<STR_LIT>""" <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:c>' , <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def initialize_options ( self ) : <EOL> self . dist_dir = None <EOL> self . includes = [ ] <EOL> self . excludes = [ ] <EOL> self . freezer_module = None <EOL> self . freezer_options = { } <EOL> self . bundle_msvcrt = False <EOL> self . dont_run_startup_hooks = False <EOL> self . bootstrap_module = None <EOL> self . bootstrap_code = None <EOL> self . compile_bootstrap_exes = False <EOL> self . _compiled_exes = { } <EOL> self . pre_freeze_callback = None <EOL> self . pre_zip_callback = None <EOL> self . enable_appdata_dir = False <EOL> self . detached_bootstrap_library = False <EOL> self . compress = '<STR_LIT>' <EOL> def finalize_options ( self ) : <EOL> assert self . compress in ( False , None , '<STR_LIT:false>' , '<STR_LIT:none>' , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' <EOL> self . set_undefined_options ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . compile_bootstrap_exes and pypyc is None : <EOL> raise PYPYC_ERROR <EOL> if self . freezer_module is None : <EOL> for freezer_module in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . freezer_module = _FREEZERS [ freezer_module ] <EOL> if self . freezer_module is not None : <EOL> break <EOL> else : <EOL> err = "<STR_LIT>" <EOL> err += "<STR_LIT>" <EOL> raise RuntimeError ( err ) <EOL> else : <EOL> try : <EOL> freezer = _FREEZERS [ self . freezer_module ] <EOL> except KeyError : <EOL> err = "<STR_LIT>" <EOL> err = err % ( self . freezer_module , ) <EOL> raise RuntimeError ( err ) <EOL> else : <EOL> if freezer is None : <EOL> err = "<STR_LIT>" <EOL> err = err % ( self . freezer_module , ) <EOL> raise RuntimeError ( err ) <EOL> self . freezer_module = freezer <EOL> if isinstance ( self . pre_freeze_callback , basestring ) : <EOL> self . pre_freeze_callback = self . _name2func ( self . pre_freeze_callback ) <EOL> if isinstance ( self . pre_zip_callback , basestring ) : <EOL> self . pre_zip_callback = self . _name2func ( self . pre_zip_callback ) <EOL> def _name2func ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:.>" not in name : <EOL> return globals ( ) [ name ] <EOL> modname , funcname = name . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> mod = __import__ ( modname , fromlist = [ funcname ] ) <EOL> return getattr ( mod , funcname ) <EOL> def run ( self ) : <EOL> self . tempdir = tempfile . mkdtemp ( ) <EOL> try : <EOL> self . _run ( ) <EOL> finally : <EOL> really_rmtree ( self . tempdir ) <EOL> def _run ( self ) : <EOL> self . _run_initialise_dirs ( ) <EOL> if self . pre_freeze_callback is not None : <EOL> self . pre_freeze_callback ( self ) <EOL> self . _run_freeze_scripts ( ) <EOL> if self . pre_zip_callback is not None : <EOL> self . pre_zip_callback ( self ) <EOL> self . _generate_filelist_manifest ( ) <EOL> self . _run_create_zipfile ( ) <EOL> def _run_initialise_dirs ( self ) : <EOL> """<STR_LIT>""" <EOL> fullname = self . distribution . get_fullname ( ) <EOL> platform = get_platform ( ) <EOL> self . bootstrap_dir = os . path . join ( self . dist_dir , <EOL> "<STR_LIT>" % ( fullname , platform , ) ) <EOL> if self . enable_appdata_dir : <EOL> self . freeze_dir = os . path . join ( self . bootstrap_dir , ESKY_APPDATA_DIR , <EOL> "<STR_LIT>" % ( fullname , platform , ) ) <EOL> else : <EOL> self . freeze_dir = os . path . join ( self . bootstrap_dir , <EOL> "<STR_LIT>" % ( fullname , platform , ) ) <EOL> if os . path . exists ( self . bootstrap_dir ) : <EOL> really_rmtree ( self . bootstrap_dir ) <EOL> os . makedirs ( self . freeze_dir ) <EOL> def _run_freeze_scripts ( self ) : <EOL> """<STR_LIT>""" <EOL> fullname = self . distribution . get_fullname ( ) <EOL> platform = get_platform ( ) <EOL> self . freezer_module . freeze ( self ) <EOL> if platform != "<STR_LIT:win32>" : <EOL> lockfile = os . path . join ( self . freeze_dir , ESKY_CONTROL_DIR , "<STR_LIT>" ) <EOL> with open ( lockfile , "<STR_LIT:w>" ) as lf : <EOL> lf . write ( "<STR_LIT>" ) <EOL> def _generate_filelist_manifest ( self ) : <EOL> """<STR_LIT>""" <EOL> filelist_file = os . path . join ( self . freeze_dir , ESKY_CONTROL_DIR , esky . patch . ESKY_FILELIST ) <EOL> esky_files = [ ] <EOL> for root , dirs , files in os . walk ( self . bootstrap_dir ) : <EOL> for f in files : <EOL> esky_files . append ( os . path . join ( os . path . relpath ( root , self . bootstrap_dir ) , f ) ) <EOL> with open ( filelist_file , '<STR_LIT:w>' ) as f : <EOL> f . write ( json . dumps ( esky_files ) ) <EOL> def _run_create_zipfile ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . compress : <EOL> fullname = self . distribution . get_fullname ( ) <EOL> platform = get_platform ( ) <EOL> zfname = os . path . join ( self . dist_dir , "<STR_LIT>" % ( fullname , platform , ) ) <EOL> if hasattr ( self . freezer_module , "<STR_LIT>" ) : <EOL> self . freezer_module . zipit ( self , self . bootstrap_dir , zfname ) <EOL> else : <EOL> if self . compress == '<STR_LIT>' : <EOL> print "<STR_LIT>" <EOL> create_zipfile ( self . bootstrap_dir , zfname , compress = True ) <EOL> really_rmtree ( self . bootstrap_dir ) <EOL> elif self . compress == '<STR_LIT>' : <EOL> print "<STR_LIT>" <EOL> create_zipfile ( self . bootstrap_dir , zfname , compress = False ) <EOL> really_rmtree ( self . bootstrap_dir ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> def _obj2code ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> if obj is None : <EOL> return "<STR_LIT>" <EOL> if isinstance ( obj , basestring ) : <EOL> return obj <EOL> if hasattr ( obj , "<STR_LIT>" ) : <EOL> return obj . read ( ) <EOL> try : <EOL> return "<STR_LIT>" . join ( self . _obj2code ( i ) for i in obj ) <EOL> except TypeError : <EOL> return inspect . getsource ( obj ) <EOL> def get_bootstrap_code ( self ) : <EOL> """<STR_LIT>""" <EOL> bscode = self . bootstrap_code <EOL> if bscode is None : <EOL> if self . bootstrap_module is not None : <EOL> bscode = __import__ ( self . bootstrap_module ) <EOL> for submod in self . bootstrap_module . split ( "<STR_LIT:.>" ) [ <NUM_LIT:1> : ] : <EOL> bscode = getattr ( bscode , submod ) <EOL> bscode = self . _obj2code ( bscode ) <EOL> return bscode <EOL> def get_executables ( self , normalise = True ) : <EOL> """<STR_LIT>""" <EOL> if normalise : <EOL> if not os . path . exists ( os . path . join ( self . tempdir , "<STR_LIT>" ) ) : <EOL> os . mkdir ( os . path . join ( self . tempdir , "<STR_LIT>" ) ) <EOL> if self . distribution . has_scripts ( ) : <EOL> for s in self . distribution . scripts : <EOL> if isinstance ( s , Executable ) : <EOL> exe = s <EOL> else : <EOL> exe = Executable ( s ) <EOL> if normalise : <EOL> name = exe . name <EOL> if sys . platform == "<STR_LIT:win32>" and name . endswith ( "<STR_LIT>" ) : <EOL> name = name [ : - <NUM_LIT:4> ] <EOL> if exe . endswith ( "<STR_LIT>" ) : <EOL> ext = "<STR_LIT>" <EOL> else : <EOL> ext = "<STR_LIT>" <EOL> script = os . path . join ( self . tempdir , "<STR_LIT>" , name + ext ) <EOL> if isinstance ( exe . script , basestring ) : <EOL> with open ( exe . script , "<STR_LIT>" ) as f : <EOL> code = f . read ( ) <EOL> else : <EOL> code = self . _obj2code ( exe . script ) <EOL> compile ( code , "<STR_LIT>" , "<STR_LIT>" ) <EOL> with open ( script , "<STR_LIT>" ) as fOut : <EOL> lines = ( ln + "<STR_LIT:\n>" for ln in code . split ( "<STR_LIT:\n>" ) ) <EOL> for ln in lines : <EOL> if ln . strip ( ) : <EOL> if not ln . strip ( ) . startswith ( "<STR_LIT:#>" ) : <EOL> if "<STR_LIT>" not in ln : <EOL> break <EOL> fOut . write ( ln ) <EOL> if not self . dont_run_startup_hooks : <EOL> fOut . write ( "<STR_LIT>" ) <EOL> fOut . write ( "<STR_LIT>" ) <EOL> fOut . write ( "<STR_LIT:\n>" ) <EOL> fOut . write ( ln ) <EOL> for ln in lines : <EOL> fOut . write ( ln ) <EOL> new_exe = Executable ( script ) <EOL> new_exe . __dict__ . update ( exe . __dict__ ) <EOL> new_exe . script = script <EOL> exe = new_exe <EOL> yield exe <EOL> def get_data_files ( self ) : <EOL> """<STR_LIT>""" <EOL> fdir = self . freeze_dir <EOL> if sys . platform == "<STR_LIT:win32>" and self . bundle_msvcrt : <EOL> for ( src , dst ) in self . get_msvcrt_private_assembly_files ( ) : <EOL> yield ( src , dst ) <EOL> if self . distribution . data_files : <EOL> for datafile in self . distribution . data_files : <EOL> if isinstance ( datafile , basestring ) : <EOL> datafile = ( "<STR_LIT>" , [ datafile ] ) <EOL> ( dst , sources ) = datafile <EOL> if os . path . isabs ( dst ) : <EOL> err = "<STR_LIT>" <EOL> err = err % ( dst , ) <EOL> raise ValueError ( err ) <EOL> dst = convert_path ( dst ) <EOL> for src in sources : <EOL> src = convert_path ( src ) <EOL> yield ( src , os . path . join ( dst , os . path . basename ( src ) ) ) <EOL> def get_package_data ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . distribution . package_data : <EOL> for pkg , data in self . distribution . package_data . iteritems ( ) : <EOL> pkg_dir = self . get_package_dir ( pkg ) <EOL> pkg_path = pkg . replace ( "<STR_LIT:.>" , "<STR_LIT:/>" ) <EOL> if isinstance ( data , basestring ) : <EOL> data = [ data ] <EOL> for dpattern in data : <EOL> dfiles = glob ( os . path . join ( pkg_dir , convert_path ( dpattern ) ) ) <EOL> for nm in dfiles : <EOL> arcnm = pkg_path + nm [ len ( pkg_dir ) : ] <EOL> yield ( nm , arcnm ) <EOL> def get_package_dir ( self , pkg ) : <EOL> """<STR_LIT>""" <EOL> inpath = pkg . split ( "<STR_LIT:.>" ) <EOL> outpath = [ ] <EOL> if not self . distribution . package_dir : <EOL> outpath = inpath <EOL> else : <EOL> while inpath : <EOL> try : <EOL> dir = self . distribution . package_dir [ "<STR_LIT:.>" . join ( inpath ) ] <EOL> except KeyError : <EOL> outpath . insert ( <NUM_LIT:0> , inpath [ - <NUM_LIT:1> ] ) <EOL> del inpath [ - <NUM_LIT:1> ] <EOL> else : <EOL> outpath . insert ( <NUM_LIT:0> , dir ) <EOL> break <EOL> else : <EOL> try : <EOL> dir = self . package_dir [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> outpath . insert ( <NUM_LIT:0> , dir ) <EOL> if outpath : <EOL> return os . path . join ( * outpath ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ staticmethod <EOL> def get_msvcrt_private_assembly_files ( ) : <EOL> """<STR_LIT>""" <EOL> cls = bdist_esky <EOL> msvcrt_info = cls . _get_msvcrt_info ( ) <EOL> if msvcrt_info is not None : <EOL> msvcrt_name = msvcrt_info [ <NUM_LIT:0> ] <EOL> for candidate in cls . _find_msvcrt_manifest_files ( msvcrt_name ) : <EOL> manifest_file , msvcrt_dir = candidate <EOL> try : <EOL> with open ( manifest_file , "<STR_LIT:rb>" ) as mf : <EOL> manifest_data = mf . read ( ) <EOL> for info in msvcrt_info : <EOL> if info . encode ( ) not in manifest_data : <EOL> break <EOL> else : <EOL> break <EOL> except EnvironmentError : <EOL> pass <EOL> else : <EOL> err = "<STR_LIT>" % ( msvcrt_info , ) <EOL> raise RuntimeError ( err ) <EOL> manifest_name = msvcrt_name + "<STR_LIT>" <EOL> yield ( manifest_file , os . path . join ( msvcrt_name , manifest_name ) ) <EOL> for fnm in os . listdir ( msvcrt_dir ) : <EOL> yield ( os . path . join ( msvcrt_dir , fnm ) , <EOL> os . path . join ( msvcrt_name , fnm ) ) <EOL> @ staticmethod <EOL> def _get_msvcrt_info ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> manifest_str = winres . get_app_manifest ( ) <EOL> except EnvironmentError : <EOL> return None <EOL> manifest = minidom . parseString ( manifest_str ) <EOL> for assembly in manifest . getElementsByTagName ( "<STR_LIT>" ) : <EOL> name = assembly . attributes [ "<STR_LIT:name>" ] . value <EOL> if name . startswith ( "<STR_LIT>" ) and name . endswith ( "<STR_LIT>" ) : <EOL> version = assembly . attributes [ "<STR_LIT:version>" ] . value <EOL> pubkey = assembly . attributes [ "<STR_LIT>" ] . value <EOL> return ( name , version , pubkey ) <EOL> return None <EOL> @ staticmethod <EOL> def _find_msvcrt_manifest_files ( name ) : <EOL> """<STR_LIT>""" <EOL> cls = bdist_esky <EOL> progfiles = os . path . expandvars ( "<STR_LIT>" ) <EOL> for dnm in os . listdir ( progfiles ) : <EOL> if dnm . lower ( ) . startswith ( "<STR_LIT>" ) : <EOL> dpath = os . path . join ( progfiles , dnm , "<STR_LIT>" , "<STR_LIT>" ) <EOL> for ( subdir , _ , filenames ) in os . walk ( dpath ) : <EOL> for fnm in filenames : <EOL> if name . lower ( ) in fnm . lower ( ) : <EOL> if fnm . lower ( ) . endswith ( "<STR_LIT>" ) : <EOL> mf = os . path . join ( subdir , fnm ) <EOL> md = cls . _find_msvcrt_dir_for_manifest ( name , mf ) <EOL> if md is not None : <EOL> yield ( mf , md ) <EOL> winsxs_m = os . path . expandvars ( "<STR_LIT>" ) <EOL> for fnm in os . listdir ( winsxs_m ) : <EOL> if name . lower ( ) in fnm . lower ( ) : <EOL> if fnm . lower ( ) . endswith ( "<STR_LIT>" ) : <EOL> mf = os . path . join ( winsxs_m , fnm ) <EOL> md = cls . _find_msvcrt_dir_for_manifest ( name , mf ) <EOL> if md is not None : <EOL> yield ( mf , md ) <EOL> winsxs = os . path . expandvars ( "<STR_LIT>" ) <EOL> for fnm in os . listdir ( winsxs ) : <EOL> if name . lower ( ) in fnm . lower ( ) : <EOL> if fnm . lower ( ) . endswith ( "<STR_LIT>" ) : <EOL> mf = os . path . join ( winsxs , fnm ) <EOL> md = cls . _find_msvcrt_dir_for_manifest ( name , mf ) <EOL> if md is not None : <EOL> yield ( mf , md ) <EOL> @ staticmethod <EOL> def _find_msvcrt_dir_for_manifest ( msvcrt_name , manifest_file ) : <EOL> """<STR_LIT>""" <EOL> msvcrt_dir = "<STR_LIT:.>" . join ( manifest_file . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) <EOL> if os . path . isdir ( msvcrt_dir ) : <EOL> return msvcrt_dir <EOL> msvcrt_basename = os . path . basename ( msvcrt_dir ) <EOL> msvcrt_parent = os . path . dirname ( os . path . dirname ( msvcrt_dir ) ) <EOL> msvcrt_dir = os . path . join ( msvcrt_parent , msvcrt_basename ) <EOL> if os . path . isdir ( msvcrt_dir ) : <EOL> return msvcrt_dir <EOL> msvcrt_dir = os . path . join ( msvcrt_parent , msvcrt_name ) <EOL> if os . path . isdir ( msvcrt_dir ) : <EOL> return msvcrt_dir <EOL> return None <EOL> def compile_to_bootstrap_exe ( self , exe , source , relpath = None ) : <EOL> """<STR_LIT>""" <EOL> if not relpath : <EOL> relpath = exe . name <EOL> source = "<STR_LIT>" + source <EOL> cdir = os . path . join ( self . tempdir , "<STR_LIT>" ) <EOL> if not os . path . exists ( cdir ) : <EOL> os . mkdir ( cdir ) <EOL> source_hash = hashlib . md5 ( source ) . hexdigest ( ) <EOL> outname = "<STR_LIT>" % ( source_hash , get_platform ( ) ) <EOL> if exe . gui_only : <EOL> outname += "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> outname += "<STR_LIT>" <EOL> if COMPILED_BOOTSTRAP_CACHE is not None : <EOL> outfile = os . path . join ( COMPILED_BOOTSTRAP_CACHE , outname ) <EOL> if os . path . exists ( outfile ) : <EOL> return self . copy_to_bootstrap_env ( outfile , relpath ) <EOL> try : <EOL> outfile = self . _compiled_exes [ ( source_hash , exe . gui_only ) ] <EOL> except KeyError : <EOL> infile = os . path . join ( cdir , "<STR_LIT>" ) <EOL> outfile = os . path . join ( cdir , outname ) <EOL> with open ( infile , "<STR_LIT>" ) as f : <EOL> f . write ( source ) <EOL> opts = dict ( gui_only = exe . gui_only ) <EOL> pypyc . compile_rpython ( infile , outfile , ** opts ) <EOL> self . _compiled_exes [ ( source_hash , exe . gui_only ) ] = outfile <EOL> if COMPILED_BOOTSTRAP_CACHE is not None : <EOL> cachedfile = os . path . join ( COMPILED_BOOTSTRAP_CACHE , outname ) <EOL> try : <EOL> shutil . copy2 ( outfile , cachedfile ) <EOL> except EnvironmentError : <EOL> pass <EOL> return self . copy_to_bootstrap_env ( outfile , relpath ) <EOL> def copy_to_bootstrap_env ( self , src , dst = None ) : <EOL> """<STR_LIT>""" <EOL> if dst is None : <EOL> dst = src <EOL> srcpath = os . path . join ( self . freeze_dir , src ) <EOL> dstpath = os . path . join ( self . bootstrap_dir , dst ) <EOL> if os . path . isdir ( srcpath ) : <EOL> self . copy_tree ( srcpath , dstpath ) <EOL> else : <EOL> if not os . path . isdir ( os . path . dirname ( dstpath ) ) : <EOL> self . mkpath ( os . path . dirname ( dstpath ) ) <EOL> self . copy_file ( srcpath , dstpath ) <EOL> self . add_to_bootstrap_manifest ( dstpath ) <EOL> return dstpath <EOL> def add_to_bootstrap_manifest ( self , dstpath ) : <EOL> if not os . path . isdir ( os . path . join ( self . freeze_dir , ESKY_CONTROL_DIR ) ) : <EOL> os . mkdir ( os . path . join ( self . freeze_dir , ESKY_CONTROL_DIR ) ) <EOL> f_manifest = os . path . join ( self . freeze_dir , ESKY_CONTROL_DIR , "<STR_LIT>" ) <EOL> with open ( f_manifest , "<STR_LIT>" ) as f_manifest : <EOL> f_manifest . seek ( <NUM_LIT:0> , os . SEEK_END ) <EOL> if os . path . isdir ( dstpath ) : <EOL> for ( dirnm , _ , filenms ) in os . walk ( dstpath ) : <EOL> for fnm in filenms : <EOL> fpath = os . path . join ( dirnm , fnm ) <EOL> dpath = fpath [ len ( self . bootstrap_dir ) + <NUM_LIT:1> : ] <EOL> if os . sep != "<STR_LIT:/>" : <EOL> dpath = dpath . replace ( os . sep , "<STR_LIT:/>" ) <EOL> f_manifest . write ( dpath ) <EOL> f_manifest . write ( "<STR_LIT:\n>" ) <EOL> else : <EOL> dst = dstpath [ len ( self . bootstrap_dir ) + <NUM_LIT:1> : ] <EOL> if os . sep != "<STR_LIT:/>" : <EOL> dst = dst . replace ( os . sep , "<STR_LIT:/>" ) <EOL> f_manifest . write ( dst ) <EOL> f_manifest . write ( "<STR_LIT:\n>" ) <EOL> class bdist_esky_patch ( Command ) : <EOL> """<STR_LIT>""" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> def initialize_options ( self ) : <EOL> self . dist_dir = None <EOL> self . from_version = None <EOL> def finalize_options ( self ) : <EOL> self . set_undefined_options ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def run ( self ) : <EOL> fullname = self . distribution . get_fullname ( ) <EOL> platform = get_platform ( ) <EOL> vdir = "<STR_LIT>" % ( fullname , platform , ) <EOL> appname = split_app_version ( vdir ) [ <NUM_LIT:0> ] <EOL> target_esky = os . path . join ( self . dist_dir , vdir + "<STR_LIT>" ) <EOL> if not os . path . exists ( target_esky ) : <EOL> self . run_command ( "<STR_LIT>" ) <EOL> if self . from_version : <EOL> source_vdir = join_app_version ( appname , self . from_version , platform ) <EOL> source_eskys = [ os . path . join ( self . dist_dir , source_vdir + "<STR_LIT>" ) ] <EOL> else : <EOL> source_eskys = [ ] <EOL> for nm in os . listdir ( self . dist_dir ) : <EOL> if target_esky . endswith ( nm ) : <EOL> continue <EOL> if nm . startswith ( appname + "<STR_LIT:->" ) and nm . endswith ( platform + "<STR_LIT>" ) : <EOL> source_eskys . append ( os . path . join ( self . dist_dir , nm ) ) <EOL> for source_esky in source_eskys : <EOL> target_vdir = os . path . basename ( source_esky ) [ : - <NUM_LIT:4> ] <EOL> target_version = split_app_version ( target_vdir ) [ <NUM_LIT:1> ] <EOL> patchfile = vdir + "<STR_LIT>" % ( target_version , ) <EOL> patchfile = os . path . join ( self . dist_dir , patchfile ) <EOL> print "<STR_LIT>" , target_esky , "<STR_LIT>" , source_esky , "<STR_LIT>" , patchfile <EOL> if not self . dry_run : <EOL> try : <EOL> esky . patch . main ( [ "<STR_LIT>" , "<STR_LIT>" , source_esky , target_esky , patchfile ] ) <EOL> except : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise <EOL> distutils . command . __all__ . append ( "<STR_LIT>" ) <EOL> distutils . command . __all__ . append ( "<STR_LIT>" ) <EOL> sys . modules [ "<STR_LIT>" ] = sys . modules [ "<STR_LIT>" ] <EOL> sys . modules [ "<STR_LIT>" ] = sys . modules [ "<STR_LIT>" ] </s>
