def reload_code(): # Do not reload anything in these directories or their subdirectories. dir_reload_blacklist = set(["core"]) macro_dir = "C:\\NatLink\\NatLink\\MacroSystem" # Unload all grammars. natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. for name, module in sys.modules.items(): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.startswith(macro_dir) and not bool(set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): print "removing %s from cache" % name # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name] # Reload the top-level modules in macro_dir. natlinkmain.findAndLoadFiles() print "finished reloading"
def reload_code(): # Do not reload anything in these directories or their subdirectories. dir_reload_blacklist = set(["core"]) macro_dir = "C:\\NatLink\\NatLink\\MacroSystem" source_dir = r"\\VBOXSVR\aenea\dragonfly_grammars" # Unload all grammars if natlinkmain is available. if natlinkmain: natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. # Consider them in sorted order to try to make things as predictable as possible to ease debugging. for name, module in sorted(sys.modules.items()): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.startswith(macro_dir) and not bool( set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): print "removing %s from cache" % name # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name] # Copy in the new source files from the remote directory # for d, dirs, files in os.walk(source_dir): for f in files: full_file_name = os.path.join(d, f) if os.path.isfile(full_file_name): shutil.copy(full_file_name, macro_dir) print "copied %s" % full_file_name try: # Reload the top-level modules in macro_dir if natlinkmain is available. if natlinkmain: natlinkmain.findAndLoadFiles() except Exception as e: print "reloading failed: {}".format(e) else: print "finished reloading"
def reload_code(): # Do not reload anything in these directories or their subdirectories. dir_reload_blacklist = set(["core"]) macro_dir = aenea.config.STARTING_PROJECT_ROOT print macro_dir # Unload all grammars. natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. # Consider them in sorted order to try to make things as predictable as possible to ease debugging. for name, module in sorted(sys.modules.items()): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.lower().startswith( macro_dir.lower() or name.startwith('aenea') or name.startwith('dragonfly')) and not bool( set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): print "removing %s from cache" % name # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name] try: # Reload the top-level modules in macro_dir. natlinkmain.findAndLoadFiles() except Exception as e: print "reloading failed: {}".format(e) else: print "finished reloading"
def unload_code(optional_blacklist = []): print "Unloading all aenea code" # Do not reload anything in these directories or their subdirectories. #blacklist_list = list("core") + optional_blacklist dir_reload_blacklist = set(["core"]) if len(optional_blacklist): dir_reload_blacklist.add(optional_blacklist) print "Blacklist: ", dir_reload_blacklist macro_dir = "C:\\NatLink\\NatLink\\MacroSystem" # Unload all grammars if natlinkmain is available. if natlinkmain and not len(optional_blacklist): natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. # Consider them in sorted order to try to make things as predictable as possible to ease debugging. for name, module in sorted(sys.modules.items()): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.startswith(macro_dir) and not bool(set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): print "removing %s from cache (in module %s)" % (name, module) # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name]
def unloadCode(): import natlinkmain, sys, os # Do not reload anything in these directories or their subdirectories. dir_reload_blacklist = set(["core"]) # TODO: should only care about path ending in Natlink/Natlink/MacroSystem macro_dir = "E:\\NatLink\\NatLink\\MacroSystem" # Unload all grammars. natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. for name, module in sys.modules.items(): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.startswith(macro_dir) and not bool(set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): # if hasattr(sys.modules[name], "unload") and callable(sys.modules[name].unload): # sys.modules[name].unload() # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name]
def unloadCode(): import natlinkmain, sys, os # Do not reload anything in these directories or their subdirectories. dir_reload_blacklist = set(["core"]) # TODO: should only care about path ending in Natlink/Natlink/MacroSystem macro_dir = "E:\\NatLink\\NatLink\\MacroSystem" # Unload all grammars. natlinkmain.unloadEverything() # Unload all modules in macro_dir except for those in directories on the # blacklist. for name, module in sys.modules.items(): if module and hasattr(module, "__file__"): # Some builtin modules only have a name so module is None or # do not have a __file__ attribute. We skip these. path = module.__file__ # Convert .pyc paths to .py paths. path = topy(path) # Do not unimport this module! This will cause major problems! if (path.startswith(macro_dir) and not bool(set(path.split(os.path.sep)) & dir_reload_blacklist) and path != topy(os.path.abspath(__file__))): # if hasattr(sys.modules[name], "unload") and callable(sys.modules[name].unload): # sys.modules[name].unload() # Remove the module from the cache so that it will be reloaded # the next time # that it is imported. The paths for packages # end with __init__.pyc so this # takes care of them as well. del sys.modules[name]