# build a zip file with all top-level library files # and the directly reachable packages. import zipfile import os libdir = os.path.normpath('python/2.7/win32/Lib') outzip = os.path.normpath('build/pylib27.zip') # temp for now zf = zipfile.PyZipFile(outzip, 'w', zipfile.ZIP_DEFLATED) zf.debug = True # write the toplevel dir zf.writepy(libdir) # write all directories that are packages # Note: this only works with my patched version that allows to exclude # the test directories. # The file 'test\badsyntax_future3.py' does not compile! def ignore_tests(pathname): print pathname path, name = os.path.split(pathname) return name.lower() not in ('test', 'tests') for pkg in os.listdir(libdir): pkgdir = os.path.join(libdir, pkg) if os.path.isdir(pkgdir): try: zf.writepy(pkgdir, filterfunc=ignore_tests) except TypeError, e: print "\n*** this python version is wrong, need the extended version with filterfunc ***\n" raise zf.printdir()