def test_TCL_TK(config): # TCL_root, TK_root and support/useTK.py print "I: Finding TCL/TK..." if not (target_iswin): saveexcludes = bindepend.excludes bindepend.excludes = {} pattern = [r'libtcl(\d\.\d)?\.(so|dylib)', r'(?i)tcl(\d\d)\.dll'][target_iswin] a = mf.ImportTracker() a.analyze_r('Tkinter') binaries = [] for modnm, mod in a.modules.items(): if isinstance(mod, mf.ExtensionModule): binaries.append((mod.__name__, mod.__file__, 'EXTENSION')) binaries.extend(bindepend.Dependencies(binaries)) binaries.extend(bindepend.Dependencies([('', sys.executable, '')])) for nm, fnm, typ in binaries: mo = re.match(pattern, nm) if mo: ver = mo.group(1) tclbindir = os.path.dirname(fnm) if target_iswin: ver = ver[0] + '.' + ver[1:] elif ver is None: # we found "libtcl.so.0" so we need to get the version from the lib directory for name in os.listdir(tclbindir): mo = re.match(r'tcl(\d.\d)', name) if mo: ver = mo.group(1) print "I: found TCL/TK version %s" % ver open(os.path.join(HOME, 'support', 'useTK.py'), 'w').write(_useTK % (ver, ver)) tclnm = 'tcl%s' % ver tknm = 'tk%s' % ver # Linux: /usr/lib with the .tcl files in /usr/lib/tcl8.3 and /usr/lib/tk8.3 # Windows: Python21/DLLs with the .tcl files in Python21/tcl/tcl8.3 and Python21/tcl/tk8.3 # or D:/Programs/Tcl/bin with the .tcl files in D:/Programs/Tcl/lib/tcl8.0 and D:/Programs/Tcl/lib/tk8.0 if target_iswin: for attempt in ['../tcl', '../lib']: if os.path.exists(os.path.join(tclbindir, attempt, tclnm)): config['TCL_root'] = os.path.join( tclbindir, attempt, tclnm) config['TK_root'] = os.path.join( tclbindir, attempt, tknm) break else: config['TCL_root'] = os.path.join(tclbindir, tclnm) config['TK_root'] = os.path.join(tclbindir, tknm) break else: print "I: could not find TCL/TK" if not target_iswin: bindepend.excludes = saveexcludes
def find_EXE_dependencies(config): global target_platform, target_iswin print "I: computing EXE_dependencies" python = opts.executable or sys.executable target_platform = opts.target_platform or sys.platform config['python'] = python config['target_platform'] = target_platform target_iswin = target_platform[:3] == 'win' if not iswin: while os.path.islink(python): python = os.path.join( os.path.split(python)[0], os.readlink(python)) xtrapath = [] if target_iswin and not iswin: # try to find a mounted Windows system xtrapath = glob.glob('/mnt/*/WINDOWS/system32/') if not xtrapath: print "E: Can not find a mounted Windows system" print "W: Please set 'xtrpath' in the config file yourself" xtrapath = config.get('xtrapath') or xtrapath config['xtrapath'] = xtrapath toc = bindepend.Dependencies([('', python, '')], target_platform, xtrapath) if iswin and sys.version[:3] == '1.5': import exceptions toc.append((os.path.basename(exceptions.__file__), exceptions.__file__, 'BINARY')) config['EXE_dependencies'] = toc[1:]
def dependencies(self): """Return a list of binary dependencies.""" if self._depends is not None: return self._depends self._depends = [] for (lib, path) in bindepend.Dependencies([(self.name, self.path)]): self._depends.append(binaryresource(lib, path)) return self._depends
import mf, bindepend # EXE_dependencies print "I: computing EXE_dependencies" python = sys.executable if not iswin: while os.path.islink(python): python = os.readlink(python) if not os.path.isabs(python): for dir in string.split(os.environ['PATH'], os.pathsep): test = os.path.join(dir, python) if os.path.exists(test): python = test break toc = bindepend.Dependencies([('', python, '')]) if iswin and sys.version[:3] == '1.5': import exceptions toc.append((os.path.basename(exceptions.__file__), exceptions.__file__, 'BINARY')) config['EXE_dependencies'] = toc[1:] _useTK = """\ # Generated by Configure.py # This file is public domain import os, sys try: basedir = os.environ['_MEIPASS2'] except KeyError: basedir = sys.path[0] tcldir = os.path.join(basedir, '_MEI', 'tcl%s') tkdir = os.path.join(basedir, '_MEI', 'tk%s')
def assemble(self): print "running Analysis", os.path.basename(self.out) # Reset seen variable to correctly discover dependencies # if there are multiple Analysis in a single specfile. bindepend.seen = {} paths = self.pathex for i in range(len(paths)): # FIXME: isn't self.pathex already norm-abs-pathed? paths[i] = absnormpath(paths[i]) ################################################### # Scan inputs and prepare: dirs = {} # input directories pynms = [] # python filenames with no extension for script in self.inputs: if not os.path.exists(script): print "Analysis: script %s not found!" % script sys.exit(1) d, base = os.path.split(script) if not d: d = os.getcwd() d = absnormpath(d) pynm, ext = os.path.splitext(base) dirs[d] = 1 pynms.append(pynm) ################################################### # Initialize analyzer and analyze scripts analyzer = mf.ImportTracker(dirs.keys() + paths, self.hookspath, self.excludes, target_platform=target_platform) #print analyzer.path scripts = [] # will contain scripts to bundle for i in range(len(self.inputs)): script = self.inputs[i] print "Analyzing:", script analyzer.analyze_script(script) scripts.append((pynms[i], script, 'PYSOURCE')) ################################################### # Fills pure, binaries and rthookcs lists to TOC pure = [] # pure python modules binaries = [] # binaries to bundle zipfiles = [] # zipfiles to bundle datas = [] # datafiles to bundle rthooks = [] # rthooks if needed for modnm, mod in analyzer.modules.items(): # FIXME: why can we have a mod == None here? if mod is not None: hooks = findRTHook(modnm) #XXX if hooks: rthooks.extend(hooks) datas.extend(mod.datas) if isinstance(mod, mf.BuiltinModule): pass else: fnm = mod.__file__ if isinstance(mod, mf.ExtensionModule): binaries.append((mod.__name__, fnm, 'EXTENSION')) elif isinstance(mod, (mf.PkgInZipModule, mf.PyInZipModule)): zipfiles.append( ("eggs/" + os.path.basename(str(mod.owner)), str(mod.owner), 'ZIPFILE')) else: # mf.PyModule instances expose a list of binary # dependencies, most probably shared libraries accessed # via ctypes. Add them to the overall required binaries. binaries.extend(mod.binaries) if modnm != '__main__': pure.append((modnm, fnm, 'PYMODULE')) binaries.extend( bindepend.Dependencies(binaries, platform=target_platform)) self.fixMissingPythonLib(binaries) if zipfiles: scripts[-1:-1] = [("_pyi_egg_install.py", os.path.join(HOMEPATH, "support/_pyi_egg_install.py"), 'PYSOURCE')] # Add realtime hooks just before the last script (which is # the entrypoint of the application). scripts[-1:-1] = rthooks self.scripts = TOC(scripts) self.pure = TOC(pure) self.binaries = TOC(binaries) self.zipfiles = TOC(zipfiles) self.datas = TOC(datas) try: # read .toc oldstuff = _load_data(self.out) except: oldstuff = None self.pure = TOC(compile_pycos(self.pure)) newstuff = (self.inputs, self.pathex, self.hookspath, self.excludes, self.scripts, self.pure, self.binaries, self.zipfiles, self.datas) if oldstuff != newstuff: _save_data(self.out, newstuff) wf = open(WARNFILE, 'w') for ln in analyzer.getwarnings(): wf.write(ln + '\n') wf.close() print "Warnings written to %s" % WARNFILE return 1 print self.out, "no change!" return 0
def assemble(self): print "running Analysis", os.path.basename(self.out) paths = self.pathex for i in range(len(paths)): paths[i] = os.path.abspath(os.path.normpath(paths[i])) dirs = {} pynms = [] for script in self.inputs: if not os.path.exists(script): print "Analysis: script %s not found!" % script sys.exit(1) d, base = os.path.split(script) if not d: d = os.getcwd() d = os.path.abspath(os.path.normpath(d)) pynm, ext = os.path.splitext(base) dirs[d] = 1 pynms.append(pynm) analyzer = mf.ImportTracker(dirs.keys()+paths, self.hookspath, self.excludes) #print analyzer.path scripts = [] for i in range(len(self.inputs)): script = self.inputs[i] print "Analyzing:", script analyzer.analyze_script(script) scripts.append((pynms[i], script, 'PYSOURCE')) pure = [] binaries = [] rthooks = [] for modnm, mod in analyzer.modules.items(): if mod is not None: hooks = findRTHook(modnm) #XXX if hooks: rthooks.extend(hooks) if isinstance(mod, mf.BuiltinModule): pass else: fnm = mod.__file__ if isinstance(mod, mf.ExtensionModule): binaries.append((mod.__name__, fnm, 'EXTENSION')) elif modnm == '__main__': pass else: pure.append((modnm, fnm, 'PYMODULE')) binaries.extend(bindepend.Dependencies(binaries)) scripts[1:1] = rthooks self.scripts = TOC(scripts) self.pure = TOC(pure) self.binaries = TOC(binaries) try: oldstuff = eval(open(self.out, 'r').read()) except: oldstuff = None if oldstuff != (self.inputs, self.pathex, self.hookspath, self.excludes, scripts, pure, binaries): outf = open(self.out, 'w') pprint.pprint( (self.inputs, self.pathex, self.hookspath, self.excludes, self.scripts, self.pure, self.binaries), outf) outf.close() wf = open(WARNFILE, 'w') for ln in analyzer.getwarnings(): wf.write(ln+'\n') wf.close() print "Warnings written to %s" % WARNFILE return 1 print self.out, "no change!" return 0