def listPlugins(self, list_disabled=False): plugins = [] for dir_name in sorted(os.listdir(self.path_plugins)): dir_path = os.path.join(self.path_plugins, dir_name) plugin_name = dir_name.replace("disabled-", "") if dir_name.startswith("disabled"): is_enabled = False else: is_enabled = True plugin_config = self.config["builtin"].get(plugin_name, {}) if "enabled" in plugin_config: is_enabled = plugin_config["enabled"] if dir_name == "__pycache__" or not os.path.isdir(dir_path): continue # skip if dir_name.startswith("Debug") and not config.debug: continue # Only load in debug mode if module name starts with Debug if not is_enabled and not list_disabled: continue # Dont load if disabled plugin = {} plugin["source"] = "builtin" plugin["name"] = plugin_name plugin["dir_name"] = dir_name plugin["dir_path"] = dir_path plugin["inner_path"] = plugin_name plugin["enabled"] = is_enabled plugin["rev"] = config.rev plugin["loaded"] = plugin_name in self.plugin_names plugins.append(plugin) plugins += self.listInstalledPlugins(list_disabled) return plugins
def listInstalledPlugins(self, list_disabled=False): plugins = [] for address, site_plugins in sorted(self.config.items()): if address == "builtin": continue for plugin_inner_path, plugin_config in sorted( site_plugins.items()): is_enabled = plugin_config.get("enabled", False) if not is_enabled and not list_disabled: continue plugin_name = os.path.basename(plugin_inner_path) dir_path = "%s/%s/%s" % (self.path_installed_plugins, address, plugin_inner_path) plugin = {} plugin["source"] = address plugin["name"] = plugin_name plugin["dir_name"] = plugin_name plugin["dir_path"] = dir_path plugin["inner_path"] = plugin_inner_path plugin["enabled"] = is_enabled plugin["rev"] = plugin_config.get("rev", 0) plugin["loaded"] = plugin_name in self.plugin_names plugins.append(plugin) return plugins
def make_plugin_list(self): plugins = [] for name, plugin in self.plugins.items(): if not plugin.enabled or plugin.backend: continue plugins.append(Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) return plugins
def detectPlugins(self): """ Search for available plugins. """ plugins = [] for plugin in os.listdir(os.path.join(os.path.dirname(__file__), "plugins")): if plugin.endswith(".py") and not plugin.startswith("__init__") and not plugin.startswith("example") and plugin[:-3] != "base": plugins.append(plugin[:-3]) plugins.sort() return plugins
def make_plugin_list(self): plugins = [] for name, plugin in self.plugins.items(): if not plugin.enabled or plugin.backend: continue plugins.append( Menu(plugin.plugin_name, plugin.description, *(plugin.setup() or []))) return plugins
def detectPlugins(self): """ Search for available plugins. """ plugins = [] for plugin in os.listdir( os.path.join(os.path.dirname(__file__), "plugins")): if plugin.endswith(".py") and not plugin.startswith( "__init__") and not plugin.startswith( "example") and plugin[:-3] != "base": plugins.append(plugin[:-3]) plugins.sort() return plugins
def __load_plugins(self, subpackage, plugin_names=[]): ''' Loads Plugsy plugins :param subpackage: The subpackage to be loaded, such as 'core' or 'addons' :param plugin_names: An optional list of specific plugins to load :return: List of plugin objects ''' self.logger.debug("ENTRY") plugins = [] # Iterate packages and contained plugins for plugin in self.__import_available_plugins(subpackage): # Skip plugin load if name specified and not matching plugin, or plugin already loaded if (not plugin_names or plugin[0].lower() in plugin_names) and not self.get_plugin(plugin[0]): self.logger.debug("Attempting to load '%s' plugin" % plugin[0]) try: name, _class, plugin, configuration = self.__instantiate_plugin(plugin) self.logger.debug("'%s' loaded successfully" % name) # Try to load the plugins try: if subpackage.lower().split(".")[1] == "core": self.logger.debug("Setting plugin as core plugin") plugin.set_core_plugin() plugin.init_logging() self.logger.debug("Loading plugin config") plugin.load_configuration(configuration) except Exception as nx: raise InvalidPlugin( plugin_name=name, message=nx ) plugins.append(plugin) except InvalidPlugin as ix: # raise exception as "not a plugin or something" if subpackage.lower().split(".")[1] == "core": self.logger.critical("Could not import core plugin") raise(ix) else: self.logger.error( "Skipping plugin '%s' due to load error: %s" % ( ix.plugin_name, ix.message ) ) self.logger.debug("EXIT") return plugins
def processed(options): if not all([options.file1, options.feds1]): sys.exit("--file1 and --feds1 are required (see './oneRun.py --help').") if not options.outputFile.endswith(".root"): sys.exit("--output-file must end with .root (%s)" % options.outputFile) if options.file2 and not options.feds2: sys.exit("--file2 requires --feds2") if 0 <= options.sparseLoop: if options.file2: sys.exit("--sparse-loop does not work with --file2") if options.nEventsSkip: sys.exit("--sparse-loop does not work with --nevents-skip") matching.__ignoreCE = options.ignoreCE matching.__utcaBcnDelta = options.utcaBcnDelta matching.__utcaPipelineDelta = options.utcaPipelineDelta printer.__color = not options.noColor common = subset(options, ["dump", "firstNTs", "lastNAmcs", "nEventsMax", "nEventsSkip", "perTs", "progress", "sparseLoop"]) common.update(subset(options, ["noWarnQuality"], invert=True)) common["crateslots"] = sw.fedList(options.crateslots) plugins = options.plugins.split(",") if 1 <= options.dump and "printraw" not in plugins: plugins.append("printraw") if options.file2 and "compare" not in plugins: plugins.append("compare") common["plugins"] = [x for x in plugins if x] outer = {"fedIds": sw.fedList(options.feds1), "label": "files1", "fileNames": options.file1} outer.update(common) inner = {} if options.feds2: inner = {"fedIds": sw.fedList(options.feds2), "label": "files2", "fileNames": options.file2 if options.file2 else options.file1} inner.update(common) return {"outer": outer, "inner": inner, "outputFile": options.outputFile, "mapOptions": subset(options, ["printEventMap", "identityMap"]), "options": subset(options, ["anyEmap", "printEmap", "printMismatches", "fewerHistos"])}
def processed(options): if not all([options.file1, options.feds1]): sys.exit("--file1 and --feds1 are required (see './oneRun.py --help').") if not options.outputFile.endswith(".root"): sys.exit("--output-file must end with .root (%s)" % options.outputFile) if options.file2 and not options.feds2: sys.exit("--file2 requires --feds2") if 0 <= options.sparseLoop: if options.file2: sys.exit("--sparse-loop does not work with --file2") if options.nEventsSkip: sys.exit("--sparse-loop does not work with --nevents-skip") matching.__okErrF = sw.fedList(options.okErrF) matching.__utcaBcnDelta = options.utcaBcnDelta matching.__utcaPipelineDelta = options.utcaPipelineDelta printer.__color = not options.noColor common = subset(options, ["dump", "firstNTs", "lastNAmcs", "nEventsMax", "nEventsSkip", "progress", "sparseLoop"]) common.update(subset(options, ["noUnpack", "noWarnQuality", "noWarnUnpack"], invert=True)) common["crateslots"] = sw.fedList(options.crateslots) plugins = options.plugins.split(",") if 1 <= options.dump and "printraw" not in plugins: plugins.append("printraw") if options.file2 and "compare" not in plugins: plugins.append("compare") common["plugins"] = filter(lambda x: x, plugins) outer = {"fedIds": sw.fedList(options.feds1), "label": "files1", "fileNames": options.file1} outer.update(common) inner = {} if options.feds2: inner = {"fedIds": sw.fedList(options.feds2), "label": "files2", "fileNames": options.file2 if options.file2 else options.file1} inner.update(common) return {"outer": outer, "inner": inner, "outputFile": options.outputFile, "mapOptions": subset(options, ["printEventMap", "identityMap"]), "options": subset(options, ["anyEmap", "printEmap", "printMismatches", "fewerHistos"])}
def _gather_plugins(self): """ Scan the plugins package for installed plugins in the form of subpackages. """ import plugins objects = pkgutil.iter_modules( plugins.__path__) # (module_loader, name, ispkg) package_names = [o[1] for o in objects if o[2]] plugin_descriptions = [] for package_name in package_names: try: plugin_class = PluginController.get_plugin_class(package_name) PluginController.check_plugin(plugin_class) plugin_descriptions.append( (package_name, plugin_class.name, plugin_class)) except Exception as exception: self.log(package_name, "Could not load plugin", exception) # Check for double plugins per_name = {} for description in plugin_descriptions: if description[1] not in per_name: per_name[description[1]] = [description] else: per_name[description[1]].append(description) # Remove plugins that are defined in multiple packages plugins = [] for name in per_name: if len(per_name[name]) > 1: self.log( name, "Could not enable plugin", "found in multiple pacakges: %s" % ([t[0] for t in per_name[name]], )) else: try: plugin_class = per_name[name][0][2] plugins.append( plugin_class(self.__webinterface, self.get_logger(name))) except Exception as exception: self.log(name, "Could not initialize plugin", exception, traceback.format_exc()) return plugins
def installed_plugins(self): plugins = [] for plugin in self.get_plugins(): plugins.append(plugin["plugin"].title.replace(':','') + ' (' + plugin["filename"] + ')') return plugins
#!/usr/bin/env python #mall_urls=["https://www.smzdm.com/mall/cebbank/"] #m = MallPlugin(mall_urls) #m.start() # #search_urls=["http://search.smzdm.com/?c=home&s=%E5%85%89%E5%A4%A7&order=score&mall_id=1065"] #s = SearchPlugin(search_urls) #s.start() import utils import plugins import data from pydoc import locate plugins = [] for p in data.enabled_plugins: plugin = locate(p) plugins.append(plugin) print plugins for plugin in plugins: inst = plugin() inst.start()
def iitc(bot, event, *args): """get a screenshot of a search term or intel URL or the default intel URL of the hangout.""" arguments = {} if args: if len(args) > 1: url = ' '.join(str(i) for i in args) else: url = args[0] if '"' in url: url = url.replace('"', '') else: url = bot.conversation_memory_get(event.conv_id, 'IntelURL') if bot.config.exists(["intel_screenbot", "email"]): if bot.config.exists(["intel_screenbot", "password"]): email = bot.config.get_by_path(["intel_screenbot", "email"]) password = bot.config.get_by_path(["intel_screenbot", "password"]) arguments['email'] = email arguments['password'] = password else: html = "<i><b>{}</b> No Intel password has been added to config. Unable to authenticate".format(event.user.full_name) yield from bot.coro_send_message(event.conv, html) else: html = "<i><b>{}</b> No Intel Email/password has been added to config. Unable to authenticate".format(event.user.full_name) yield from bot.coro_send_message(event.conv, html) if url is None: html = "<i><b>{}</b> No Intel URL has been set for screenshots.".format(event.user.full_name) yield from bot.coro_send_message(event.conv, html) else: if re.match(r'(http(s)?:\/\/)', url): search = 'nix' zoomParameter = re.search(r"(?:&z=)", url, re.IGNORECASE) if zoomParameter: ZoomSearch = re.finditer(r"(?:&z=).*", url, flags=re.I) for matchNum, zoomlevel_raw in enumerate(ZoomSearch): matchNum = matchNum + 1 zoomlevel_clean = zoomlevel_raw.group() zoomlevel = zoomlevel_clean[3:][:2] if zoomlevel.isdigit(): yield from bot.coro_send_message(event.conv_id, "<i>iitc map at zoom level "+ zoomlevel + " requested, please wait...</i>") else: yield from bot.coro_send_message(event.conv_id, "<i>iitc map requested, please wait...</i>") else: search = url zoomParameter = re.search(r"(?<=z=)", url, re.IGNORECASE) if zoomParameter: ZoomSearch = re.finditer(r"(?<=z=)[^\s]+", url, flags=re.I) for matchNum, zoomlevel_raw in enumerate(ZoomSearch): matchNum = matchNum + 1 zoomlevel = zoomlevel_raw.group() search = search.replace("z={}".format(zoomlevel),"") if zoomlevel.isdigit(): yield from bot.coro_send_message(event.conv_id, "<i>searching " + search + " on iitc map and screenshooting it at zoom level "+ zoomlevel + " as requested, please wait...</i>") arguments['zoomlevel'] = str(zoomlevel) else: yield from bot.coro_send_message(event.conv_id, "<i>searching " + search + " on iitc map and and screenshooting it as requested, please wait...</i>") url = 'https://www.ingress.com/intel' filepath = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name filename = filepath.split('/', filepath.count('/'))[-1] args_filepath = tempfile.NamedTemporaryFile(prefix="args_{}".format(event.conv_id), suffix=".json", delete=False).name logger.debug("temporary screenshot file: {}".format(filepath)) logger.debug("temporary args file: {}".format(args_filepath)) if bot.conversation_memory_get(event.conv_id, 'iitc_plugins'): plugins = [] plugin_names = bot.conversation_memory_get(event.conv_id, 'iitc_plugins').split(", ") if bot.memory.exists(["iitc_plugins"]): for plugin_objects in bot.memory.get_by_path(["iitc_plugins"]): for plugin_name in plugin_names: if plugin_objects["name"] == plugin_name: plugins.append(plugin_objects["url"]) else: plugins = '' arguments['plugins'] = plugins arguments['search'] = search arguments['url'] = url arguments['filepath'] = filepath arguments['maptype'] = "iitc" arguments['screenshotfunction'] = "map" with open(args_filepath, 'w') as out: out.write(json.dumps(arguments)) try: loop = asyncio.get_event_loop() image_data = yield from _screencap(url, args_filepath, filepath, filename, bot, event, arguments) except Exception as e: yield from bot.coro_send_message(event.conv_id, "<i>error getting screenshot</i>") logger.exception("screencap failed".format(url)) return
def Save(self, frame): if not self.has_section("Main"): self.add_section("Main") self.set("Main", "WindowPos", ",".join([str(i) for i in frame.rect.GetPosition()])) self.set("Main", "WindowSize", ",".join([str(i) for i in frame.rect.GetSize()])) self.set("Main", "MaximizeState", str(frame.IsMaximized())) self.set("Main", "MinimizeToTray", str(self._app.settings["MinimizeToTray"])) if frame.session: self.set("Main", "SessionFile", frame.session) self.set("Main", "FixedTabWidth", str(self._app.settings["FixedTabWidth"])) self.setlist("RecentFiles", None, self._app.settings["RecentFiles"]) plugins = [] for i in range(len(self._app.plugins.names)): plugins.append( "%s, %s" % (self._app.plugins.names[i], self._app.plugins.enabled[i])) self.setlist("Plugins", None, plugins) if not self.has_section("Editor"): self.add_section("Editor") self.set("Editor", "BackupType", str(self._app.settings["BackupType"])) self.set("Editor", "BackupDir", self._app.settings["BackupDir"]) if not self.has_section("Panes"): self.add_section("Panes") self.set("Panes", "LeftDocked", ";".join(frame.managers[wx.LEFT].GetPanes())) self.set("Panes", "RightDocked", ";".join(frame.managers[wx.RIGHT].GetPanes())) self.set("Panes", "TopDocked", ";".join(frame.managers[wx.TOP].GetPanes())) self.set("Panes", "BottomDocked", ";".join(frame.managers[wx.BOTTOM].GetPanes())) self.set("Panes", "LeftActive", str(frame.managers[wx.LEFT].GetCurrent())) self.set("Panes", "RightActive", str(frame.managers[wx.RIGHT].GetCurrent())) self.set("Panes", "TopActive", str(frame.managers[wx.TOP].GetCurrent())) self.set("Panes", "BottomActive", str(frame.managers[wx.BOTTOM].GetCurrent())) if not self.has_section("Search"): self.add_section("Search") self.set("Search", "QuickFind", frame.searchbar.find.GetValue()) for item in ("Find", "Replace", "Filter"): self.set("Search", "Last%s" % item, self._app.settings["Last%s" % item]) self.set("Search", "FilterExclude", str(self._app.settings["FilterExclude"])) self.setlist("Search", "FindHistory", self._app.settings["FindHistory"]) self.setlist("Search", "ReplaceHistory", self._app.settings["ReplaceHistory"]) self.setlist("Search", "FilterHistory", self._app.settings["FilterHistory"]) if not self.has_section("Browser"): self.add_section("Browser") self.set("Browser", "ShowHidden", str(self._app.settings["ShowHidden"])) self.set("Browser", "UpdatePath", str(self._app.settings["UpdatePath"])) self.set("Browser", "FilterIndex", str(frame.filebrowser.dirctrl.GetFilterIndex())) self.setlist("Browser", "FavoriteList", frame.filebrowser.favorites) paths = [] frame.filebrowser.dirctrl.GetPaths(paths) self.setlist("Browser", "SelectedPaths", paths) config = open(self.filename, 'w') self.write(config) config.close()