# # This file is part of Documancer (http://documancer.sf.net) # # Copyright (C) 2004 Kevin Ollivier # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: make_py_dist.py,v 1.5 2005/02/06 10:25:41 vaclavslavik Exp $ # # This script creates the mini python distribution that is shipped # with Documancer on Windows. import sys, os, string, shutil, glob, modulefinder def makedir(path): pathparts = string.split(path, os.sep) fullpath = "" for part in pathparts: fullpath = fullpath + part + os.sep if not os.path.exists(fullpath): os.mkdir(fullpath) deps = [] sys.path.append(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "src")) modfinder = modulefinder.ModuleFinder(excludes=["Tkinter", "_xmlplus"]) modfinder.add_module("site") #make sure we get unique dependencies from providers, too. srcdir = os.path.join("..", "src") scripts = [os.path.join(srcdir, "documancer.py")] for item in os.listdir(os.path.join(srcdir, "providers")): fullpath = os.path.join(srcdir, "providers", item) if os.path.isdir(fullpath): scripts = scripts + glob.glob(os.path.join(fullpath, "*.py")) mpdir = "minipython" if os.path.exists(mpdir): shutil.rmtree(mpdir) os.mkdir(mpdir) os.mkdir(os.path.join(mpdir, "lib")) spdir = os.path.join(mpdir, "lib", "site-packages") os.mkdir(spdir) os.mkdir(os.path.join(mpdir, "lib", "encodings")) if os.name == "nt": deps.append(os.path.join(sys.prefix, "python.exe")) deps.append(os.path.join(sys.prefix, "w9xpopen.exe")) import win32api #if the below file exists, then the dependency checking will copy it over #if not, we need to check the Windows system dir for it if not os.path.exists(os.path.join(sys.prefix, "python23.dll")): sysdir = win32api.GetSystemDirectory() syspython = os.path.join(sysdir, "python23.dll") if os.path.exists(syspython): shutil.copyfile(syspython, os.path.join(mpdir, "python23.dll")) #See win32com.__init__.py's SetupEnvironment() for why this particular #hack is needed. import win32com for p in win32com.__path__[1:]: modulefinder.AddPackagePath("win32com", p) for extra in ["win32com.shell"]: __import__(extra) m = sys.modules[extra] for p in m.__path__[1:]: modulefinder.AddPackagePath(extra, p) #Because these get put in Win32 system folder... pywindlls = ["PyWinTypes23.dll", "PythonCOM23.dll"] for dll in pywindlls: pywindll = os.path.join(sysdir, dll) if os.path.exists(pywindll): shutil.copyfile(pywindll, os.path.join(mpdir, dll)) #we need this to make sure win32 modules are on the path. myfile = open(os.path.join(mpdir, "lib", "site-packages", "win32.pth"), "w") myfile.write("win32") myfile.close() myfile = open(os.path.join(mpdir, "lib", "site-packages", "win32lib.pth"), "w") myfile.write("win32/lib") myfile.close() for script in scripts: modfinder.run_script(script) print script for item in modfinder.modules.items(): filename = item[1].__file__ if filename and string.find(filename, sys.prefix) != -1 and not filename in deps: deps.append(filename) encodingsdir = os.path.join(sys.prefix, "lib", "encodings", "*") deps = deps + glob.glob(encodingsdir) deps = deps + glob.glob(os.path.join(sys.prefix, "*.txt")) deps.append(os.path.join(sys.prefix, "lib", "site.py")) deps.append(os.path.join(sys.prefix, "lib", "locale.py")) #if we're using wxPython 2.5.3 or above, we need to include wx.pth wxpth_file = os.path.join(sys.prefix, "lib", "site-packages", "wx.pth") if os.path.exists(wxpth_file): deps.append(wxpth_file) for filename in deps: destfilename = string.replace(filename, sys.prefix, mpdir) makedir(os.path.dirname(destfilename)) shutil.copyfile(filename, destfilename) if os.path.splitext(filename)[1] in [".pyd", ".exe", ".dll"]: stream = os.popen("dumpbin.exe /DEPENDENTS " + filename) data = stream.read() stream.close() data = string.split(data, "\n") for datum in data: if string.find(datum, ".dll") != -1: thisfile = string.strip(datum) thisdir = os.path.dirname(filename) destdir = os.path.dirname(destfilename) #if the DLL is not in the extension's directory #that means it's on the path somewhere, so it should #not be copied in if os.path.exists(os.path.join(thisdir, thisfile)): shutil.copyfile(os.path.join(thisdir, thisfile), os.path.join(destdir, thisfile)) for item in sys.path: if os.path.exists(os.path.join(item, "python23.dll")): shutil.copyfile(os.path.join(item, "python23.dll"), os.path.join(mpdir, "python23.dll")) print `modfinder.any_missing_maybe()` # move some files to different places/names: shutil.move(os.path.join(mpdir, 'LICENSE.txt'), os.path.join(mpdir, 'Python-LICENSE.txt')) shutil.move(os.path.join(mpdir, 'NEWS.txt'), os.path.join(mpdir, 'Python-NEWS.txt')) shutil.move(os.path.join(mpdir, 'README.txt'), os.path.join(mpdir, 'Python-README.txt'))