Esempio n. 1
0
 def import_mod(mod_name):
     try:
         macro_tree[mod_name] = {}
         modules[mod_name] = importlib.import_module(SOURCEDIR+"."+mod_name)
         print("Module '%s' updated"%mod_name)
     except Exception as e:
         print("Failed to update '%s' module: %s: %s"%(mod_name, type(e).__name__, e))
         del macro_tree[mod_name]
Esempio n. 2
0
 def reloader():
     while True:
         with loader_lock:
             if len(watch): #if update needed
                 for i in watch:
                     if watch[i] == "add":
                         if i in modules: unload(i)
                         import_mod(i)
                     elif watch[i] == "del":
                         unload(i)
                         print("Module '%s' unloaded"%i)
                 invoker.wait(app().form.updateMacroTree)
                 watch.clear()
         time.sleep(1)
Esempio n. 3
0
 def handle_wrap(self, msg, args):
     if msg in ("Call", "Doc"):
         path = args["Macro"].rsplit(".", 1)
         if len(path)==1: path.insert(0, DEF_MODULE)
         if path[0] in macro_tree and path[1] in macro_tree[path[0]]:
             macro = getattr(modules[path[0]], path[1], None)
         else: macro = None
         if not macro: return "SERVER_NO_MACRO"
         elif msg == "Doc":
             print("Help on '%s' requested"%args["Macro"])
             return macro.__doc__ or ""
         else: #Caller must 'Test' if server is 'OK' before this
             print("Macro '%s' called "%path[1])
             invoker.invoke(app().form.startMacro, macro, args["Workbook"])
             return "OK"
     elif msg == "Request":
         print("Macro list requested")
         return "|".join(getMacroList(args["Application"]))
     elif msg == "Test":
         print("Connection checked")
         with run_lock:
             return "Busy" if not run_lock._value else "OK"
     elif msg == "Interrupt":
         print("Request to interrupt macro")
         with run_lock: #FIXME: It's possible to make several requests before macro is interrupted. Is it ok?
             if not run_lock._value:
                 _thread.interrupt_main()
             else: return "Not busy"
         return "OK"
     else:
         print("Unknown message")
         return "Unknown"