00001 import sys 00002 import imp 00003 import os 00004 00005 __copyright__ = """\ 00006 (c). Copyright 1990-2008, Vyper Logix Corp., All Rights Reserved. 00007 00008 Published under Creative Commons License 00009 (http://creativecommons.org/licenses/by-nc/3.0/) 00010 restricted to non-commercial educational use only., 00011 00012 See also: http://www.VyperLogix.com and http://www.pypi.info for details. 00013 00014 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO 00015 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 00016 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00017 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00018 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00019 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00020 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! 00021 00022 USE AT YOUR OWN RISK. 00023 """ 00024 00025 class ImpWrapper: 00026 ## 00027 # callback(path,fullname) 00028 def __init__(self, path=None, callback=None): 00029 if path is not None and not os.path.isdir(path): 00030 raise ImportError 00031 self.path = path 00032 self.__callback__ = callback 00033 00034 def find_module(self, fullname, path=None): 00035 callback_failed = (path is None) 00036 if (not callback_failed): 00037 if (callable(self.__callback__)): 00038 try: 00039 self.__callback__(path,fullname) 00040 except Exception, details: 00041 print 'ERROR: %s' % (str(details)) 00042 callback_failed = True 00043 else: 00044 callback_failed = True 00045 if (callback_failed): 00046 print '"%s" --> "%s".' % (path,fullname) 00047 subname = fullname.split(".")[-1] 00048 if subname != fullname and self.path is None: 00049 return None 00050 if self.path is None: 00051 path = None 00052 else: 00053 path = [self.path] 00054 try: 00055 file, filename, stuff = imp.find_module(subname, path) 00056 except ImportError: 00057 return None 00058 return ImpLoader(file, filename, stuff) 00059 00060 class ImpLoader: 00061 def __init__(self, file, filename, stuff): 00062 self.file = file 00063 self.filename = filename 00064 self.stuff = stuff 00065 00066 def load_module(self, fullname): 00067 mod = imp.load_module(fullname, self.file, self.filename, self.stuff) 00068 if self.file: 00069 self.file.close() 00070 mod.__loader__ = self # for introspection 00071 return mod 00072 00073 def hook(callback=None): 00074 i = ImpWrapper(callback=callback) 00075 sys.meta_path.append(i) 00076 sys.path_hooks.append(ImpWrapper) 00077 00078 def reporterHook(fname=None,isVerbose=False): 00079 import os, sys 00080 00081 if (fname is None): 00082 fname = os.sep.join([os.path.dirname(sys.argv[0]),os.path.basename('%s.txt' % (sys.argv[0].split('.')[0]))]) 00083 if (os.path.exists(fname)): 00084 os.remove(fname) 00085 00086 def myCallback(path,fullname): 00087 _msg = '(%s) :: "%s" --> "%s".' % (os.path.basename(sys.argv[0]),path,fullname) 00088 fOut = open(fname,'a') 00089 try: 00090 print >>fOut, _msg 00091 finally: 00092 fOut.flush() 00093 fOut.close() 00094 if (isVerbose): 00095 print _msg 00096 hook(callback=myCallback) 00097 00098 if (__name__ == '__main__'): 00099 import sys 00100 print >>sys.stdout, __copyright__ 00101 print >>sys.stderr, __copyright__ 00102 00103 #def myCallback(path,fullname): 00104 #print '(%s) :: "%s" --> "%s".' % (os.path.basename(sys.argv[0]),path,fullname) 00105 #hook(callback=myCallback) 00106 00107 #mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc") 00108 #for mname in mnames: 00109 #parent = mname.split(".")[0] 00110 #for n in sys.modules.keys(): 00111 #if n.startswith(parent): 00112 #del sys.modules[n] 00113 #for mname in mnames: 00114 #m = __import__(mname, globals(), locals(), ["__dummy__"]) 00115 #m.__loader__ # to make sure we actually handled the import 00116 00117
© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."
Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.
122,241 lines of code and growing...