Commits

uniqx committed 190878f

local an global variables now available for each file monitored by pyld

Comments (0)

Files changed (4)

 import time
 import tarfile
 
+
 #
 # main application
 #
   # update modification time
   handle['mtime'] = mtime
 
-  print handle
+  #print handle
 
   # archive
   if arch_path != '':
   if target in ('init','reload','unload','tick'):
     try:
       __name__ = '__pyld_'+target+'__'
-      exec(handle['code_object_'+target])
+      exec(handle['code_object_'+target],global_vars,handle['local_vars'])
       __name__ = '__main__'
     except KeyError:
       pass
 
 
 
+# global vars shared by all files that are observed by pyld
+global_vars = {}
+
 
 if __name__ == '__main__':
 
   observe_handles = []
 
   # scan interval for file changes
-  interval = 0.33
+  scan_interval = 0.33
 
   # path for the archive where the changesets are stored
   arch_path = '' #os.path.split(os.getcwd())[-1] + '.' + str(int(time.time())) + '.tar'
             last_opt_param = '-r'
             remaining_opt_param_count = 1
         else:
-          observe_handles.append({'path':arg,'mtime':0.0,'init':False})
+          observe_handles.append({'path':arg,'mtime':0.0,'init':False,'local_vars':{}})
 
       # parse option arguments
       else:
         remaining_opt_param_count -= 1
         if last_opt_param == '-i':
-          interval = float(arg)
+          scan_interval = float(arg)
         if last_opt_param == '-r':
           arch_path = arg
 
   ## main loop
   ##
 
-  last_tick = time.time()
+  last_tick = time.time() # tick time
+  last_scan = last_tick # scan time
   running = True
   while running:
 
-    # calculate delta time since since last tick
-    delta = time.time() - last_tick
+    # calculate delta time since last tick
+    tick_delta = time.time() - last_tick
+    scan_delta = time.time() - last_scan
 
     # check files
-    if delta >= interval:
+    if scan_delta >= scan_interval:
 
       for handle in observe_handles:
         __check_file(handle)
 
-      last_tick = time.time()
+      last_scan = time.time()
 
     # exec ticks
     for handle in observe_handles:
+
+
+if __name__ == '__pyld_init__':
+  global the_global_number
+  the_global_number = 42
+  test_1_var = 0
+  print 'initializing pyld test'
+
+if __name__ == '__pyld_unload__':
+  print 'unloading pyld test ... test_1_var:', test_1_var, 'the_global_number:', the_global_number
+
+if __name__ == '__pyld_reload__':
+  test_1_var = 0
+  print 'reloading pyld test ... test_1_var:', test_1_var, 'the_global_number:', the_global_number
+
+
+if __name__ == '__pyld_tick__':
+  test_1_var += 1
+  ## better don't print stuff here ^^
+
+
+if __name__ == '__pyld_init__':
+  test_2_var = 0
+  print 'initializing pyld test'
+
+if __name__ == '__pyld_unload__':
+  print 'unloading pyld test ... test_2_var:', test_2_var, 'the_global_number:', the_global_number
+
+if __name__ == '__pyld_reload__':
+  test_2_var = 0
+  print 'reloading pyld test ... test_2_var:', test_2_var, 'the_global_number:', the_global_number
+
+
+
+if __name__ == '__pyld_tick__':
+  test_2_var += 1
+  ## better don't print stuff here ^^

test-pyld.py

-
-
-if __name__ == '__pyld_init__':
-  print 'initializing pyld test'
-
-if __name__ == '__pyld_unload__':
-  print 'unloading pyld test'
-
-if __name__ == '__pyld_reload__':
-  print 'reloading pyld test'
-
-
-if __name__ == '__pyld_tick__':
-  pass
-  ## better don't print stuff here ^^