0001 # 0002 # Generate scripts needed for serious testing! 0003 # 0004 import win32com, win32com.client.makepy 0005 import win32com.test 0006 import pythoncom 0007 import sys, os 0008 0009 genList = [ 0010 ("msword8", "{00020905-0000-0000-C000-000000000046}",1033,8,0), 0011 ] 0012 0013 genDir = "Generated4Test" 0014 def GetGenPath(): 0015 import win32api 0016 return os.path.join(win32api.GetFullPathName(win32com.test.__path__[0]), genDir) 0017 0018 def GenerateFromRegistered(fname, *loadArgs): 0019 # tlb = apply(pythoncom.LoadRegTypeLib, loadArgs) 0020 genPath = GetGenPath() 0021 try: 0022 os.stat(genPath) 0023 except os.error: 0024 os.mkdir(genPath) 0025 # Ensure an __init__ exists. 0026 open(os.path.join(genPath, "__init__.py"), "w").close() 0027 print fname, ": generating -", 0028 f = open(os.path.join(genPath, fname + ".py"), "w") 0029 win32com.client.makepy.GenerateFromTypeLibSpec(loadArgs, f, bQuiet = 1, bGUIProgress = 1, bUnicodeToString=NeedUnicodeConversions) 0030 f.close() 0031 print "compiling -", 0032 fullModName = "win32com.test.%s.%s" % (genDir, fname) 0033 exec "import " + fullModName 0034 # Inject the generated module as a top level module. 0035 sys.modules[fname] = sys.modules[fullModName] 0036 print "done" 0037 0038 0039 def GenerateAll(): 0040 for args in genList: 0041 try: 0042 apply(GenerateFromRegistered, args) 0043 except KeyboardInterrupt: 0044 print "** Interrupted ***" 0045 break 0046 except pythoncom.com_error: 0047 print "** Could not generate test code for ", args[0] 0048 0049 def CleanAll(): 0050 print "Cleaning generated test scripts..." 0051 try: # Clear exceptions! 0052 1/0 0053 except: 0054 pass 0055 genPath = GetGenPath() 0056 for args in genList: 0057 try: 0058 name = args[0]+".py" 0059 os.unlink(os.path.join(genPath, name)) 0060 except os.error, details: 0061 if type(details)==type(()) and details[0]!=2: 0062 print "Could not deleted generated", name, details 0063 try: 0064 name = args[0]+".pyc" 0065 os.unlink(os.path.join(genPath, name)) 0066 except os.error, details: 0067 if type(details)==type(()) and details[0]!=2: 0068 print "Could not deleted generated", name, details 0069 try: 0070 os.unlink(os.path.join(genPath, "__init__.py")) 0071 except: 0072 pass 0073 try: 0074 os.unlink(os.path.join(genPath, "__init__.pyc")) 0075 except: 0076 pass 0077 try: 0078 os.rmdir(genPath) 0079 except os.error, details: 0080 print "Could not delete test directory -", details 0081 0082 if __name__=='__main__': 0083 GenerateAll() 0084 CleanAll() 0085
Generated by PyXR 0.9.4