def prepare_python(platform, ignifuga_src, python_build, options, env): target = get_target(platform) if not isdir(target.tmp): os.makedirs(target.tmp) if prepare_source('Python', SOURCES['PYTHON'], python_build): # Now copy the Setup.dist files python_setup = join(ROOT_DIR, 'external', 'Setup.'+platform) if not isfile(python_setup): error("Can not find Python Setup file for platform") exit() setupfile = join(python_build, 'Modules', 'Setup') shutil.copy(python_setup, setupfile) # Patch import.c cmd = 'patch -p0 -i %s %s' % (join(PATCHES_DIR, 'import.c.diff'), join(python_build, 'Python', 'import.c')) Popen(shlex.split(cmd)).communicate() # Append the Ignifuga sources if ignifuga_src != None: mod = __import__('modules.python.'+platform, fromlist=['prepare']) ignifuga_module = mod.prepare(env, target, options, ignifuga_src, python_build) f = open(setupfile, 'at') f.write(ignifuga_module) f.close() # Append the greenlet module shutil.copy(join(SOURCES['GREENLET'], 'greenlet.c'), join(python_build, 'Modules')) shutil.copy(join(SOURCES['GREENLET'], 'greenlet.h'), join(python_build, 'Modules')) shutil.copy(join(SOURCES['GREENLET'], 'slp_platformselect.h'), join(python_build, 'Modules')) shutil.copytree(join(SOURCES['GREENLET'], 'platform'), join(python_build, 'Modules', 'platform')) # Append the bitarray module shutil.copy(join(SOURCES['BITARRAY'], '_bitarray.c'), join(python_build, 'Modules'))
def load_config(conf): """Load configuration from file.""" log.success('Loading configurations from {file}'.format(file=conf)) config = dict() if conf: try: with open(conf, 'rt') as conf_fd: config = json.load(conf_fd) except FileNotFoundError: log.error('Specified configuration file not found') sys.exit(1) except Exception: log.error('An error occured while parsing configuration file') sys.exit(1) return config
def prepare_python(platform, ignifuga_src, python_build, options, env): target = get_target(platform) if not isdir(target.tmp): os.makedirs(target.tmp) if prepare_source('Python', SOURCES['PYTHON'], python_build): # Now copy the Setup.dist files python_setup = join(ROOT_DIR, 'external', 'Setup.' + platform) if not isfile(python_setup): error("Can not find Python Setup file for platform") exit() setupfile = join(python_build, 'Modules', 'Setup') shutil.copy(python_setup, setupfile) # Patch import.c cmd = 'patch -p0 -i %s %s' % (join(PATCHES_DIR, 'import.c.diff'), join(python_build, 'Python', 'import.c')) Popen(shlex.split(cmd)).communicate() # Append the Ignifuga sources if ignifuga_src != None: mod = __import__('modules.python.' + platform, fromlist=['prepare']) ignifuga_module = mod.prepare(env, target, options, ignifuga_src, python_build) f = open(setupfile, 'at') f.write(ignifuga_module) f.close() # Append the greenlet module shutil.copy(join(SOURCES['GREENLET'], 'greenlet.c'), join(python_build, 'Modules')) shutil.copy(join(SOURCES['GREENLET'], 'greenlet.h'), join(python_build, 'Modules')) shutil.copy(join(SOURCES['GREENLET'], 'slp_platformselect.h'), join(python_build, 'Modules')) shutil.copytree(join(SOURCES['GREENLET'], 'platform'), join(python_build, 'Modules', 'platform')) # Append the bitarray module shutil.copy(join(SOURCES['BITARRAY'], '_bitarray.c'), join(python_build, 'Modules'))
def build_project_generic(options, platform, target, pp, env=None): package = options.project.split('.')[-1] if package == 'ignifuga': error('Name your project something else than ignifuga please') exit() if package +'.py' == basename(options.main).lower(): error('Your main file can not have the same name as the project. If your project is com.mdqinc.test your main file can not be named test.py') exit() platform_build = join(target.project, platform) main_file = join(platform_build, basename(options.main)) cython_src = join(target.project, platform, 'cython_src') info('Building %s for %s (package: %s)' % (options.project, platform, package)) if not isdir(target.project): os.makedirs(target.project) # Prepare and cythonize project sources prepare_project(target.project_root, platform_build) # Remove main file as it'll be cythonized differently if isfile(main_file): os.unlink(main_file) cfiles, glue_h, glue_c = cythonize(platform_build, package, options, [options.main,]) # Cythonize main file main_file_ct = getctime(abspath(options.main)) main_file_c = join(cython_src, splitext(basename(options.main))[0] + '.cpp') cfiles.append(main_file_c) if not isfile(main_file_c) or getctime(main_file_c) < main_file_ct: log('Cythonizing main file %s' % main_file) mfc = join(cython_src, splitext(basename(main_file))[0] + '.cpp') cmd = 'cython --embed --cplus --include-dir "%s/.." -o "%s" "%s" ' % (ROOT_DIR, mfc, abspath(options.main)) Popen(shlex.split(cmd), cwd = cython_src).communicate() if not isfile(mfc): error ('Could not cythonize main file') exit() # Insert SDL.h into the cythonized file if not options.bare: with file(mfc, 'r') as original: mfc_data = original.read() mfc_data = mfc_data.replace('PyErr_Print();', 'PyErr_Print();fflush(stdout);fflush(stderr);') with file(mfc, 'w') as modified: modified.write("#include \"SDL.h\"\n"+mfc_data) shutil.move(mfc, main_file_c) # Build the executable sources = '' for cf in cfiles: sources += cf + ' ' mod = __import__('modules.project.'+platform, fromlist=['make']) mod.make(options, env, target, sources, cython_src, cfiles) info('Project built successfully')
# Show favorites get_favorites(twitter_api, 0, False) # # Main # if __name__ == '__main__': try: sleep = TimeSleep() # Arguments parsing parser = argparse.ArgumentParser( description= 'Simple Twitter Bot v{version} (sources: git.bmoine.fr/twitter-bot)' .format(version=__version__), epilog='Make your Twitter great again!') parser.add_argument('-c', '--config', type=str, default='config.json', help='path to JSON configuration file') main(parser.parse_args()) except tweepy.error.TweepError as e: log.error('Twitter error: {error}'.format(error=e)) except Exception as e: log.error('An error occured: {error}'.format(error=e))
def build_project_generic(options, platform, target, pp, env=None): package = options.project.split('.')[-1] if package == 'ignifuga': error('Name your project something else than ignifuga please') exit() if package + '.py' == basename(options.main).lower(): error( 'Your main file can not have the same name as the project. If your project is com.mdqinc.test your main file can not be named test.py' ) exit() platform_build = join(target.project, platform) main_file = join(platform_build, basename(options.main)) cython_src = join(target.project, platform, 'cython_src') info('Building %s for %s (package: %s)' % (options.project, platform, package)) if not isdir(target.project): os.makedirs(target.project) # Prepare and cythonize project sources prepare_project(target.project_root, platform_build) # Remove main file as it'll be cythonized differently if isfile(main_file): os.unlink(main_file) cfiles, glue_h, glue_c = cythonize(platform_build, package, options, [ options.main, ]) # Cythonize main file main_file_ct = getctime(abspath(options.main)) main_file_c = join(cython_src, splitext(basename(options.main))[0] + '.cpp') cfiles.append(main_file_c) if not isfile(main_file_c) or getctime(main_file_c) < main_file_ct: log('Cythonizing main file %s' % main_file) mfc = join(cython_src, splitext(basename(main_file))[0] + '.cpp') cmd = 'cython --embed --cplus --include-dir "%s/.." -o "%s" "%s" ' % ( ROOT_DIR, mfc, abspath(options.main)) Popen(shlex.split(cmd), cwd=cython_src).communicate() if not isfile(mfc): error('Could not cythonize main file') exit() # Insert SDL.h into the cythonized file if not options.bare: with file(mfc, 'r') as original: mfc_data = original.read() mfc_data = mfc_data.replace( 'PyErr_Print();', 'PyErr_Print();fflush(stdout);fflush(stderr);') with file(mfc, 'w') as modified: modified.write("#include \"SDL.h\"\n" + mfc_data) shutil.move(mfc, main_file_c) # Build the executable sources = '' for cf in cfiles: sources += cf + ' ' mod = __import__('modules.project.' + platform, fromlist=['make']) mod.make(options, env, target, sources, cython_src, cfiles) info('Project built successfully')
def cythonize(build_dir, package_name, options, skip=[]): files = [] cfiles = [] updatedfiles = [] for f in locate('*.py', build_dir): files.append(f) for f in locate('*.pyx', build_dir): files.append(f) # Cythonize the source files for f in files: if f[len(build_dir):] not in skip and f[len(build_dir) + 1:] not in skip: mf = getctime(f) cf = splitext(f)[0] + '.cpp' if not isfile(cf) or getctime(cf) < mf: ccf = join(build_dir, 'cython_src', cf.replace(os.sep, '+')[len(build_dir) + 1:]) if not isfile(ccf) or getctime(ccf) < mf: log('Cythonizing %s' % basename(f)) cmd = 'cython --cplus --include-dir "%s/.." "%s"' % ( ROOT_DIR, f) p = Popen(shlex.split(cmd), cwd=build_dir) p.communicate() if p.returncode != 0: error("Problem cythonizing file") exit() updatedfiles.append(cf) else: log('Skipping Cython for %s' % basename(f)) cfiles.append(cf) # Flatten the directory structure, replace / by + signs files = cfiles[:] cfiles = [] cython_src = join(build_dir, 'cython_src') if not isdir(cython_src): os.makedirs(cython_src) for f in files: d = f[len(build_dir) + 1:].replace(os.sep, '+') cfile = join(cython_src, d) if isfile(f): shutil.move(f, cfile) cfiles.append(cfile) if f in updatedfiles: updatedfiles.remove(f) updatedfiles.append(cfile) # Walk the files, arrange the package in the proper hierachy glue_h = "" glue_c = "" packages = [ package_name, ] for f in cfiles: filename = basename(f) package = filename.replace('+', '.').replace('.cpp', '') # The last part of the package is the current module module = package.split('.')[-1] # Remove the module from the package package = '.'.join(package.split('.')[:-1]) subpackage = package.split('.') if len(subpackage) > 0: subpackage = subpackage[-1] else: subpackage = '' if package != '': package = package_name + '.' + package else: package = package_name if package not in packages: packages.append(package) # Patch the correct paths and package name in the updated cython generated files if f in updatedfiles: log('Patching %s' % (basename(f), )) if module != '__init__': cmd = SED_CMD + """'s|Py_InitModule4(__Pyx_NAMESTR("\(.*\)")|Py_InitModule4(__Pyx_NAMESTR("%s.\\1")|g' %s""" % ( package, f) else: cmd = SED_CMD + """'s|Py_InitModule4(__Pyx_NAMESTR("\(.*\)")|Py_InitModule4(__Pyx_NAMESTR("%s")|g' %s""" % ( package, f) Popen(shlex.split(cmd), cwd=cython_src).communicate() if module != '__init__': cmd = SED_CMD + """'s|init%s|init%s_%s|g' %s""" % ( module, package.replace('.', '_'), module, f) else: cmd = SED_CMD + """'s|init%s|init%s|g' %s""" % ( subpackage, package.replace('.', '_'), f) Popen(shlex.split(cmd), cwd=cython_src).communicate() cmd = SED_CMD + """'s|__pyx_import_star_type_names|__pyx_import_star_type_names_%s%s|g' %s""" % ( package.replace('.', '_'), module, f) Popen(shlex.split(cmd), cwd=cython_src).communicate() if module != '__init__': glue_h += "extern void init%s_%s(void);\n" % (package.replace( '.', '_'), module) glue_c += ' PyImport_AppendInittab("%s.%s", init%s_%s);\n' % ( package, module, package.replace('.', '_'), module) else: glue_h += "extern void init%s(void);\n" % (package.replace( '.', '_')) glue_c += ' PyImport_AppendInittab("%s", init%s);\n' % ( package, package.replace('.', '_')) if options.rocket and not options.bare: # Special case: add libRocket to the glue glue_h += "extern void init_rocketcore(void);\n" glue_c += ' PyImport_AppendInittab("_rocketcore", init_rocketcore);\n' glue_h += "extern void init_rocketcontrols(void);\n" glue_c += ' PyImport_AppendInittab("_rocketcontrols", init_rocketcontrols);\n' # Make package xxx_glue.c with no frozen modules glue = make_glue(package_name, glue_h, glue_c) f = open(join(cython_src, package_name + '_glue.c'), 'w') f.write(glue) f.close() cfiles.append(join(cython_src, package_name + '_glue.c')) # We have to flatten CPP files as well, because this will all be compiled using Python's build system # which is "flat structure" oriented, ie all .o files end up in python/Modules for f in locate( '*.cpp', build_dir, [cython_src, join(build_dir, 'android_project')]): if f not in cfiles: d = f[len(build_dir) + 1:].replace(os.sep, '+') cfile = join(cython_src, d) if not isfile(cfile) or getmtime(f) > getmtime(cfile): cmd = 'cp %s %s' % (f, cfile) Popen(shlex.split(cmd), cwd=build_dir).communicate() cfiles.append(cfile) return cfiles, glue_h, glue_c
def make_python_freeze(platform, modules, frozen_file): """Get a list of python native modules, return them frozen""" target = get_target(platform) frozen_h = '//Ignifuga auto generated file, contains the following modules: %s\n#include "Python.h"\n\n' % ( ','.join(modules)) mod_sizes = {} # Locate the Python library locations = os.listdir(join(HOST_DIST_DIR, 'lib')) python_version = None for l in locations: if l.startswith('python') and isdir(join(HOST_DIST_DIR, 'lib', l)): python_version = l if python_version == None: error('Could not find Python library') exit() # Copy module source to a temp location modtemp = join(target.tmp, 'freezer') if isdir(modtemp): shutil.rmtree(modtemp) os.makedirs(modtemp) for mod in modules: f = join(HOST_DIST_DIR, 'lib', python_version, mod.replace('.', os.sep)) if isdir(f): # It's a package! f = join(HOST_DIST_DIR, 'lib', python_version, mod.replace('.', os.sep), '__init__') + '.py' newf = join(modtemp, mod.replace('.', os.sep), '__init__') + '.py' else: f = f + '.py' newf = join(modtemp, mod.replace('.', os.sep)) + '.py' if isfile(f): if not isdir(dirname(newf)): os.makedirs(dirname(newf)) shutil.copy(f, newf) # Patch some modules if mod == 'site': # Patch USER_BASE, etc cmd = 'patch -p0 -i %s %s' % (join( PATCHES_DIR, 'site.py.diff'), basename(newf)) Popen(shlex.split(cmd), cwd=dirname(newf)).communicate() elif mod == 'platform': # Add Android platform detection cmd = 'patch -p0 -i %s %s' % (join( PATCHES_DIR, 'platform.py.diff'), basename(newf)) Popen(shlex.split(cmd), cwd=dirname(newf)).communicate() f = open(join(modtemp, 'ignifuga_compile.py'), 'w') f.write(""" import compileall compileall.compile_dir("%s") """ % (modtemp, )) f.close() cmd = '%s %s' % (join(HOST_DIST_DIR, 'bin', 'python'), join(modtemp, 'ignifuga_compile.py')) Popen(shlex.split(cmd), cwd=modtemp).communicate() for mod in modules: is_package = False f = join(modtemp, mod.replace('.', os.sep)) if isdir(f): # It's a package! f = join(modtemp, mod.replace('.', os.sep), '__init__') + '.pyc' is_package = True else: f = f + '.pyc' if isfile(f): log("Freezing...%s" % f) fp = open(f, 'rb') if fp.read(4) == imp.get_magic(): fp.read(4) code = marshal.dumps(marshal.load(fp)) mod_sizes[mod] = len(code) if not is_package else -len( code) # A package is signaled by a negative size frozen_h += 'unsigned char M_ignifuga_frozen_%s[] = {' % mod.replace( '.', '_') for i in range(0, len(code), 16): frozen_h += '\n\t' for c in code[i:i + 16]: frozen_h += '%d,' % ord(c) frozen_h += '\n};\n' fp.close() else: error("Could not Freeze...%s" % f) exit() frozen_h += 'static struct _frozen _PyImport_FrozenModules[] = {\n' for mod in modules: if mod in mod_sizes: frozen_h += '\t{"%s",M_ignifuga_frozen_%s, %d},\n' % ( mod, mod.replace('.', '_'), mod_sizes[mod]) frozen_h += '\t{0, 0, 0} /* sentinel */\n};\n' frozen_h += '\nstruct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;\n' f = open(frozen_file, 'w') f.write(frozen_h) f.close()
if options.available_platforms: print "Available Platforms: 'all',", str(AVAILABLE_PLATFORMS)[1:-1] print "Platform Aliases:" for platform, alias in PLATFORM_ALIASES.iteritems(): print platform, " -> ", alias exit() options.platform = str(options.platform).lower() if options.platform in PLATFORM_ALIASES: options.platform = PLATFORM_ALIASES[options.platform] # Temporarily disable intel_mingw64 if options.platform == 'intel_mingw64': error( "MingW64 support is temporarily disabled until this is solved: https://github.com/python-greenlet/greenlet/issues/20" ) exit(1) if options.platform not in AVAILABLE_PLATFORMS and options.platform != 'all': error('Invalid target platform. Valid platforms: %s' % AVAILABLE_PLATFORMS) parser.print_help() exit(1) if options.platform == 'all': platforms = AVAILABLE_PLATFORMS # Temporarily disable intel_mingw64 platforms.remove('intel_mingw64') else: platforms = [
def cythonize(build_dir, package_name, options, skip=[]): files = [] cfiles = [] updatedfiles = [] for f in locate('*.py', build_dir): files.append(f) for f in locate('*.pyx', build_dir): files.append(f) # Cythonize the source files for f in files: if f[len(build_dir):] not in skip and f[len(build_dir)+1:] not in skip: mf = getctime(f) cf = splitext(f)[0] + '.cpp' if not isfile(cf) or getctime(cf) < mf: ccf = join(build_dir, 'cython_src', cf.replace(os.sep, '+')[len(build_dir)+1:]) if not isfile(ccf) or getctime(ccf) < mf: log('Cythonizing %s' % basename(f)) cmd = 'cython --cplus --include-dir "%s/.." "%s"' % (ROOT_DIR, f) p = Popen(shlex.split(cmd), cwd = build_dir) p.communicate() if p.returncode != 0: error("Problem cythonizing file") exit() updatedfiles.append(cf) else: log('Skipping Cython for %s' % basename(f)) cfiles.append(cf) # Flatten the directory structure, replace / by + signs files = cfiles[:] cfiles = [] cython_src = join(build_dir, 'cython_src') if not isdir(cython_src): os.makedirs(cython_src) for f in files: d = f[len(build_dir)+1:].replace(os.sep, '+') cfile = join(cython_src, d) if isfile(f): shutil.move(f, cfile) cfiles.append(cfile) if f in updatedfiles: updatedfiles.remove(f) updatedfiles.append(cfile) # Walk the files, arrange the package in the proper hierachy glue_h = "" glue_c = "" packages = [package_name,] for f in cfiles: filename = basename(f) package = filename.replace('+', '.').replace('.cpp', '') # The last part of the package is the current module module = package.split('.')[-1] # Remove the module from the package package = '.'.join(package.split('.')[:-1]) subpackage = package.split('.') if len(subpackage)>0: subpackage = subpackage[-1] else: subpackage = '' if package != '': package = package_name+'.'+package else: package = package_name if package not in packages: packages.append(package) # Patch the correct paths and package name in the updated cython generated files if f in updatedfiles: log('Patching %s' % (basename(f),)) if module != '__init__': cmd = SED_CMD + """'s|Py_InitModule4(__Pyx_NAMESTR("\(.*\)")|Py_InitModule4(__Pyx_NAMESTR("%s.\\1")|g' %s""" % (package,f) else: cmd = SED_CMD + """'s|Py_InitModule4(__Pyx_NAMESTR("\(.*\)")|Py_InitModule4(__Pyx_NAMESTR("%s")|g' %s""" % (package,f) Popen(shlex.split(cmd), cwd = cython_src).communicate() if module != '__init__': cmd = SED_CMD + """'s|init%s|init%s_%s|g' %s""" % (module,package.replace('.', '_'),module,f) else: cmd = SED_CMD + """'s|init%s|init%s|g' %s""" % (subpackage,package.replace('.', '_'),f) Popen(shlex.split(cmd), cwd = cython_src).communicate() cmd = SED_CMD + """'s|__pyx_import_star_type_names|__pyx_import_star_type_names_%s%s|g' %s""" % (package.replace('.', '_'),module, f) Popen(shlex.split(cmd), cwd = cython_src).communicate() if module != '__init__': glue_h += "extern void init%s_%s(void);\n" % (package.replace('.', '_'),module) glue_c += ' PyImport_AppendInittab("%s.%s", init%s_%s);\n' % (package, module, package.replace('.', '_'),module) else: glue_h += "extern void init%s(void);\n" % (package.replace('.', '_')) glue_c += ' PyImport_AppendInittab("%s", init%s);\n' % (package, package.replace('.', '_')) if options.rocket and not options.bare: # Special case: add libRocket to the glue glue_h += "extern void init_rocketcore(void);\n" glue_c += ' PyImport_AppendInittab("_rocketcore", init_rocketcore);\n' glue_h += "extern void init_rocketcontrols(void);\n" glue_c += ' PyImport_AppendInittab("_rocketcontrols", init_rocketcontrols);\n' # Make package xxx_glue.c with no frozen modules glue = make_glue(package_name, glue_h, glue_c) f = open(join(cython_src, package_name+'_glue.c'), 'w') f.write(glue) f.close() cfiles.append(join(cython_src, package_name+'_glue.c')) # We have to flatten CPP files as well, because this will all be compiled using Python's build system # which is "flat structure" oriented, ie all .o files end up in python/Modules for f in locate('*.cpp', build_dir, [cython_src, join(build_dir, 'android_project')]): if f not in cfiles: d = f[len(build_dir)+1:].replace(os.sep, '+') cfile = join(cython_src, d) if not isfile(cfile) or getmtime(f) > getmtime(cfile): cmd = 'cp %s %s' % (f, cfile) Popen(shlex.split(cmd), cwd = build_dir).communicate() cfiles.append(cfile) return cfiles, glue_h, glue_c
def make_python_freeze(platform, modules, frozen_file): """Get a list of python native modules, return them frozen""" target = get_target(platform) frozen_h = '//Ignifuga auto generated file, contains the following modules: %s\n#include "Python.h"\n\n' % (','.join(modules)) mod_sizes = {} # Locate the Python library locations = os.listdir(join(HOST_DIST_DIR, 'lib')) python_version = None for l in locations: if l.startswith('python') and isdir(join(HOST_DIST_DIR, 'lib', l)): python_version = l if python_version == None: error('Could not find Python library') exit() # Copy module source to a temp location modtemp = join(target.tmp, 'freezer') if isdir(modtemp): shutil.rmtree(modtemp) os.makedirs(modtemp) for mod in modules: f = join(HOST_DIST_DIR, 'lib', python_version, mod.replace('.', os.sep)) if isdir(f): # It's a package! f = join(HOST_DIST_DIR, 'lib', python_version, mod.replace('.', os.sep), '__init__') + '.py' newf = join(modtemp, mod.replace('.', os.sep), '__init__')+'.py' else: f = f + '.py' newf = join(modtemp, mod.replace('.', os.sep)) + '.py' if isfile(f): if not isdir(dirname(newf)): os.makedirs(dirname(newf)) shutil.copy(f, newf) # Patch some modules if mod == 'site': # Patch USER_BASE, etc cmd = 'patch -p0 -i %s %s' % (join(PATCHES_DIR, 'site.py.diff'), basename(newf)) Popen(shlex.split(cmd), cwd=dirname(newf)).communicate() elif mod == 'platform': # Add Android platform detection cmd = 'patch -p0 -i %s %s' % (join(PATCHES_DIR, 'platform.py.diff'), basename(newf)) Popen(shlex.split(cmd), cwd=dirname(newf)).communicate() f = open(join(modtemp, 'ignifuga_compile.py'), 'w') f.write(""" import compileall compileall.compile_dir("%s") """ % (modtemp,)) f.close() cmd = '%s %s' % (join(HOST_DIST_DIR, 'bin', 'python'), join(modtemp, 'ignifuga_compile.py')) Popen(shlex.split(cmd), cwd = modtemp).communicate() for mod in modules: is_package = False f = join(modtemp, mod.replace('.', os.sep)) if isdir(f): # It's a package! f = join(modtemp, mod.replace('.', os.sep), '__init__') + '.pyc' is_package=True else: f = f + '.pyc' if isfile(f): log("Freezing...%s" % f) fp = open(f, 'rb') if fp.read(4) == imp.get_magic(): fp.read(4) code = marshal.dumps(marshal.load(fp)) mod_sizes[mod] = len(code) if not is_package else -len(code) # A package is signaled by a negative size frozen_h+='unsigned char M_ignifuga_frozen_%s[] = {' % mod.replace('.', '_') for i in range(0, len(code), 16): frozen_h+='\n\t' for c in code[i:i+16]: frozen_h+='%d,' % ord(c) frozen_h+='\n};\n' fp.close() else: error("Could not Freeze...%s" % f) exit() frozen_h +='static struct _frozen _PyImport_FrozenModules[] = {\n' for mod in modules: if mod in mod_sizes: frozen_h+='\t{"%s",M_ignifuga_frozen_%s, %d},\n' % (mod, mod.replace('.', '_'), mod_sizes[mod]) frozen_h +='\t{0, 0, 0} /* sentinel */\n};\n' frozen_h +='\nstruct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;\n' f = open(frozen_file, 'w') f.write(frozen_h) f.close()
if options.available_platforms: print "Available Platforms: 'all',", str(AVAILABLE_PLATFORMS)[1:-1] print "Platform Aliases:" for platform, alias in PLATFORM_ALIASES.iteritems(): print platform, " -> ", alias exit() options.platform = str(options.platform).lower() if options.platform in PLATFORM_ALIASES: options.platform = PLATFORM_ALIASES[options.platform] # Temporarily disable intel_mingw64 if options.platform == 'intel_mingw64': error("MingW64 support is temporarily disabled until this is solved: https://github.com/python-greenlet/greenlet/issues/20") exit(1) if options.platform not in AVAILABLE_PLATFORMS and options.platform != 'all': error('Invalid target platform. Valid platforms: %s' % AVAILABLE_PLATFORMS) parser.print_help() exit(1) if options.platform == 'all': platforms = AVAILABLE_PLATFORMS # Temporarily disable intel_mingw64 platforms.remove('intel_mingw64') else: platforms = [options.platform,] if options.androidndk != None:
def sleep_window(self): """Sleep for window.""" log.error('Maximum requests exceeded, sleeping for {sleep}'.format( sleep=self.pretty_time(self.request_window))) if self.request_window > 0: time.sleep(self.request_window)