Changeset View
Changeset View
Standalone View
Standalone View
ext/python/Tools/freeze/freeze.py
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | def main(): | ||||
modargs = 0 | modargs = 0 | ||||
debug = 1 | debug = 1 | ||||
odir = '' | odir = '' | ||||
win = sys.platform[:3] == 'win' | win = sys.platform[:3] == 'win' | ||||
replace_paths = [] # settable with -r option | replace_paths = [] # settable with -r option | ||||
error_if_any_missing = 0 | error_if_any_missing = 0 | ||||
# default the exclude list for each platform | # default the exclude list for each platform | ||||
if win: exclude = exclude + [ | if win: exclude = exclude + [ | ||||
Lint: PEP8 E701: multiple statements on one line (colon) | |||||
'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', | 'dos', 'dospath', 'mac', 'macpath', 'macfs', 'MACFS', 'posix', | ||||
'os2', 'ce', 'riscos', 'riscosenviron', 'riscospath', | 'os2', 'ce', 'riscos', 'riscosenviron', 'riscospath', | ||||
] | ] | ||||
fail_import = exclude[:] | fail_import = exclude[:] | ||||
# output files | # output files | ||||
frozen_c = 'frozen.c' | frozen_c = 'frozen.c' | ||||
config_c = 'config.c' | config_c = 'config.c' | ||||
target = 'a.out' # normally derived from script name | target = 'a.out' # normally derived from script name | ||||
makefile = 'Makefile' | makefile = 'Makefile' | ||||
subsystem = 'console' | subsystem = 'console' | ||||
# parse command line by first replacing any "-i" options with the | # parse command line by first replacing any "-i" options with the | ||||
# file contents. | # file contents. | ||||
pos = 1 | pos = 1 | ||||
while pos < len(sys.argv)-1: | while pos < len(sys.argv)-1: | ||||
# last option can not be "-i", so this ensures "pos+1" is in range! | # last option can not be "-i", so this ensures "pos+1" is in range! | ||||
if sys.argv[pos] == '-i': | if sys.argv[pos] == '-i': | ||||
try: | try: | ||||
options = open(sys.argv[pos+1]).read().split() | options = open(sys.argv[pos+1]).read().split() | ||||
except IOError, why: | except IOError as why: | ||||
usage("File name '%s' specified with the -i option " | usage("File name '%s' specified with the -i option " | ||||
"can not be read - %s" % (sys.argv[pos+1], why) ) | "can not be read - %s" % (sys.argv[pos+1], why) ) | ||||
# Replace the '-i' and the filename with the read params. | # Replace the '-i' and the filename with the read params. | ||||
sys.argv[pos:pos+2] = options | sys.argv[pos:pos+2] = options | ||||
pos = pos + len(options) - 1 # Skip the name and the included args. | pos = pos + len(options) - 1 # Skip the name and the included args. | ||||
pos = pos + 1 | pos = pos + 1 | ||||
# Now parse the command line with the extras inserted. | # Now parse the command line with the extras inserted. | ||||
try: | try: | ||||
opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:b:qs:wX:x:l:') | opts, args = getopt.getopt(sys.argv[1:], 'r:a:dEe:hmo:p:P:b:qs:wX:x:l:') | ||||
except getopt.error, msg: | except getopt.error as msg: | ||||
usage('getopt error: ' + str(msg)) | usage('getopt error: ' + str(msg)) | ||||
# process option arguments | # process option arguments | ||||
for o, a in opts: | for o, a in opts: | ||||
if o == '-h': | if o == '-h': | ||||
print __doc__ | print __doc__ | ||||
return | return | ||||
if o == '-b': | if o == '-b': | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | if odir and not os.path.isdir(odir): | ||||
usage('%s: mkdir failed (%s)' % (odir, str(msg))) | usage('%s: mkdir failed (%s)' % (odir, str(msg))) | ||||
base = '' | base = '' | ||||
if odir: | if odir: | ||||
base = os.path.join(odir, '') | base = os.path.join(odir, '') | ||||
frozen_c = os.path.join(odir, frozen_c) | frozen_c = os.path.join(odir, frozen_c) | ||||
config_c = os.path.join(odir, config_c) | config_c = os.path.join(odir, config_c) | ||||
target = os.path.join(odir, target) | target = os.path.join(odir, target) | ||||
makefile = os.path.join(odir, makefile) | makefile = os.path.join(odir, makefile) | ||||
if win: extensions_c = os.path.join(odir, extensions_c) | if win: extensions_c = os.path.join(odir, extensions_c) | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
# Handle special entry point requirements | # Handle special entry point requirements | ||||
# (on Windows, some frozen programs do not use __main__, but | # (on Windows, some frozen programs do not use __main__, but | ||||
# import the module directly. Eg, DLLs, Services, etc | # import the module directly. Eg, DLLs, Services, etc | ||||
custom_entry_point = None # Currently only used on Windows | custom_entry_point = None # Currently only used on Windows | ||||
python_entry_is_main = 1 # Is the entry point called __main__? | python_entry_is_main = 1 # Is the entry point called __main__? | ||||
# handle -s option on Windows | # handle -s option on Windows | ||||
if win: | if win: | ||||
import winmakemakefile | import winmakemakefile | ||||
try: | try: | ||||
custom_entry_point, python_entry_is_main = \ | custom_entry_point, python_entry_is_main = \ | ||||
winmakemakefile.get_custom_entry_point(subsystem) | winmakemakefile.get_custom_entry_point(subsystem) | ||||
except ValueError, why: | except ValueError as why: | ||||
usage(why) | usage(why) | ||||
# Actual work starts here... | # Actual work starts here... | ||||
# collect all modules of the program | # collect all modules of the program | ||||
dir = os.path.dirname(scriptfile) | dir = os.path.dirname(scriptfile) | ||||
path[0] = dir | path[0] = dir | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | def main(): | ||||
# report unknown modules | # report unknown modules | ||||
if unknown: | if unknown: | ||||
sys.stderr.write('Warning: unknown modules remain: %s\n' % | sys.stderr.write('Warning: unknown modules remain: %s\n' % | ||||
' '.join(unknown)) | ' '.join(unknown)) | ||||
# windows gets different treatment | # windows gets different treatment | ||||
if win: | if win: | ||||
# Taking a shortcut here... | # Taking a shortcut here... | ||||
import winmakemakefile, checkextensions_win32 | import winmakemakefile, checkextensions_win32 | ||||
Lint: PEP8 E401 multiple imports on one line Lint: PEP8 E401: multiple imports on one line | |||||
checkextensions_win32.write_extension_table(extensions_c, | checkextensions_win32.write_extension_table(extensions_c, | ||||
frozen_extensions) | frozen_extensions) | ||||
# Create a module definition for the bootstrap C code. | # Create a module definition for the bootstrap C code. | ||||
xtras = [frozenmain_c, os.path.basename(frozen_c), | xtras = [frozenmain_c, os.path.basename(frozen_c), | ||||
frozendllmain_c, os.path.basename(extensions_c)] + files | frozendllmain_c, os.path.basename(extensions_c)] + files | ||||
maindefn = checkextensions_win32.CExtension( '__main__', xtras ) | maindefn = checkextensions_win32.CExtension( '__main__', xtras ) | ||||
frozen_extensions.append( maindefn ) | frozen_extensions.append( maindefn ) | ||||
outfp = open(makefile, 'w') | outfp = open(makefile, 'w') | ||||
Show All 24 Lines | def main(): | ||||
if os.path.exists(makefile_in): | if os.path.exists(makefile_in): | ||||
makevars = parsesetup.getmakevars(makefile_in) | makevars = parsesetup.getmakevars(makefile_in) | ||||
for key in makevars.keys(): | for key in makevars.keys(): | ||||
somevars[key] = makevars[key] | somevars[key] = makevars[key] | ||||
somevars['CFLAGS'] = ' '.join(cflags) # override | somevars['CFLAGS'] = ' '.join(cflags) # override | ||||
somevars['CPPFLAGS'] = ' '.join(cppflags) # override | somevars['CPPFLAGS'] = ' '.join(cppflags) # override | ||||
files = [base_config_c, base_frozen_c] + \ | files = [base_config_c, base_frozen_c] + \ | ||||
files + supp_sources + addfiles + libs + \ | files + supp_sources + addfiles + libs + \ | ||||
Lint: PEP8 E222 multiple spaces after operator Lint: PEP8 E222: multiple spaces after operator | |||||
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] | ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)'] | ||||
outfp = bkfile.open(makefile, 'w') | outfp = bkfile.open(makefile, 'w') | ||||
try: | try: | ||||
makemakefile.makemakefile(outfp, somevars, files, base_target) | makemakefile.makemakefile(outfp, somevars, files, base_target) | ||||
finally: | finally: | ||||
outfp.close() | outfp.close() | ||||
Show All 19 Lines |
multiple statements on one line (colon)