<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import os <EOL> import sys <EOL> import imp <EOL> import zipfile <EOL> import shutil <EOL> import inspect <EOL> import struct <EOL> import marshal <EOL> from py2app . build_app import py2app , get_zipfile , Target <EOL> import esky <EOL> from esky . util import create_zipfile <EOL> def freeze ( dist ) : <EOL> """<STR_LIT>""" <EOL> includes = dist . includes <EOL> excludes = dist . excludes <EOL> options = dist . freezer_options <EOL> includes . append ( "<STR_LIT>" ) <EOL> for inc in options . pop ( "<STR_LIT>" , ( ) ) : <EOL> includes . append ( inc ) <EOL> for exc in options . pop ( "<STR_LIT>" , ( ) ) : <EOL> excludes . append ( exc ) <EOL> if "<STR_LIT>" not in includes and "<STR_LIT>" not in excludes : <EOL> excludes . append ( "<STR_LIT>" ) <EOL> options [ "<STR_LIT>" ] = includes <EOL> options [ "<STR_LIT>" ] = excludes <EOL> exes = list ( dist . get_executables ( ) ) <EOL> if not exes : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> cmd = _make_py2app_cmd ( dist . freeze_dir , dist . distribution , options , exes ) <EOL> cmd . run ( ) <EOL> appnm = dist . distribution . get_name ( ) + "<STR_LIT>" <EOL> app_dir = os . path . join ( dist . freeze_dir , appnm ) <EOL> resdir = os . path . join ( app_dir , "<STR_LIT>" ) <EOL> for ( dirnm , _ , filenms ) in os . walk ( resdir ) : <EOL> for nm in filenms : <EOL> if nm . endswith ( "<STR_LIT>" ) : <EOL> pyfile = os . path . join ( dirnm , nm [ : - <NUM_LIT:1> ] ) <EOL> if os . path . exists ( pyfile ) : <EOL> os . unlink ( pyfile + "<STR_LIT:c>" ) <EOL> if nm . endswith ( "<STR_LIT>" ) : <EOL> pyfile = os . path . join ( dirnm , nm [ : - <NUM_LIT:1> ] ) <EOL> if os . path . exists ( pyfile ) : <EOL> os . unlink ( pyfile + "<STR_LIT:o>" ) <EOL> for ( src , dst ) in dist . get_data_files ( ) : <EOL> dst = os . path . join ( app_dir , "<STR_LIT>" , "<STR_LIT>" , dst ) <EOL> dstdir = os . path . dirname ( dst ) <EOL> if not os . path . isdir ( dstdir ) : <EOL> dist . mkpath ( dstdir ) <EOL> dist . copy_file ( src , dst ) <EOL> zfpath = os . path . join ( cmd . lib_dir , get_zipfile ( dist . distribution ) ) <EOL> lib = zipfile . ZipFile ( zfpath , "<STR_LIT:a>" ) <EOL> for ( src , arcnm ) in dist . get_package_data ( ) : <EOL> lib . write ( src , arcnm ) <EOL> lib . close ( ) <EOL> esky_name = dist . distribution . get_name ( ) <EOL> code_source = [ "<STR_LIT>" % ( esky_name , ) ] <EOL> code_source . append ( inspect . getsource ( esky . bootstrap ) ) <EOL> if not dist . compile_bootstrap_exes : <EOL> code_source . append ( _FAKE_ESKY_BOOTSTRAP_MODULE ) <EOL> code_source . append ( _EXTRA_BOOTSTRAP_CODE ) <EOL> code_source . append ( dist . get_bootstrap_code ( ) ) <EOL> code_source . append ( "<STR_LIT>" ) <EOL> code_source . append ( "<STR_LIT>" ) <EOL> code_source = "<STR_LIT:\n>" . join ( code_source ) <EOL> def copy_to_bootstrap_env ( src , dst = None ) : <EOL> if dst is None : <EOL> dst = src <EOL> src = os . path . join ( appnm , src ) <EOL> dist . copy_to_bootstrap_env ( src , dst ) <EOL> if dist . compile_bootstrap_exes : <EOL> for exe in dist . get_executables ( normalise = False ) : <EOL> if not exe . include_in_bootstrap_env : <EOL> continue <EOL> relpath = os . path . join ( "<STR_LIT>" , "<STR_LIT>" , exe . name ) <EOL> dist . compile_to_bootstrap_exe ( exe , code_source , relpath ) <EOL> else : <EOL> pydir = "<STR_LIT>" % sys . version_info [ : <NUM_LIT:2> ] <EOL> for nm in ( "<STR_LIT>" , "<STR_LIT>" + pydir + "<STR_LIT>" , ) : <EOL> try : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" + nm ) <EOL> except Exception , e : <EOL> pass <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> if sys . version_info [ : <NUM_LIT:2> ] < ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" + pydir + "<STR_LIT>" ) <EOL> else : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" + pydir + "<STR_LIT>" <EOL> % sys . version_info [ : <NUM_LIT:2> ] ) <EOL> if "<STR_LIT>" not in sys . builtin_module_names : <EOL> dynload = "<STR_LIT>" + pydir + "<STR_LIT>" <EOL> for nm in os . listdir ( os . path . join ( app_dir , dynload ) ) : <EOL> if nm . startswith ( "<STR_LIT>" ) : <EOL> copy_to_bootstrap_env ( os . path . join ( dynload , nm ) ) <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> bsdir = dist . bootstrap_dir <EOL> if os . path . exists ( os . path . join ( app_dir , "<STR_LIT>" ) ) : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> with open ( bsdir + "<STR_LIT>" , "<STR_LIT>" ) as f : <EOL> pass <EOL> if os . path . exists ( os . path . join ( app_dir , "<STR_LIT>" ) ) : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> with open ( bsdir + "<STR_LIT>" , "<STR_LIT:wb>" ) as f : <EOL> f . write ( imp . get_magic ( ) + struct . pack ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> f . write ( marshal . dumps ( compile ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> if os . path . exists ( os . path . join ( app_dir , "<STR_LIT>" ) ) : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> with open ( bsdir + "<STR_LIT>" , "<STR_LIT:wb>" ) as f : <EOL> f . write ( imp . get_magic ( ) + struct . pack ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> with open ( bsdir + "<STR_LIT>" , "<STR_LIT>" ) as f : <EOL> f . write ( code_source ) <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> for exe in dist . get_executables ( normalise = False ) : <EOL> if not exe . include_in_bootstrap_env : <EOL> continue <EOL> exepath = copy_to_bootstrap_env ( "<STR_LIT>" + exe . name ) <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> if exe . icon is not None : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" + exe . icon ) <EOL> copy_to_bootstrap_env ( "<STR_LIT>" ) <EOL> with open ( os . path . join ( app_dir , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) as f : <EOL> infotxt = f . read ( ) <EOL> for nm in os . listdir ( os . path . join ( app_dir , "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> if "<STR_LIT>" % ( nm , ) in infotxt : <EOL> copy_to_bootstrap_env ( "<STR_LIT>" + nm ) <EOL> def zipit ( dist , bsdir , zfname ) : <EOL> """<STR_LIT>""" <EOL> def get_arcname ( fpath ) : <EOL> return os . path . join ( dist . distribution . get_name ( ) + "<STR_LIT>" , fpath ) <EOL> return create_zipfile ( bsdir , zfname , get_arcname , compress = True ) <EOL> def _make_py2app_cmd ( dist_dir , distribution , options , exes ) : <EOL> exe = exes [ <NUM_LIT:0> ] <EOL> extra_exes = exes [ <NUM_LIT:1> : ] <EOL> cmd = py2app ( distribution ) <EOL> for ( nm , val ) in options . iteritems ( ) : <EOL> setattr ( cmd , nm , val ) <EOL> cmd . dist_dir = dist_dir <EOL> cmd . app = [ Target ( script = exe . script , dest_base = exe . name ) ] <EOL> cmd . extra_scripts = [ e . script for e in extra_exes ] <EOL> cmd . finalize_options ( ) <EOL> cmd . plist [ "<STR_LIT>" ] = exe . name <EOL> old_run = cmd . run <EOL> def new_run ( ) : <EOL> old_deployment_target = os . environ . get ( "<STR_LIT>" , None ) <EOL> old_run ( ) <EOL> if old_deployment_target is None : <EOL> os . environ . pop ( "<STR_LIT>" , None ) <EOL> else : <EOL> os . environ [ "<STR_LIT>" ] = old_deployment_target <EOL> resdir = os . path . join ( dist_dir , distribution . get_name ( ) + "<STR_LIT>" , "<STR_LIT>" ) <EOL> scriptf = os . path . join ( resdir , exe . name + "<STR_LIT>" ) <EOL> if not os . path . exists ( scriptf ) : <EOL> old_scriptf = os . path . basename ( exe . script ) <EOL> old_scriptf = os . path . join ( resdir , old_scriptf ) <EOL> shutil . move ( old_scriptf , scriptf ) <EOL> cmd . run = new_run <EOL> return cmd <EOL> _FAKE_ESKY_BOOTSTRAP_MODULE = """<STR_LIT>""" <EOL> _EXTRA_BOOTSTRAP_CODE = """<STR_LIT>""" </s>
