0001 import glob, zipfile, os 0002 import sys, re, time 0003 0004 excludePy = ["makePyXR.py", "bumpRelease.py", "latexCrawler.py"] 0005 0006 def printHeader(header): 0007 delimiter = "=" * len(header) 0008 print 0009 print delimiter 0010 print header 0011 print delimiter 0012 print 0013 0014 def getPythonFiles(): 0015 return [x for x in glob.glob("*.py") if x not in excludePy] + [x for x in glob.glob(os.path.join("tests","*.py"))] 0016 0017 def getSettingFiles(): 0018 return ["settings.RedHat", "settings.OpenBSD", "settings.Win32"] 0019 0020 printHeader("Removing windows linefeeds") 0021 0022 for fil in getPythonFiles(): 0023 if os.path.isdir(fil): 0024 print file, "Directory!" 0025 continue 0026 if fil == 'tests\\mixedNewlines.py': 0027 print "Skipping mixedNewlines.py. It's supposed to be invalid" 0028 continue 0029 data = open(fil, "rb").read() 0030 if '\0' in data: 0031 print fil, "Binary!" 0032 continue 0033 newdata = re.sub("\r\n", "\n", data) 0034 if newdata != data: 0035 print fil 0036 f = open(fil, "wb") 0037 f.write(newdata) 0038 f.close() 0039 0040 printHeader("Getting version and date") 0041 from misc import version, minorMinorVersion, minorMinorDate 0042 0043 versionfile = "releases.py" 0044 versionDate = time.strftime("%d %b %Y %H:%M:%S +0000", time.gmtime()) 0045 minorMinorVersion = 0 0046 release = "%s.%s" % (version, minorMinorVersion) 0047 0048 if not os.path.exists(versionfile): 0049 f = file(versionfile, "wb") 0050 f.write("# PyXR.zip Release %s\n\n" % release) 0051 f.write("version = %s\n" % repr(version)) 0052 f.write("minorMinorVersion = 0\n") 0053 0054 f.write ("minorMinorDate = %s\n\n" % repr(versionDate)) 0055 f.close() 0056 else: 0057 execfile(versionfile) 0058 minorMinorVersion += 1 0059 release = "%s.%s" % (version, minorMinorVersion) 0060 f = file(versionfile, "ab") 0061 f.write("# PyXR.zip Release %s\n\n" % release) 0062 f.write("version = %s\n" % repr(version)) 0063 f.write("minorMinorVersion = %s\n" % (minorMinorVersion)) 0064 f.write ("minorMinorDate = %s\n\n" % repr(versionDate)) 0065 f.close() 0066 0067 0068 printHeader("Creating zip") 0069 0070 longFilename = "PyXR-%s.%s.zip" % (version, minorMinorVersion) 0071 0072 zp = zipfile.ZipFile(longFilename, "w") 0073 0074 printHeader("Making documentation") 0075 0076 readme = file("readme.html", "r").read() 0077 currentUpdates = file("currentUpdates.html").read() 0078 updates = file("updates.html").read() 0079 0080 currentUpdates = re.sub(r"\:\:VERSION\:\:", release, currentUpdates) 0081 currentUpdates = re.sub(r"\:\:DATE\:\:", versionDate, currentUpdates) 0082 0083 updates = re.sub(r"\:\:UPDATE\:\:", currentUpdates, updates) 0084 up = file("tmpUpdates.html", "w") 0085 up.write(updates) 0086 up.close() 0087 zp.write("tmpUpdates.html", "PyXR\\updates.html") 0088 0089 readme = re.sub(r"\:\:VERSION\:\:", release, readme) 0090 readme = re.sub(r"\:\:DATE\:\:", versionDate, readme) 0091 readme = re.sub(r"\:\:UPDATE\:\:", currentUpdates, readme) 0092 0093 #make readme index 0094 pyxr = file("pyxr.html", "w") 0095 pyxr.write(readme) 0096 pyxr.close() 0097 #add to archive 0098 zp.write("pyxr.html", "PyXR\\readme.html") 0099 zp.write("settings.html", "PyXR\\settings.html") 0100 0101 0102 0103 printHeader("Adding py files to zip") 0104 0105 for x in getPythonFiles(): 0106 print x 0107 zp.write(x, "PyXR\\%s" % x) 0108 0109 printHeader("Adding setting.cfg files to zip") 0110 0111 for x in getSettingFiles(): 0112 print x 0113 zp.write(x, "PyXR\\%s" % x) 0114 0115 printHeader("Adding License File") 0116 0117 zp.write("license.txt", "PyXR\\license.txt") 0118 0119 print "Finalizing zip file" 0120 0121 zp.close() 0122 0123 print "Copying '%s' to 'pyxr.zip'" % longFilename 0124 0125 import shutil 0126 shutil.copy(longFilename, "PyXR.zip") 0127 0128
Generated by PyXR 0.9.4