autoreloader.py
Go to the documentation of this file.
1 #!/neo/opt/bin/python
2 
3 
4 import ihooks, os, sys
5 from pyclearsilver.log import *
6 
7 #ihooks.install(AutoReload())
8 
9 class AutoReload(ihooks.ModuleImporter):
10  def __init__(self):
11  ihooks.ModuleImporter.__init__(self)
12  self.datestamps = {}
13 
14  def import_module(self,name,globals={},locals={},fromlist={}):
15 # warn("import_module", name)
16  testpath = name + ".py"
17 
18  # stat the file if we have it
19  if os.path.isfile(testpath):
20  stinfo = os.stat(testpath)
21  else:
22  stinfo = None
23 
24  if sys.modules.has_key(name):
25 # warn("reimporting", testpath)
26  # already imported
27  m = ihooks.ModuleImporter.import_module(self,name,globals,locals,fromlist)
28  try:
29  testpath = m.__file__
30  if os.path.isfile(testpath):
31  stinfo = os.stat(testpath)
32  except AttributeError: pass
33 
34  if stinfo:
35 
36  stored_time = self.datestamps.get(testpath,0)
37  if stored_time < stinfo.st_mtime:
38 
39  self.datestamps[testpath] = stinfo.st_mtime
40  if stored_time:
41  warn("---------------------", name, "changed reloading", stored_time, stinfo.st_mtime, os.getcwd())
42 
43  reload(sys.modules[name])
44  else :
45 # warn("loading for the first time", testpath)
46  if stinfo:
47  self.datestamps[testpath] = stinfo.st_mtime
48  m = ihooks.ModuleImporter.import_module(self,name,globals,locals,fromlist)
49  try:
50  testpath = m.__file__
51  stinfo = os.stat(testpath)
52  if os.path.isfile(testpath):
53  self.datestamps[testpath] = stinfo.st_mtime
54  except AttributeError:
55  pass
56 
57  return m
58 
59 
60 warn("**********************8 installing autoreload")
61 ihooks.install(AutoReload())
def warn(args)
Definition: log.py:100
def import_module(self, name, globals={}, locals={}, fromlist={})
Definition: autoreloader.py:14


pyclearsilver
Author(s): Scott Noob Hassan
autogenerated on Mon Jun 10 2019 15:51:13