def _do_import(self): """Does the dirty stuff with __import__""" old_syspath = copy(sys.path) try: sys.path += [os.curdir, "plugins"] self.module = __import__(self.name, globals(), locals(), ["plugin"]) except ImportError, reason: warning('error loading "%s": %s' % (self.name, reason))
def _do_import(self): """Does the dirty stuff with __import__""" old_syspath = sys.path try: sys.path += [".", self.base_dir] self.module = __import__(self.directory, globals(), None, ["plugin"]) self.module = self.module.plugin except Exception, reason: warning('error importing "%s": %s' % (self.name, reason)) self.module = None
def start(self): """Instantiate (if necessary) and starts the plugin. @return False if something goes wrong, else True. """ self.instantiate() if not self._instance: return False try: self._instance.start() self._instance.started = True except Exception, reason: warning('error starting "%s": %s' % (self.name, reason)) return False
def scan_directory(self, dir_): """Find plugins and packages inside dir_""" dirs = files = [] for root, directories, files in os.walk(dir_): dirs = directories files = files break # sooo ugly for directory in [x for x in dirs if not x.startswith(".")]: try: mod = PackageHandler(dir_, directory) self._plugins[mod.name] = mod except Exception, reason: warning("Exception while importing %s:\n%s" % (directory, reason))
def start(self): """Instanciate (if necessary) and starts the plugin. @return False if something goes wrong, else True. """ inst = self.instanciate() if not inst: return False try: inst.category_register() inst.start() inst.extension_register() inst._started = True except Exception, reason: warning('error starting "%s": %s' % (self.name, reason)) return False
async def end_request(self): temp = dbg.tempdir.mktemp() req = DlRequest(file_path=temp.filepath) for uri in self.dumps(): uri.pop('id') req.put(**uri) async with dlopen(req) as dl: dbg.upload( size=dl.file.size, filepath=dl.file.pathname, ) dbg.set_percent(dl.percent_complete) dbg.set_timeleft(dl.remaining_time) dbg.set_speed(lambda: dl.transfer_rate()) dl.start(loop=asyncio.get_running_loop()) # FIX: Nbdler 下载器在协程下出现的问题 while not dl._future: await asyncio.sleep(0.01) dbg.add_stopper(dl.pause) async for exception in dl.aexceptions(): dbg.warning(exception.exc_info) if isinstance(exception, HandlerError): await dl.apause() break else: exception = None await dl.ajoin() if exception: # 若发生异常,抛出异常 raise exception from exception.exception # 更新文件信息 dbg.upload( filepath=dl.file.pathname, size=dl.file.size, )
import extension from debugger import warning, debug ERROR = False try: import dbus import dbus.service from dbus.mainloop.glib import DBusGMainLoop except ImportError, description: warning('failed some import on dbus: %s' % str(description)) ERROR = True if not ERROR: BUS_NAME = "com.gtk.emesene" BUS_PATH = "/com/gtk/emesene" def create_function(name,Qargs): '''hack to create a function with a certain number of arguments''' def y(): pass y_code = types.CodeType(args,\ y.func_code.co_nlocals,\ y.func_code.co_stacksize,\ y.func_code.co_flags,\ y.func_code.co_code,\ y.func_code.co_consts,\ y.func_code.co_names,\ y.func_code.co_varnames,\ y.func_code.co_filename,\