<s> """<STR_LIT>""" <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> from warnings import warnpy3k <EOL> warnpy3k ( "<STR_LIT>" , stacklevel = <NUM_LIT:2> ) <EOL> import sys <EOL> import os , errno , shutil <EOL> import imp , marshal <EOL> import re <EOL> from copy import deepcopy <EOL> import getopt <EOL> from plistlib import Plist <EOL> from types import FunctionType as function <EOL> class BundleBuilderError ( Exception ) : pass <EOL> class Defaults : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> defaults = self . _getDefaults ( ) <EOL> defaults . update ( kwargs ) <EOL> self . __dict__ . update ( defaults ) <EOL> def _getDefaults ( cls ) : <EOL> defaults = { } <EOL> for base in cls . __bases__ : <EOL> if hasattr ( base , "<STR_LIT>" ) : <EOL> defaults . update ( base . _getDefaults ( ) ) <EOL> for name , value in cls . __dict__ . items ( ) : <EOL> if name [ <NUM_LIT:0> ] != "<STR_LIT:_>" and not isinstance ( value , <EOL> ( function , classmethod ) ) : <EOL> defaults [ name ] = deepcopy ( value ) <EOL> return defaults <EOL> _getDefaults = classmethod ( _getDefaults ) <EOL> class BundleBuilder ( Defaults ) : <EOL> """<STR_LIT>""" <EOL> name = None <EOL> plist = Plist ( CFBundleDevelopmentRegion = "<STR_LIT>" , <EOL> CFBundleInfoDictionaryVersion = "<STR_LIT>" ) <EOL> type = "<STR_LIT>" <EOL> creator = None <EOL> bundle_id = None <EOL> resources = [ ] <EOL> files = [ ] <EOL> libs = [ ] <EOL> builddir = "<STR_LIT>" <EOL> symlink = <NUM_LIT:0> <EOL> verbosity = <NUM_LIT:1> <EOL> destroot = "<STR_LIT>" <EOL> def setup ( self ) : <EOL> self . name , ext = os . path . splitext ( self . name ) <EOL> if not ext : <EOL> ext = "<STR_LIT>" <EOL> bundleextension = ext <EOL> self . bundlepath = pathjoin ( self . builddir , self . name + bundleextension ) <EOL> plist = self . plist <EOL> plist . CFBundleName = self . name <EOL> plist . CFBundlePackageType = self . type <EOL> if self . creator is None : <EOL> if hasattr ( plist , "<STR_LIT>" ) : <EOL> self . creator = plist . CFBundleSignature <EOL> else : <EOL> self . creator = "<STR_LIT>" <EOL> plist . CFBundleSignature = self . creator <EOL> if self . bundle_id : <EOL> plist . CFBundleIdentifier = self . bundle_id <EOL> elif not hasattr ( plist , "<STR_LIT>" ) : <EOL> plist . CFBundleIdentifier = self . name <EOL> def build ( self ) : <EOL> """<STR_LIT>""" <EOL> builddir = self . builddir <EOL> if builddir and not os . path . exists ( builddir ) : <EOL> os . mkdir ( builddir ) <EOL> self . message ( "<STR_LIT>" % repr ( self . bundlepath ) , <NUM_LIT:1> ) <EOL> if os . path . exists ( self . bundlepath ) : <EOL> shutil . rmtree ( self . bundlepath ) <EOL> if os . path . exists ( self . bundlepath + '<STR_LIT>' ) : <EOL> shutil . rmtree ( self . bundlepath + '<STR_LIT>' ) <EOL> bp = self . bundlepath <EOL> self . bundlepath = bp + '<STR_LIT>' <EOL> try : <EOL> os . mkdir ( self . bundlepath ) <EOL> self . preProcess ( ) <EOL> self . _copyFiles ( ) <EOL> self . _addMetaFiles ( ) <EOL> self . postProcess ( ) <EOL> os . rename ( self . bundlepath , bp ) <EOL> finally : <EOL> self . bundlepath = bp <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> def preProcess ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def postProcess ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _addMetaFiles ( self ) : <EOL> contents = pathjoin ( self . bundlepath , "<STR_LIT>" ) <EOL> makedirs ( contents ) <EOL> assert len ( self . type ) == len ( self . creator ) == <NUM_LIT:4> , "<STR_LIT>" <EOL> pkginfo = pathjoin ( contents , "<STR_LIT>" ) <EOL> f = open ( pkginfo , "<STR_LIT:wb>" ) <EOL> f . write ( self . type + self . creator ) <EOL> f . close ( ) <EOL> infoplist = pathjoin ( contents , "<STR_LIT>" ) <EOL> self . plist . write ( infoplist ) <EOL> def _copyFiles ( self ) : <EOL> files = self . files [ : ] <EOL> for path in self . resources : <EOL> files . append ( ( path , pathjoin ( "<STR_LIT>" , "<STR_LIT>" , <EOL> os . path . basename ( path ) ) ) ) <EOL> for path in self . libs : <EOL> files . append ( ( path , pathjoin ( "<STR_LIT>" , "<STR_LIT>" , <EOL> os . path . basename ( path ) ) ) ) <EOL> if self . symlink : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> msg = "<STR_LIT>" <EOL> else : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> msg = "<STR_LIT>" <EOL> files . sort ( ) <EOL> for src , dst in files : <EOL> if os . path . isdir ( src ) : <EOL> self . message ( "<STR_LIT>" % ( msg , src , dst ) , <NUM_LIT:2> ) <EOL> else : <EOL> self . message ( "<STR_LIT>" % ( msg , src , dst ) , <NUM_LIT:2> ) <EOL> dst = pathjoin ( self . bundlepath , dst ) <EOL> if self . symlink : <EOL> symlink ( src , dst , mkdirs = <NUM_LIT:1> ) <EOL> else : <EOL> copy ( src , dst , mkdirs = <NUM_LIT:1> ) <EOL> def message ( self , msg , level = <NUM_LIT:0> ) : <EOL> if level <= self . verbosity : <EOL> indent = "<STR_LIT>" <EOL> if level > <NUM_LIT:1> : <EOL> indent = ( level - <NUM_LIT:1> ) * "<STR_LIT:U+0020>" <EOL> sys . stderr . write ( indent + msg + "<STR_LIT:\n>" ) <EOL> def report ( self ) : <EOL> pass <EOL> if __debug__ : <EOL> PYC_EXT = "<STR_LIT>" <EOL> else : <EOL> PYC_EXT = "<STR_LIT>" <EOL> MAGIC = imp . get_magic ( ) <EOL> USE_ZIPIMPORT = "<STR_LIT>" in sys . builtin_module_names <EOL> SITE_PY = """<STR_LIT>""" <EOL> ZIP_ARCHIVE = "<STR_LIT>" <EOL> SITE_PY_ZIP = SITE_PY + ( "<STR_LIT>" % ZIP_ARCHIVE ) <EOL> def getPycData ( fullname , code , ispkg ) : <EOL> if ispkg : <EOL> fullname += "<STR_LIT>" <EOL> path = fullname . replace ( "<STR_LIT:.>" , os . sep ) + PYC_EXT <EOL> return path , MAGIC + '<STR_LIT>' + marshal . dumps ( code ) <EOL> EXT_LOADER = """<STR_LIT>""" <EOL> MAYMISS_MODULES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> STRIP_EXEC = "<STR_LIT>" <EOL> BOOTSTRAP_SCRIPT = """<STR_LIT>""" <EOL> ARGV_EMULATOR = """<STR_LIT>""" <EOL> PYTHONFRAMEWORKGOODIES = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def isFramework ( ) : <EOL> return sys . exec_prefix . find ( "<STR_LIT>" ) > <NUM_LIT:0> <EOL> LIB = os . path . join ( sys . prefix , "<STR_LIT>" , "<STR_LIT>" + sys . version [ : <NUM_LIT:3> ] ) <EOL> SITE_PACKAGES = os . path . join ( LIB , "<STR_LIT>" ) <EOL> class AppBuilder ( BundleBuilder ) : <EOL> use_zipimport = USE_ZIPIMPORT <EOL> type = "<STR_LIT>" <EOL> platform = "<STR_LIT>" <EOL> mainprogram = None <EOL> executable = None <EOL> nibname = None <EOL> iconfile = None <EOL> symlink_exec = <NUM_LIT:0> <EOL> standalone = <NUM_LIT:0> <EOL> semi_standalone = <NUM_LIT:0> <EOL> python = None <EOL> argv_emulation = <NUM_LIT:0> <EOL> excludeModules = [ ] <EOL> includeModules = [ ] <EOL> includePackages = [ ] <EOL> strip = <NUM_LIT:0> <EOL> pymodules = [ ] <EOL> missingModules = [ ] <EOL> maybeMissingModules = [ ] <EOL> def setup ( self ) : <EOL> if ( ( self . standalone or self . semi_standalone ) <EOL> and self . mainprogram is None ) : <EOL> raise BundleBuilderError , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if self . mainprogram is None and self . executable is None : <EOL> raise BundleBuilderError , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . execdir = pathjoin ( "<STR_LIT>" , self . platform ) <EOL> if self . name is not None : <EOL> pass <EOL> elif self . mainprogram is not None : <EOL> self . name = os . path . splitext ( os . path . basename ( self . mainprogram ) ) [ <NUM_LIT:0> ] <EOL> elif self . executable is not None : <EOL> self . name = os . path . splitext ( os . path . basename ( self . executable ) ) [ <NUM_LIT:0> ] <EOL> if self . name [ - <NUM_LIT:4> : ] != "<STR_LIT>" : <EOL> self . name += "<STR_LIT>" <EOL> if self . executable is None : <EOL> if not self . standalone and not isFramework ( ) : <EOL> self . symlink_exec = <NUM_LIT:1> <EOL> if self . python : <EOL> self . executable = self . python <EOL> else : <EOL> self . executable = sys . executable <EOL> if self . nibname : <EOL> self . plist . NSMainNibFile = self . nibname <EOL> if not hasattr ( self . plist , "<STR_LIT>" ) : <EOL> self . plist . NSPrincipalClass = "<STR_LIT>" <EOL> if self . standalone and isFramework ( ) : <EOL> self . addPythonFramework ( ) <EOL> BundleBuilder . setup ( self ) <EOL> self . plist . CFBundleExecutable = self . name <EOL> if self . standalone or self . semi_standalone : <EOL> self . findDependencies ( ) <EOL> def preProcess ( self ) : <EOL> resdir = "<STR_LIT>" <EOL> if self . executable is not None : <EOL> if self . mainprogram is None : <EOL> execname = self . name <EOL> else : <EOL> execname = os . path . basename ( self . executable ) <EOL> execpath = pathjoin ( self . execdir , execname ) <EOL> if not self . symlink_exec : <EOL> self . files . append ( ( self . destroot + self . executable , execpath ) ) <EOL> self . execpath = execpath <EOL> if self . mainprogram is not None : <EOL> mainprogram = os . path . basename ( self . mainprogram ) <EOL> self . files . append ( ( self . mainprogram , pathjoin ( resdir , mainprogram ) ) ) <EOL> if self . argv_emulation : <EOL> realmainprogram = mainprogram <EOL> mainprogram = '<STR_LIT>' + mainprogram <EOL> resdirpath = pathjoin ( self . bundlepath , resdir ) <EOL> mainprogrampath = pathjoin ( resdirpath , mainprogram ) <EOL> makedirs ( resdirpath ) <EOL> open ( mainprogrampath , "<STR_LIT:w>" ) . write ( ARGV_EMULATOR % locals ( ) ) <EOL> if self . standalone or self . semi_standalone : <EOL> self . includeModules . append ( "<STR_LIT>" ) <EOL> self . includeModules . append ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" not in self . plist : <EOL> self . plist [ "<STR_LIT>" ] = [ <EOL> { "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] <EOL> executable = os . path . basename ( self . executable ) <EOL> execdir = pathjoin ( self . bundlepath , self . execdir ) <EOL> bootstrappath = pathjoin ( execdir , self . name ) <EOL> makedirs ( execdir ) <EOL> if self . standalone or self . semi_standalone : <EOL> hashbang = "<STR_LIT>" <EOL> elif self . python : <EOL> hashbang = self . python <EOL> else : <EOL> hashbang = os . path . realpath ( sys . executable ) <EOL> standalone = self . standalone <EOL> semi_standalone = self . semi_standalone <EOL> optimize = sys . flags . optimize <EOL> open ( bootstrappath , "<STR_LIT:w>" ) . write ( BOOTSTRAP_SCRIPT % locals ( ) ) <EOL> os . chmod ( bootstrappath , <NUM_LIT:0> <NUM_LIT> ) <EOL> if self . iconfile is not None : <EOL> iconbase = os . path . basename ( self . iconfile ) <EOL> self . plist . CFBundleIconFile = iconbase <EOL> self . files . append ( ( self . iconfile , pathjoin ( resdir , iconbase ) ) ) <EOL> def postProcess ( self ) : <EOL> if self . standalone or self . semi_standalone : <EOL> self . addPythonModules ( ) <EOL> if self . strip and not self . symlink : <EOL> self . stripBinaries ( ) <EOL> if self . symlink_exec and self . executable : <EOL> self . message ( "<STR_LIT>" % ( self . executable , <EOL> self . execpath ) , <NUM_LIT:2> ) <EOL> dst = pathjoin ( self . bundlepath , self . execpath ) <EOL> makedirs ( os . path . dirname ( dst ) ) <EOL> os . symlink ( os . path . abspath ( self . executable ) , dst ) <EOL> if self . missingModules or self . maybeMissingModules : <EOL> self . reportMissing ( ) <EOL> def addPythonFramework ( self ) : <EOL> for lib in self . libs : <EOL> if os . path . basename ( lib ) == "<STR_LIT>" : <EOL> return <EOL> frameworkpath = sys . exec_prefix [ : sys . exec_prefix . find ( <EOL> "<STR_LIT>" ) + len ( "<STR_LIT>" ) ] <EOL> version = sys . version [ : <NUM_LIT:3> ] <EOL> frameworkpath = pathjoin ( frameworkpath , "<STR_LIT>" , version ) <EOL> destbase = pathjoin ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , version ) <EOL> for item in PYTHONFRAMEWORKGOODIES : <EOL> src = pathjoin ( frameworkpath , item ) <EOL> dst = pathjoin ( destbase , item ) <EOL> self . files . append ( ( src , dst ) ) <EOL> def _getSiteCode ( self ) : <EOL> if self . use_zipimport : <EOL> return compile ( SITE_PY % { "<STR_LIT>" : self . semi_standalone } , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def addPythonModules ( self ) : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> if self . use_zipimport : <EOL> import zipfile <EOL> relpath = pathjoin ( "<STR_LIT>" , "<STR_LIT>" , ZIP_ARCHIVE ) <EOL> abspath = pathjoin ( self . bundlepath , relpath ) <EOL> zf = zipfile . ZipFile ( abspath , "<STR_LIT:w>" , zipfile . ZIP_DEFLATED ) <EOL> for name , code , ispkg in self . pymodules : <EOL> self . message ( "<STR_LIT>" % name , <NUM_LIT:2> ) <EOL> path , pyc = getPycData ( name , code , ispkg ) <EOL> zf . writestr ( path , pyc ) <EOL> zf . close ( ) <EOL> sitepath = pathjoin ( self . bundlepath , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" + PYC_EXT ) <EOL> writePyc ( self . _getSiteCode ( ) , sitepath ) <EOL> else : <EOL> for name , code , ispkg in self . pymodules : <EOL> if ispkg : <EOL> name += "<STR_LIT>" <EOL> path = name . split ( "<STR_LIT:.>" ) <EOL> path = pathjoin ( "<STR_LIT>" , "<STR_LIT>" , * path ) + PYC_EXT <EOL> if ispkg : <EOL> self . message ( "<STR_LIT>" % path , <NUM_LIT:2> ) <EOL> else : <EOL> self . message ( "<STR_LIT>" % path , <NUM_LIT:2> ) <EOL> abspath = pathjoin ( self . bundlepath , path ) <EOL> makedirs ( os . path . dirname ( abspath ) ) <EOL> writePyc ( code , abspath ) <EOL> def stripBinaries ( self ) : <EOL> if not os . path . exists ( STRIP_EXEC ) : <EOL> self . message ( "<STR_LIT>" <EOL> "<STR_LIT:%s>" % STRIP_EXEC , <NUM_LIT:0> ) <EOL> else : <EOL> import stat <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> def walk ( top ) : <EOL> for name in os . listdir ( top ) : <EOL> path = pathjoin ( top , name ) <EOL> if os . path . islink ( path ) : <EOL> continue <EOL> if os . path . isdir ( path ) : <EOL> walk ( path ) <EOL> else : <EOL> mod = os . stat ( path ) [ stat . ST_MODE ] <EOL> if not ( mod & <NUM_LIT:0> <NUM_LIT:100> ) : <EOL> continue <EOL> relpath = path [ len ( self . bundlepath ) : ] <EOL> self . message ( "<STR_LIT>" % relpath , <NUM_LIT:2> ) <EOL> inf , outf = os . popen4 ( "<STR_LIT>" % <EOL> ( STRIP_EXEC , path ) ) <EOL> output = outf . read ( ) . strip ( ) <EOL> if output : <EOL> self . message ( "<STR_LIT>" % relpath , <NUM_LIT:3> ) <EOL> self . message ( output , <NUM_LIT:3> ) <EOL> walk ( self . bundlepath ) <EOL> def findDependencies ( self ) : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> import modulefinder <EOL> mf = modulefinder . ModuleFinder ( excludes = self . excludeModules ) <EOL> if self . use_zipimport : <EOL> mf . import_hook ( "<STR_LIT>" ) <EOL> site = mf . add_module ( "<STR_LIT>" ) <EOL> site . __code__ = self . _getSiteCode ( ) <EOL> mf . scan_code ( site . __code__ , site ) <EOL> mf . import_hook ( "<STR_LIT>" ) <EOL> includeModules = self . includeModules [ : ] <EOL> for name in self . includePackages : <EOL> includeModules . extend ( findPackageContents ( name ) . keys ( ) ) <EOL> for name in includeModules : <EOL> try : <EOL> mf . import_hook ( name ) <EOL> except ImportError : <EOL> self . missingModules . append ( name ) <EOL> mf . run_script ( self . mainprogram ) <EOL> modules = mf . modules . items ( ) <EOL> modules . sort ( ) <EOL> for name , mod in modules : <EOL> path = mod . __file__ <EOL> if path and self . semi_standalone : <EOL> if path . startswith ( LIB ) and not path . startswith ( SITE_PACKAGES ) : <EOL> continue <EOL> if path and mod . __code__ is None : <EOL> filename = os . path . basename ( path ) <EOL> pathitems = name . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] + [ filename ] <EOL> dstpath = pathjoin ( * pathitems ) <EOL> if self . use_zipimport : <EOL> if name != "<STR_LIT>" : <EOL> dstpath = pathjoin ( "<STR_LIT>" , dstpath ) <EOL> source = EXT_LOADER % { "<STR_LIT:name>" : name , "<STR_LIT:filename>" : dstpath } <EOL> code = compile ( source , "<STR_LIT>" % name , "<STR_LIT>" ) <EOL> mod . __code__ = code <EOL> self . files . append ( ( path , pathjoin ( "<STR_LIT>" , "<STR_LIT>" , dstpath ) ) ) <EOL> if mod . __code__ is not None : <EOL> ispkg = mod . __path__ is not None <EOL> if not self . use_zipimport or name != "<STR_LIT>" : <EOL> self . pymodules . append ( ( name , mod . __code__ , ispkg ) ) <EOL> if hasattr ( mf , "<STR_LIT>" ) : <EOL> missing , maybe = mf . any_missing_maybe ( ) <EOL> else : <EOL> missing = mf . any_missing ( ) <EOL> maybe = [ ] <EOL> self . missingModules . extend ( missing ) <EOL> self . maybeMissingModules . extend ( maybe ) <EOL> def reportMissing ( self ) : <EOL> missing = [ name for name in self . missingModules <EOL> if name not in MAYMISS_MODULES ] <EOL> if self . maybeMissingModules : <EOL> maybe = self . maybeMissingModules <EOL> else : <EOL> maybe = [ name for name in missing if "<STR_LIT:.>" in name ] <EOL> missing = [ name for name in missing if "<STR_LIT:.>" not in name ] <EOL> missing . sort ( ) <EOL> maybe . sort ( ) <EOL> if maybe : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . message ( "<STR_LIT>" <EOL> "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . message ( "<STR_LIT>" <EOL> "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> for name in maybe : <EOL> self . message ( "<STR_LIT>" + name , <NUM_LIT:1> ) <EOL> if missing : <EOL> self . message ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> for name in missing : <EOL> self . message ( "<STR_LIT>" + name , <NUM_LIT:1> ) <EOL> def report ( self ) : <EOL> import pprint <EOL> pprint . pprint ( self . __dict__ ) <EOL> if self . standalone or self . semi_standalone : <EOL> self . reportMissing ( ) <EOL> SUFFIXES = [ _suf for _suf , _mode , _tp in imp . get_suffixes ( ) ] <EOL> identifierRE = re . compile ( r"<STR_LIT>" ) <EOL> def findPackageContents ( name , searchpath = None ) : <EOL> head = name . split ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] <EOL> if identifierRE . match ( head ) is None : <EOL> return { } <EOL> try : <EOL> fp , path , ( ext , mode , tp ) = imp . find_module ( head , searchpath ) <EOL> except ImportError : <EOL> return { } <EOL> modules = { name : None } <EOL> if tp == imp . PKG_DIRECTORY and path : <EOL> files = os . listdir ( path ) <EOL> for sub in files : <EOL> sub , ext = os . path . splitext ( sub ) <EOL> fullname = name + "<STR_LIT:.>" + sub <EOL> if sub != "<STR_LIT>" and fullname not in modules : <EOL> modules . update ( findPackageContents ( fullname , [ path ] ) ) <EOL> return modules <EOL> def writePyc ( code , path ) : <EOL> f = open ( path , "<STR_LIT:wb>" ) <EOL> f . write ( MAGIC ) <EOL> f . write ( "<STR_LIT>" * <NUM_LIT:4> ) <EOL> marshal . dump ( code , f ) <EOL> f . close ( ) <EOL> def copy ( src , dst , mkdirs = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if mkdirs : <EOL> makedirs ( os . path . dirname ( dst ) ) <EOL> if os . path . isdir ( src ) : <EOL> shutil . copytree ( src , dst , symlinks = <NUM_LIT:1> ) <EOL> else : <EOL> shutil . copy2 ( src , dst ) <EOL> def copytodir ( src , dstdir ) : <EOL> """<STR_LIT>""" <EOL> dst = pathjoin ( dstdir , os . path . basename ( src ) ) <EOL> copy ( src , dst ) <EOL> def makedirs ( dir ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . makedirs ( dir ) <EOL> except OSError , why : <EOL> if why . errno != errno . EEXIST : <EOL> raise <EOL> def symlink ( src , dst , mkdirs = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( src ) : <EOL> raise IOError , "<STR_LIT>" % src <EOL> if mkdirs : <EOL> makedirs ( os . path . dirname ( dst ) ) <EOL> os . symlink ( os . path . abspath ( src ) , dst ) <EOL> def pathjoin ( * args ) : <EOL> """<STR_LIT>""" <EOL> for seg in args [ <NUM_LIT:1> : ] : <EOL> assert seg [ <NUM_LIT:0> ] != "<STR_LIT:/>" <EOL> return os . path . join ( * args ) <EOL> cmdline_doc = """<STR_LIT>""" <EOL> def usage ( msg = None ) : <EOL> if msg : <EOL> print msg <EOL> print cmdline_doc <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def main ( builder = None ) : <EOL> if builder is None : <EOL> builder = AppBuilder ( verbosity = <NUM_LIT:1> ) <EOL> shortopts = "<STR_LIT>" <EOL> longopts = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> try : <EOL> options , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , shortopts , longopts ) <EOL> except getopt . error : <EOL> usage ( ) <EOL> for opt , arg in options : <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . builddir = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . name = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . resources . append ( os . path . normpath ( arg ) ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> srcdst = arg . split ( '<STR_LIT::>' ) <EOL> if len ( srcdst ) != <NUM_LIT:2> : <EOL> usage ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> builder . files . append ( srcdst ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . executable = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . mainprogram = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . argv_emulation = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT:-c>' , '<STR_LIT>' ) : <EOL> builder . creator = arg <EOL> elif opt == '<STR_LIT>' : <EOL> builder . bundle_id = arg <EOL> elif opt == '<STR_LIT>' : <EOL> builder . iconfile = arg <EOL> elif opt == "<STR_LIT>" : <EOL> builder . libs . append ( os . path . normpath ( arg ) ) <EOL> elif opt == "<STR_LIT>" : <EOL> builder . nibname = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . plist = Plist . fromFile ( arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . symlink = <NUM_LIT:1> <EOL> elif opt == '<STR_LIT>' : <EOL> builder . symlink_exec = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> usage ( ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . verbosity += <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . verbosity -= <NUM_LIT:1> <EOL> elif opt == '<STR_LIT>' : <EOL> builder . standalone = <NUM_LIT:1> <EOL> elif opt == '<STR_LIT>' : <EOL> builder . semi_standalone = <NUM_LIT:1> <EOL> elif opt == '<STR_LIT>' : <EOL> builder . python = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . excludeModules . append ( arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> builder . includeModules . append ( arg ) <EOL> elif opt == '<STR_LIT>' : <EOL> builder . includePackages . append ( arg ) <EOL> elif opt == '<STR_LIT>' : <EOL> builder . strip = <NUM_LIT:1> <EOL> elif opt == '<STR_LIT>' : <EOL> builder . destroot = arg <EOL> elif opt == '<STR_LIT>' : <EOL> builder . use_zipimport = False <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> usage ( "<STR_LIT>" ) <EOL> command = args [ <NUM_LIT:0> ] <EOL> if command == "<STR_LIT>" : <EOL> builder . setup ( ) <EOL> builder . build ( ) <EOL> elif command == "<STR_LIT>" : <EOL> builder . setup ( ) <EOL> builder . report ( ) <EOL> elif command == "<STR_LIT>" : <EOL> usage ( ) <EOL> else : <EOL> usage ( "<STR_LIT>" % command ) <EOL> def buildapp ( ** kwargs ) : <EOL> builder = AppBuilder ( ** kwargs ) <EOL> main ( builder ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
