$search
00001 #!/neo/opt/bin/python 00002 00003 00004 import ihooks, os, sys 00005 from pyclearsilver.log import * 00006 00007 #ihooks.install(AutoReload()) 00008 00009 class AutoReload(ihooks.ModuleImporter): 00010 def __init__(self): 00011 ihooks.ModuleImporter.__init__(self) 00012 self.datestamps = {} 00013 00014 def import_module(self,name,globals={},locals={},fromlist={}): 00015 # warn("import_module", name) 00016 testpath = name + ".py" 00017 00018 # stat the file if we have it 00019 if os.path.isfile(testpath): 00020 stinfo = os.stat(testpath) 00021 else: 00022 stinfo = None 00023 00024 if sys.modules.has_key(name): 00025 # warn("reimporting", testpath) 00026 # already imported 00027 m = ihooks.ModuleImporter.import_module(self,name,globals,locals,fromlist) 00028 try: 00029 testpath = m.__file__ 00030 if os.path.isfile(testpath): 00031 stinfo = os.stat(testpath) 00032 except AttributeError: pass 00033 00034 if stinfo: 00035 00036 stored_time = self.datestamps.get(testpath,0) 00037 if stored_time < stinfo.st_mtime: 00038 00039 self.datestamps[testpath] = stinfo.st_mtime 00040 if stored_time: 00041 warn("---------------------", name, "changed reloading", stored_time, stinfo.st_mtime, os.getcwd()) 00042 00043 reload(sys.modules[name]) 00044 else : 00045 # warn("loading for the first time", testpath) 00046 if stinfo: 00047 self.datestamps[testpath] = stinfo.st_mtime 00048 m = ihooks.ModuleImporter.import_module(self,name,globals,locals,fromlist) 00049 try: 00050 testpath = m.__file__ 00051 stinfo = os.stat(testpath) 00052 if os.path.isfile(testpath): 00053 self.datestamps[testpath] = stinfo.st_mtime 00054 except AttributeError: 00055 pass 00056 00057 return m 00058 00059 00060 warn("**********************8 installing autoreload") 00061 ihooks.install(AutoReload())