def scan_commands(self): self._commands = [] if self.mod == None: return dic = self.mod.__dict__ if '__root__' in dic: root = dic['__root__'] else: root = [] for k in dic: if k.startswith('_') or k in root: continue item = dic[k] if type(item) == types.FunctionType: bisect.insort(self._commands, method.Method(item, k, self)) elif type(item) == types.ModuleType and utils.is_commander_module(item): mod = Module(k, item, self) bisect.insort(self._commands, mod) # Insert root functions into this module for r in mod.roots(): bisect.insert(self._commands, r)
def reload(self): if not self.unload(): return if self.real_name in sys.modules: raise Exception('Module already exists...') oldpath = list(sys.path) try: sys.path.insert(0, self._dirname) self._rollback.monitor() self._rollback.cancel() self.mod = importlib.import_module(self.real_name) if not utils.is_commander_module(self.mod): raise Exception('Module is not a commander module...') if '__default__' in self.mod.__dict__: self.method = self.mod.__dict__['__default__'] else: self.method = None self._func_props = None except: sys.path = oldpath self._rollback.uninstall() if self.real_name in sys.modules: del sys.modules[self.real_name] raise sys.path = oldpath
def _import(self, name, globals={}, locals={}, fromlist=[], level=0): maybe = not name in sys.modules mod = self._original_import(name, globals, locals, fromlist, level) if maybe and utils.is_commander_module(mod): self._new_modules.append(name) return mod