def fetch_feeds(self, feeds): """ Fetch given feeds, possibly parallelizing requests """ start = time.time() load_plugins() logger.debug(u"starting fetcher") trigger_event('fetch_started') if config.fetcher.processes: from multiprocessing import Pool # Each worker has its own connection p = Pool(config.fetcher.processes, initializer=connect) p.map(feed_worker, feeds) # Exit the worker processes so their connections do not leak p.close() else: # Just sequence requests in this process for feed in feeds: feed_worker(feed) trigger_event('fetch_done', feeds) logger.info(u"%d feeds checked in %.2fs" % (len(feeds), time.time() - start))
def main(): args = parse_arguments() log.DEBUG = args.debug log.LOGFILE = args.log_file results = {} stats = get_interface_stats(args.host) plugins.load_plugins() # iterate over plugins and run get_results for each plugin # which is configured and where assigned interfaces are UP for plugin in plugins.plugins: test_interfaces = [ x.split(':')[1] for x in args.test if x.startswith(plugin.name) ] for interface in test_interfaces: if interface not in stats: debug('Interface', interface, 'is unknown on this router') continue if not stats[interface]['up']: debug('Interface', interface, 'is down - skipping') continue _interface = interface.replace('local-wan', 'wan') result = plugin.get_results(_interface, stats, args.max_delay) result['ts'] = int(time.time()) if plugin.name not in results: results[plugin.name] = {} results[plugin.name][interface] = result write_results(args.results_file, results)
def main(): time_all = time.time() """Main olm function""" logging.basicConfig(stream=sys.stdout, level=logging.INFO) logging.info("Beginning static site generation") settings_file_path = os.path.abspath( os.path.join(sys.argv[1], 'settings.py')) global CONTEXT if os.path.isfile(settings_file_path): CONTEXT = load_settings(sys.argv[1], settings_file_path) else: CONTEXT = load_settings(sys.argv[1]) load_plugins(CONTEXT) signal_sender = signal(Signals.INITIALISED) signal_sender.send((CONTEXT)) subsites = generateSite() base_folder = CONTEXT.BASE_FOLDER source_folder = CONTEXT.SOURCE_FOLDER for subsite in subsites: logging.info("Found subsite '%s'", subsite[1:]) CONTEXT.OUTPUT_FOLDER = os.path.abspath( os.path.join(base_folder, 'dist', subsite[1:])) CONTEXT.BASE_FOLDER = os.path.join(source_folder, subsite) CONTEXT.SOURCE_FOLDER = os.path.join(source_folder, subsite) generateSite() logging.info("Completed everything in %f seconds", (time.time() - time_all))
def OnInit(self): frame = PhotoOrganizerWindow(None) load_plugins(frame) frame.Show() self.SetTopWindow(frame) return True
def fetch_feeds(self, feeds): """ Fetch given feeds, possibly parallelizing requests """ start = time.time() load_plugins() logger.debug(u"starting fetcher") trigger_event('fetch_started') if config.fetcher.processes: from multiprocessing import Pool p = Pool(config.fetcher.processes) p.map(feed_worker, feeds) else: # Just sequence requests in this process for feed in feeds: feed_worker(feed) trigger_event('fetch_done', feeds) logger.info(u"%d feeds checked in %.2fs" % (len(feeds), time.time() - start))
def init_plugin_system(): # Detect plugins path = os.path.abspath(os.path.dirname(sys.argv[0])) + os.path.sep plugins_path = path + "plugins/" if not (os.path.exists(plugins_path) and os.path.isdir(plugins_path)): print_err("Could not find plugins, expected at: " + plugins_path) # Try and load plugins plugins.load_plugins(plugins_path)
def main(): """ The main function. Parses command line arguments, sets up logging, gets the user's login info, sets up any background task and starts the bot. """ # Setup logger with level specified in start_args or logging.INFO logging.basicConfig( filename=start_args.log_file, level=start_args.log_level, format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s" ) # Always keep the websockets.protocol logger at INFO as a minimum unless --enable-protocol-logging is set if not start_args.enable_protocol_logging: discord_logger = logging.getLogger("websockets.protocol") discord_logger.setLevel(start_args.log_level if start_args. log_level >= logging.INFO else logging.INFO) # Setup some config for more customization bot_meta = config.Config( "bot_meta", pretty=True, data=dict( name="PCBOT", command_prefix=config.default_command_prefix, case_sensitive_commands=config.default_case_sensitive_commands, display_owner_error_in_chat=False)) config.name = bot_meta.data["name"] config.default_command_prefix = bot_meta.data["command_prefix"] config.default_case_sensitive_commands = bot_meta.data[ "case_sensitive_commands"] config.owner_error = bot_meta.data["display_owner_error_in_chat"] # Set the client for the plugins to use plugins.set_client(client) utils.set_client(client) # Load plugin for builtin commands plugins.load_plugin("builtin", "pcbot") # Load all dynamic plugins plugins.load_plugins() # Login with the specified token if specified token = start_args.token or input("Token: ") login = [token] # Setup background tasks client.loop.create_task(add_tasks()) try: client.run(*login) except discord.errors.LoginFailure as e: logging.error(utils.format_exception(e))
def __init__(self): self.anon_mode = False self.muted = False self.start_time = int(time.time()) self.connect(self.anon_mode) self.flood_prevention = [] # plugin time! plugins.load_plugins(self) self.loaded_plugins = plugins.loaded_plugins @self.sio.on("chatMsg") def chat_msg(data, dolphinbot=self): if data["username"] == config.nick or data["username"] in self.flood_prevention: return False if self.muted: return False self.flood_prevention.append(data["username"]) command = str(data["msg"]).split(" ")[0] for plugin_name, plugin_data in self.loaded_plugins.items(): skip_command = False if not len(plugin_data[1]): skip_command = True if command in plugin_data[1] or skip_command == True: if plugin_data[2] is False: self.call_plugin(plugin_data[0], plugin_name, data) time.sleep(3) self.flood_prevention.remove(data["username"]) @self.sio.on("pm") def pm(data, dolphinbot=self): if data["username"] == config.nick or data["username"] in self.flood_prevention: return False self.flood_prevention.append(data["username"]) command = str(data["msg"]).split(" ")[0] for plugin_name, plugin_data in self.loaded_plugins.items(): skip_command = False if not len(plugin_data[1]): skip_command = True if command in plugin_data[1] or skip_command is True: if plugin_data[2] is True: self.call_plugin(plugin_data[0], plugin_name, data) self.flood_prevention.remove(data["username"]) @self.sio.on("addUser") def add_user(data, dolphinbot=self): if data["name"] == config.nick: return False if self.muted: return False for plugin_name, plugin_data in self.loaded_plugins.items(): if hasattr(plugin_data[0], plugin_name + "_user_join"): self.call_plugin(plugin_data[0], plugin_name + "_user_join", data)
def main(): plugins.load_plugins() plugins.import_plugins() app = QApplication(sys.argv) # qt_translator = QTranslator() # print(qt_translator.load("test")) # print(QLocale.system().name()) # app.installTranslator(qt_translator) w = GSMMainWindow() w.show() return app.exec_()
def main(): parser = ArgumentParser() parser.add_argument("--token", "-t", help="Specified login token", required=True) start_args = parser.parse_args() plugins.set_client(client) plugins.load_plugins() log.info("Starting client...") client.run(start_args.token)
def main(): loop = asyncio.get_event_loop() bcc = Broadcast(loop=loop) app = GraiaMiraiApplication( broadcast=bcc, connect_info=Session( host="http://xqh.ma:12321", # 填入 httpapi 服务运行的地址 authKey="ltrump923429", # 填入 authKey account=3218088431, # 你的机器人的 qq 号 websocket=True # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作. )) env['app'] = app env['bcc'] = bcc load_plugins() app.launch_blocking()
def run_rcommander(plugin_namespace, robot=None, tf_listener=None): import plugins import state_machine_tool as smt import sleep_tool as st import pointcloud_click_tool as ptl import freeze_frame_tool as frz app = qtg.QApplication(sys.argv) signal.signal(signal.SIGINT, signal.SIG_DFL) rc = RCommander(app) app.connect(app, qtc.SIGNAL('lastWindowClosed()'), app.quit) app.connect(rc.ui.action_quit, qtc.SIGNAL('clicked()'), app.quit) rc.set_robot(robot, tf_listener) default_tools = [['Origins', ptl.PointCloudClickTool(rc), 'default_frame'], ['Origins', frz.FreezeFrameTool(rc), 'default_frame'], ['Misc', smt.StateMachineTool(rc), 'default'], ['Misc', st.SleepTool(rc), 'default'], ['Misc', tt.TriggerTool(rc), 'default']] tools_list = [] for n, t, ns in default_tools: if ns in plugin_namespace: tools_list.append([n, t]) plugin_clses = plugins.load_plugins(plugin_namespace) for tab_name, pcls in plugin_clses: tools_list.append([tab_name, pcls(rc)]) rc.add_tools(tools_list) rc.show() sys.exit(app.exec_())
def load_plugins(self): for view, timeline_renderer, msg_types in plugins.load_plugins(): for msg_type in msg_types: self._viewer_types.setdefault(msg_type, []).append(view) if timeline_renderer: self._timeline_renderers[msg_type] = timeline_renderer( self)
async def program(): if CONFIG['server_start_command'] is None and \ (CONFIG['command_sink'] == 'subprocess' or CONFIG['log_source'] == 'subprocess'): print('You need to provide a server_start_command if your command_sink or log_source ' 'are set to "subprocess"') return server_process = None if CONFIG['server_start_command'] is not None: stdin_pipe_setting = \ subprocess.PIPE if CONFIG['command_sink'] == 'subprocess' else subprocess.DEVNULL stdout_pipe_setting = \ subprocess.PIPE if CONFIG['log_source'] == 'subprocess' else subprocess.DEVNULL server_process = subprocess.Popen(shlex.split(CONFIG['server_start_command']), shell=False, stdin=stdin_pipe_setting, stdout=stdout_pipe_setting) # We need to kill this process if the server dies async def kill_main_thread_coro(): exit(1) asyncio_loop = asyncio.get_event_loop() def monitor_subprocess(): while True: try: server_process.wait(SERVER_POLL_INTERVAL) asyncio.run_coroutine_threadsafe(kill_main_thread_coro(), asyncio_loop) break except subprocess.TimeoutExpired: pass monitor_thread = threading.Thread(target=monitor_subprocess) monitor_thread.setDaemon(True) monitor_thread.start() # Let Minecraft start await asyncio.sleep(CONFIG['minecraft_wait_timeout']) atexit.register( lambda: server_process.kill()) command_sink = None log_source = None if CONFIG['log_source'] == 'subprocess': log_source = monitoring.StdoutMonitor(server_process.stdout) else: log_source = monitoring.FileMonitor(CONFIG['log_source']) if CONFIG['command_sink'] == 'subprocess': command_sink = stdin_handler.StdinHandler(server_process.stdin) elif CONFIG['command_sink'].startswith('rcon:'): [_, port, password] = CONFIG['command_sink'].split(':', 2) command_sink = RconConnection() await command_sink.connect(int(port), password) asyncio.ensure_future(command_sink.server_communication_loop()) else: print('Invalid "command_sink" value') return plugins = plugins_loader.load_plugins(CONFIG['plugins_directory'], command_sink) await program_loop(plugins, log_source)
def run_rcommander(plugin_namespace, robot=None, tf_listener=None, width=600, height=600): import plugins import state_machine_tool as smt import sleep_tool as st import pointcloud_click_tool as ptl import freeze_frame_tool as frz app = qtg.QApplication(sys.argv) signal.signal(signal.SIGINT, signal.SIG_DFL) rc = RCommander(app, width, height) app.connect(app, qtc.SIGNAL('lastWindowClosed()'), app.quit) app.connect(rc.ui.action_quit, qtc.SIGNAL('clicked()'), app.quit) rc.set_robot(robot, tf_listener) default_tools = [['Origins', ptl.PointCloudClickTool(rc), 'default_frame'], ['Origins', frz.FreezeFrameTool(rc), 'default_frame'], ['Misc', smt.StateMachineTool(rc), 'default'], ['Misc', st.SleepTool(rc), 'default'], ['Misc', tt.TriggerTool(rc), 'default']] tools_list = [] for n,t,ns in default_tools: if ns in plugin_namespace: tools_list.append([n,t]) plugin_clses = plugins.load_plugins(plugin_namespace) for tab_name, pcls in plugin_clses: tools_list.append([tab_name, pcls(rc)]) rc.add_tools(tools_list) rc.show() sys.exit(app.exec_())
def load_authorizations(self): auth_plugins = plugins.load_plugins("auth") for ap in auth_plugins: try: plugin_schema_name = ap.get_configuration_schema()[0] ap.read_configuration( Config.RawConfig["auth"][plugin_schema_name]) ap.on_load() except Exception as ee: logger.error(f"failed to configure {ap}, exception: {ee}") return auth_plugins
def on_start(self): if config.getboolean('Other', 'log_network_packets'): import os import tempfile logfile = os.path.join(tempfile.gettempdir(), "netlog.txt") netlog.setLevel(logging.INFO) fh = logging.FileHandler(logfile, mode="w") fmt = logging.Formatter("[%(asctime)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S") fh.setFormatter(fmt) netlog.addHandler(fh) monsterdb.read_monster_db() itemdb.load_itemdb('itemdb.txt') dbgh = DebugLogHandler(self) dbgh.setFormatter( logging.Formatter("[%(asctime)s] %(message)s", datefmt="%H:%M")) debuglog.addHandler(dbgh) debuglog.setLevel(logging.INFO) net2 = DebugLogHandler(self) net2.setFormatter( logging.Formatter("[%(asctime)s] %(message)s", datefmt="%H:%M")) net2.setLevel(logging.ERROR) netlog.addHandler(net2) plugins.load_plugins(config) handlers.app = self import chat chat.pp_actions = () # self.reconnect() Clock.schedule_once(self.update_online_list, 0.2) Clock.schedule_interval(self.update_online_list, 35) Clock.schedule_interval(self.update_loop, 0) Clock.schedule_once(self.show_menu, 1.5)
def start(self): LOG.info("Start bot") LOG.info("Load plugins") plugins = load_plugins() LOG.info("Loaded plugins: %s" % self._plugins) for p in plugins: LOG.info('Initialize plugin: %s' % p.name) p = p(self.connection, self.channels) LOG.info("Start plugin %s" % p) p.start() self._plugins.append(p) LOG.info("Start loop") super(IRCBot, self).start()
def on_start(self): if config.getboolean('Other', 'log_network_packets'): import os import tempfile logfile = os.path.join(tempfile.gettempdir(), "netlog.txt") netlog.setLevel(logging.INFO) fh = logging.FileHandler(logfile, mode="w") fmt = logging.Formatter("[%(asctime)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S") fh.setFormatter(fmt) netlog.addHandler(fh) monsterdb.read_monster_db() itemdb.load_itemdb('itemdb.txt') dbgh = DebugLogHandler(self) dbgh.setFormatter(logging.Formatter("[%(asctime)s] %(message)s", datefmt="%H:%M")) debuglog.addHandler(dbgh) debuglog.setLevel(logging.INFO) net2 = DebugLogHandler(self) net2.setFormatter(logging.Formatter("[%(asctime)s] %(message)s", datefmt="%H:%M")) net2.setLevel(logging.ERROR) netlog.addHandler(net2) plugins.load_plugins(config) handlers.app = self # self.reconnect() Clock.schedule_once(self.update_online_list, 0.2) Clock.schedule_interval(self.update_online_list, 35) Clock.schedule_interval(self.update_loop, 0) Clock.schedule_once(self.show_menu, 1.5)
def on_start(self): if config.getboolean('Other', 'log_network_packets'): import os import tempfile logfile = os.path.join(tempfile.gettempdir(), "netlog.txt") netlog.setLevel(logging.INFO) fh = logging.FileHandler(logfile, mode="w") fmt = logging.Formatter("[%(asctime)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S") fh.setFormatter(fmt) netlog.addHandler(fh) monsterdb.read_monster_db() dbgh = DebugLogHandler(self) dbgh.setFormatter(logging.Formatter("[%(asctime)s] %(message)s", datefmt="%H:%M")) debuglog.addHandler(dbgh) debuglog.setLevel(logging.INFO) plugins.load_plugins(config, 'chatlogfile') handlers.app = self net.login(host=config.get('Server', 'host'), port=config.getint('Server', 'port'), username=config.get('Player', 'username'), password=config.get('Player', 'password'), charname=config.get('Player', 'charname')) self.root.map_w.tile_size = config.getint('GUI', 'tile_size') Clock.schedule_once(self.update_online_list, 0.2) Clock.schedule_interval(self.update_online_list, 35) Clock.schedule_interval(self.update_loop, 0)
def handler(msg): content_type, chat_type, chat_id = telepot.glance(msg) print(content_type, chat_type, chat_id, msg['text']) plugins = load_plugins() if content_type == 'text': command = msg['text'] command = command.split(' ')[0] command = command.split('@')[0] command = command.split('/', 1)[1] if command in plugins: text = plugins[command]['command']() else: text = 'Sorry, I don\'t understand what you mean by "{}"'.format( msg['text']) text += usage(plugins) bot.sendMessage(chat_id, text)
if __name__ == '__main__': import plugins import point_tool as ptl import state_machine_tool as smt import sleep_tool as st app = QApplication(sys.argv) rc = RCommander() app.connect(app, SIGNAL('lastWindowClosed()'), app.quit) app.connect(rc.ui.action_quit, SIGNAL('clicked()'), app.quit) #Load plugins tools_list = [['Graph', st.SleepTool(rc)], ['Graph', ptl.Point3DTool(rc)], ['Graph', smt.StateMachineTool(rc)]] plugin_clses = plugins.load_plugins() print 'found plugins', plugin_clses for tab_name, pcls in plugin_clses: tools_list.append([tab_name, pcls(rc)]) rc.add_tools(tools_list) rc.show() sys.exit(app.exec_())
def main(argd): """ Main entry point, expects doctopt arg dict as argd """ global DEBUG DEBUG = argd['--debug'] if not DEBUG: plugins.debugprinter.disable() if argd['--customhelp']: return 0 if plugins.custom_plugin_help() else 1 try: # Load all available plugins. plugins.load_plugins(PLUGINDIR) except plugins.InvalidConfig as ex: print_err(ex) return 1 # Do any procedures that don't require a file name/type. if argd['--plugins']: plugins.list_plugins() return 0 elif argd['--config']: return 0 if plugins.config_dump() else 1 # Determine plugin based on file name/file type/explicit name. use_default_plugin = not (argd['--pluginhelp'] or argd['--pluginconfig']) debug('Use default plugin?: {}'.format(use_default_plugin)) plugin = get_plugin(argd, use_default=use_default_plugin) if not plugin: # Not a valid plugin name, user cancelled text plugin use. return 1 if DEBUG_PLUGIN: plugins.print_json(plugin.attributes(), sort_keys=True) # Notify plugin that this might be a dry run. plugin.dryrun = argd['--dryrun'] if argd['--executable'] and 'chmodx' in plugin.ignore_post: # Current behaviour says files are made executable unless told # otherwise, so to 'force chmodx' simply means to remove it from the # 'ignored' list. try: plugin.ignore_post.remove('chmodx') except (AttributeError, KeyError): pass pluginname = plugin.get_name().title() debug('Using plugin: {}'.format(pluginname)) # Do plugin help. if argd['--pluginhelp']: return 0 if plugin.help() else 1 elif argd['--pluginconfig']: return 0 if plugin.config_dump() else 1 elif hasattr(plugin, 'run'): # This is a post plugin, it should only be used as a command. debug( 'Running post-processing plugin as command: {}'.format(pluginname)) try: exitcode = plugin._run(args=argd['ARGS']) except NotImplementedError as ex: print_err(str(ex)) exitcode = 1 except plugins.SignalExit as excancel: exitcode = handle_signalexit(excancel) except Exception: exitcode = handle_exception('{} error:'.format(pluginname), *sys.exc_info()) return exitcode # Get valid file name for this file. fname = expand_path(ensure_file_ext(argd['FILENAME'], plugin)) # Make sure the file name doesn't conflict with any plugins. # ...mainly during development and testing. if plugins.conflicting_file(plugin, argd['FILENAME'], fname): return 1 try: content = plugin._create(fname, argd['ARGS']) except plugins.SignalAction as action: # See if we have content to write # No-content is fatal unless explicitly allowed. if not (action.content or plugin.allow_blank): errmsg = 'Plugin action with no content!\n {}' print_err(errmsg.format(action.message)) return 1 content = action.content # Print plugin notification of any major changes (file name changes) if action.message: for line in action.message.split('\n'): plugin.print_status(line) # Plugin is changing the output file name. if action.filename: fname = action.filename # Plugin is adding ignore_post plugins. if action.ignore_post: debug('Adding ignore_post: {!r}'.format(action.ignore_post)) plugin.ignore_post.update(action.ignore_post) except plugins.SignalExit as excancel: # Plugin wants to stop immediately. return handle_signalexit(excancel) except Exception: return handle_exception('{} error:'.format(pluginname), *sys.exc_info()) # Confirm overwriting existing files, exit on refusal. # Non-existant file names are considered valid, and need no confimation. if not valid_filename( fname, dryrun=argd['--dryrun'], overwrite=argd['--overwrite']): return 1 if not (plugin.allow_blank or content): debug('{} is not allowed to create a blank file.'.format(pluginname)) print_err('\nFailed to create file: {}'.format(fname)) return 1 if argd['--noopen']: # Don't open the file. debug('Cancelling open plugin for {}'.format(plugin.get_name())) plugin.ignore_deferred.add('open') return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])
def load_line(self, line, arglines): """Process a configuration directive.""" l = line.split(None, 1) if len(l) == 1 and l[0] == "feeddefaults": l.append("") elif len(l) != 2: raise ConfigError("Bad line in config: " + line) handled_arglines = False if l[0] == "feed": l = l[1].split(None) if len(l) < 2: raise ConfigError("Bad line in config: " + line) self["feedslist"].append((l[1], parse_time(l[0]), parse_feed_args(l[2:], arglines))) handled_arglines = True elif l[0] == "feeddefaults": self["feeddefaults"] = parse_feed_args(l[1].split(None), arglines) handled_arglines = True elif l[0] == "define": l = l[1].split(None, 1) if len(l) != 2: raise ConfigError("Bad line in config: " + line) self["defines"][l[0]] = l[1] elif l[0] == "plugindirs": for dir in parse_list(l[1]): plugins.load_plugins(os.path.join(self.plugin_basedir, dir), self) elif l[0] == "outputfile": self["outputfile"] = l[1] elif l[0] == "outputfileold": self["outputfileold"] = l[1] elif l[0] == "maxarticles": self["maxarticles"] = int(l[1]) elif l[0] == "maxage": self["maxage"] = parse_time(l[1]) elif l[0] == "expireage": self["expireage"] = parse_time(l[1]) elif l[0] == "keepmin": self["keepmin"] = int(l[1]) elif l[0] == "dayformat": self["dayformat"] = l[1] elif l[0] == "timeformat": self["timeformat"] = l[1] elif l[0] == "datetimeformat": self["datetimeformat"] = l[1] elif l[0] == "userefresh": self["userefresh"] = parse_bool(l[1]) elif l[0] == "showfeeds": self["showfeeds"] = parse_bool(l[1]) elif l[0] == "timeout": self["timeout"] = parse_time(l[1], "s") elif l[0] == "template": self["template"] = l[1] elif l[0] == "itemtemplate": self["itemtemplate"] = l[1] elif l[0] == "verbose": self["verbose"] = parse_bool(l[1]) elif l[0] == "ignoretimeouts": self["ignoretimeouts"] = parse_bool(l[1]) elif l[0] == "daysections": self["daysections"] = parse_bool(l[1]) elif l[0] == "timesections": self["timesections"] = parse_bool(l[1]) elif l[0] == "blocklevelhtml": self["blocklevelhtml"] = parse_bool(l[1]) elif l[0] == "tidyhtml": self["tidyhtml"] = parse_bool(l[1]) elif l[0] == "sortbyfeeddate": self["sortbyfeeddate"] = parse_bool(l[1]) elif l[0] == "currentonly": self["currentonly"] = parse_bool(l[1]) elif l[0] == "hideduplicates": self["hideduplicates"] = parse_list(l[1]) elif l[0] == "newfeedperiod": self["newfeedperiod"] = l[1] elif l[0] == "changeconfig": self["changeconfig"] = parse_bool(l[1]) elif l[0] == "numthreads": self["numthreads"] = int(l[1]) elif l[0] == "include": self.load(os.path.join(self.basedir, l[1]), False) elif plugins.call_hook("config_option_arglines", self, l[0], l[1], arglines): handled_arglines = True elif plugins.call_hook("config_option", self, l[0], l[1]): pass else: raise ConfigError("Unknown config command: " + l[0]) if arglines != [] and not handled_arglines: raise ConfigError("Bad argument lines in config after: " + line)
def player_warp(data): mapserv.cmsg_map_loaded() @extends('smsg_map_login_success') def map_login_success(data): mapserv.cmsg_map_loaded() if __name__ == '__main__': logging.basicConfig(format="[%(asctime)s] %(message)s", level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S") config = ConfigParser() config.read('manachat.ini') load_itemdb('itemdb.txt') plugins.load_plugins(config) net.login(host=config.get('Server', 'host'), port=config.getint('Server', 'port'), username=config.get('Player', 'username'), password=config.get('Player', 'password'), charname=config.get('Player', 'charname')) try: asyncore.loop() except KeyboardInterrupt: mapserv.cleanup()
# If this fails we have problems. import plugins # Can be set for more output. plugins.DEBUG = False plugins.debugprinter.enable(plugins.DEBUG) # Use the existing print_err, instead of writing a new one. print_err = plugins.print_err SCRIPTDIR = os.path.abspath(sys.path[0]) PLUGINDIR = os.path.join(SCRIPTDIR, 'plugins') print('Loading plugins from: {}'.format(PLUGINDIR)) plugins.load_plugins(PLUGINDIR) if not all(len(plugins.plugins[k]) > 0 for k in plugins.plugins): print( 'Failed to load any plugins: {!r}'.format(plugins.plugins), file=sys.stderr) sys.exit(1) # Check internet connection, for plugins that download things (html.jquery). has_internet = True try: con = socket.create_connection(('8.8.8.8', 5353)) except OSError as ex: if ex.errno == 101: has_internet = False else: print_err('Error while detecting internet: {!r}'.format(ex))
# If this fails we have problems. import plugins # Can be set for more output. plugins.DEBUG = False plugins.debugprinter.enable(plugins.DEBUG) # Use the existing print_err, instead of writing a new one. print_err = plugins.print_err SCRIPTDIR = os.path.abspath(sys.path[0]) PLUGINDIR = os.path.join(SCRIPTDIR, 'plugins') print('Loading plugins from: {}'.format(PLUGINDIR)) plugins.load_plugins(PLUGINDIR) if not all(len(plugins.plugins[k]) > 0 for k in plugins.plugins): print('Failed to load any plugins: {!r}'.format(plugins.plugins), file=sys.stderr) sys.exit(1) # Check internet connection, for plugins that download things (html.jquery). has_internet = True try: con = socket.create_connection(('8.8.8.8', 5353)) except OSError as ex: if ex.errno == 101: has_internet = False else: print_err('Error while detecting internet: {!r}'.format(ex)) else:
def main(): """ The main function. Parses command line arguments, sets up logging, gets the user's login info, sets up any background task and starts the bot. """ # Add all command-line arguments parser = ArgumentParser(description="Run PCBOT.") parser.add_argument("--version", "-V", help="Return the current version.", action="version", version=__version__) # Setup a login group for handling only token or email, but not both login_group = parser.add_mutually_exclusive_group() login_group.add_argument( "--token", "-t", help="The token to login with. Prompts if omitted.") login_group.add_argument("--email", "-e", help="Alternative email to login with.") parser.add_argument("--new-pass", "-n", help="Always prompts for password.", action="store_true") parser.add_argument( "--log-level", "-l", help= "Use the specified logging level (see the docs on logging for values).", type=lambda s: getattr(logging, s.upper()), default=logging.INFO, metavar="LEVEL") start_args = parser.parse_args() # Setup logger with level specified in start_args or logging.INFO logging.basicConfig( level=start_args.log_level, format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s" ) # Always keep discord.py logger at INFO as a minimum discord_logger = logging.getLogger("discord") discord_logger.setLevel(start_args.log_level if start_args. log_level >= logging.INFO else logging.INFO) # Setup some config for more customization bot_meta = config.Config( "bot_meta", pretty=True, data=dict( name="PCBOT", command_prefix=config.default_command_prefix, case_sensitive_commands=config.default_case_sensitive_commands, display_owner_error_in_chat=False)) config.name = bot_meta.data["name"] config.default_command_prefix = bot_meta.data["command_prefix"] config.default_case_sensitive_commands = bot_meta.data[ "case_sensitive_commands"] config.owner_error = bot_meta.data["display_owner_error_in_chat"] # Set the client for the plugins to use plugins.set_client(client) utils.set_client(client) # Load plugin for builtin commands plugins.load_plugin("builtin", "pcbot") # Load all dynamic plugins plugins.load_plugins() # Handle login if not start_args.email: # Login with the specified token if specified token = start_args.token or input("Token: ") login = [token] else: # Get the email from commandline argument email = start_args.email password = "" cached_path = client._get_cache_filename( email) # Get the name of the would-be cached email # If the --new-pass command-line argument is specified, remove the cached password # Useful for when you have changed the password if start_args.new_pass: if os.path.exists(cached_path): os.remove(cached_path) # Prompt for password if the cached file does not exist (the user has not logged in before or # they they entered the --new-pass argument) if not os.path.exists(cached_path): password = getpass() login = [email, password] # Setup background tasks client.loop.create_task(add_tasks()) try: client.run(*login) except discord.errors.LoginFailure as e: logging.error(utils.format_exception(e))
def find_parser(url, args): plugins = load_plugins() for plugin in plugins: if plugin.can_handle(url): return plugin.get_parser(url, args) raise Exception("No plugin for URL: %s" % url)
def main(argd): """ Main entry point, expects doctopt arg dict as argd """ global DEBUG plugins.DEBUG = DEBUG = argd['--debug'] # Load all available plugins. plugins.load_plugins(PLUGINDIR) # Do any procedures that don't require a file name/type. if argd['--plugins']: plugins.list_plugins() return 0 elif argd['--config']: return 0 if plugins.config_dump() else 1 # Determine plugin based on file name/file type/explicit name. plugin = plugins.determine_plugin(argd) if not plugin: ftype = argd['PLUGIN'] or argd['FILENAME'] errmsg = '\n'.join( ('Not a valid file type (not supported): {}', 'Use --plugins to list available plugins.\n')).format(ftype) print_err(errmsg) return 1 if argd['--executable'] and 'chmodx' in plugin.ignore_post: # Current behaviour says files are made executable unless told # otherwise, so to 'force chmodx' simply means to remove it from the # 'ignored' list. with suppress(AttributeError, KeyError): plugin.ignore_post.remove('chmodx') pluginname = plugin.get_name().title() debug('Using plugin: {}'.format(pluginname)) # Do plugin help. if argd['--pluginhelp']: return 0 if plugins.plugin_help(plugin) else 1 elif argd['--pluginconfig']: return 0 if plugins.plugin_config_dump(plugin) else 1 # Get valid file name for this file. fname = ensure_file_ext(argd['FILENAME'], plugin) # Make sure the file name doesn't conflict with any plugins. # ...mainly during development and testing. if plugins.conflicting_file(plugin, argd['FILENAME'], fname): return 1 try: content = plugin._create(fname, argd['ARGS']) except plugins.SignalAction as action: # See if we have content to write # No-content is fatal unless explicitly allowed. if not (action.content or plugin.allow_blank): errmsg = 'Plugin action with no content!\n {}' print(errmsg.format(action.message)) return 1 content = action.content # Print plugin notification of any major changes (file name changes) if action.message: print(action.message) # Plugin is changing the output file name. if action.filename: fname = action.filename except plugins.SignalExit as excancel: # Plugin wants to stop immediately. if excancel.code != 0: # This was a real error, so print a message. reason = excancel.reason or 'No reason was given for the exit.' print('\n{}\n'.format(reason)) return excancel.code except Exception as ex: print_ex(ex, '{} error:'.format(pluginname), with_class=True) return 1 # Confirm overwriting existing files, exit on refusal. # Non-existant file names are considered valid, and need no confimation. if not valid_filename(fname): return 1 if not (plugin.allow_blank or content): debug('{} is not allowed to create a blank file.'.format(pluginname)) print('\nFailed to create file: {}'.format(fname)) return 1 return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])
def test_load(self): plugs = load_plugins()
parser.add_argument('-v', '--version', type=int, choices=[1,2,3], default=3, help='specify ldap version') parser.add_argument('--debug', action='store_true', help='implies --verbose') parser.add_argument('--name-server', dest='name_server', help='specify name server for domain') parser.add_argument('--dn', action='store_true', help='list distinguished names of AD objects') parser.add_argument('--insecure', action='store_true', help='ignore invalid tls certs') #parser.add_argument('--cert', help='') #parser.add_argument('--auth', default='ntlm', type=str.lower, choices=['ntlm', 'kerb'], help='auth type') parser.set_defaults(search_base=None) parser.set_defaults(handler=None) tls_group = parser.add_mutually_exclusive_group() tls_group.add_argument('--tls', action='store_true', help='initiate connection with TLS') tls_group.add_argument('--start-tls', dest='starttls', action='store_true', help='use START_TLS') subparsers = parser.add_subparsers(help='choose an action') plugin_list = plugins.load_plugins(subparsers) args = parser.parse_args() socket.setdefaulttimeout(args.timeout) if args.debug: h = logging.StreamHandler() h.setFormatter(logging.Formatter('[%(levelname)s] %(filename)s:%(lineno)s %(message)s')) for n in [__name__, 'plugins', 'modules']: l = logging.getLogger(n) l.setLevel(logging.DEBUG) l.addHandler(h) elif args.verbose: h = logging.StreamHandler() h.setFormatter(logging.Formatter('[%(levelname)s] %(message)s')) for n in [__name__, 'plugins', 'modules']:
def player_warp(data): mapserv.cmsg_map_loaded() @extends('smsg_map_login_success') def map_login_success(data): mapserv.cmsg_map_loaded() if __name__ == '__main__': logging.basicConfig(format="[%(asctime)s] %(message)s", level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S") config = ConfigParser() config.read('manachat.ini') load_itemdb('itemdb.txt') plugin_list = config.get('Core', 'plugins').split() plugins.load_plugins(config, *plugin_list) net.login(host=config.get('Server', 'host'), port=config.getint('Server', 'port'), username=config.get('Player', 'username'), password=config.get('Player', 'password'), charname=config.get('Player', 'charname')) try: asyncore.loop() except KeyboardInterrupt: mapserv.cleanup()
def main(): """ The main function. Parses command line arguments, sets up logging, gets the user's login info, sets up any background task and starts the bot. """ # Add all command-line arguments parser = ArgumentParser(description="Run PCBOT.") parser.add_argument("--version", "-V", help="Return the current version.", action="version", version=__version__) # Setup a login group for handling only token or email, but not both login_group = parser.add_mutually_exclusive_group() login_group.add_argument("--token", "-t", help="The token to login with. Prompts if omitted.") login_group.add_argument("--email", "-e", help="The email to login to. Token prompt is default.") parser.add_argument("--new-pass", "-n", help="Always prompts for password.", action="store_true") parser.add_argument("--log-level", "-l", help="Use the specified logging level (see the docs on logging for values).", type=lambda s: getattr(logging, s.upper()), default=logging.INFO, metavar="LEVEL") start_args = parser.parse_args() # Setup logger with level specified in start_args or logging.INFO logging.basicConfig(level=start_args.log_level, format="%(levelname)s %(asctime)s [%(module)s / %(name)s]: %(message)s") # Always keep discord.py logger at INFO as a minimum discord_logger = logging.getLogger("discord") discord_logger.setLevel(start_args.log_level if start_args.log_level >= logging.INFO else logging.INFO) # Setup some config for more customization bot_meta = config.Config("bot_meta", pretty=True, data=dict( name="PCBOT", command_prefix=config.command_prefix )) config.name = bot_meta.data["name"] config.command_prefix = bot_meta.data["command_prefix"] # Set the client for the plugins to use plugins.set_client(client) # Load plugin for builtin commands plugins.load_plugin("builtin", "pcbot") # Load all dynamic plugins plugins.load_plugins() # Handle login if not start_args.email: # Login with the specified token if specified token = start_args.token or input("Token: ") login = [token] else: # Get the email from commandline argument email = start_args.email password = "" cached_path = client._get_cache_filename(email) # Get the name of the would-be cached email # If the --new-pass command-line argument is specified, remove the cached password # Useful for when you have changed the password if start_args.new_pass: if os.path.exists(cached_path): os.remove(cached_path) # Prompt for password if the cached file does not exist (the user has not logged in before or # they they entered the --new-pass argument) if not os.path.exists(cached_path): password = getpass() login = [email, password] # Setup background tasks client.loop.create_task(add_tasks()) try: client.run(*login) except discord.errors.LoginFailure as e: logging.error(utils.format_exception(e))
import json import logging from discord.ext import commands import plugins with open("config.json", "r") as f: config: dict = json.load(f) client = commands.Bot(command_prefix=commands.when_mentioned_or('!'), description="League of Legends Trivia", pm_help=False, owner_id=config["bot"]["owner_id"] or None) plugins.load_plugins(client, config) @client.event async def on_ready(): logger.info(f"Logged in. User: {client.user}, ID: {client.user.id}") @client.event async def on_command_error(ctx: commands.Context, e: BaseException): if isinstance(e, (commands.BadArgument, commands.MissingRequiredArgument, commands.CommandOnCooldown)): # do these really warrant a traceback? return logger.error(f'Ignoring exception in command {ctx.command}') logger.error("Logging an uncaught exception",
#!/usr/bin/env python import logging import yara # type: ignore import config import json import sys from lib.ursadb import UrsaDb from util import setup_logging, make_sha256_tag from typing import Any, List from lib.yaraparse import parse_yara, combine_rules from db import AgentTask, JobId, Database, MatchInfo, TaskType from cachetools import cached, LRUCache from metadata import MetadataPlugin, Metadata from plugins import load_plugins METADATA_PLUGINS = load_plugins(config.PLUGINS) @cached(cache=LRUCache(maxsize=32), key=lambda db, job: job.key) def compile_yara(db: Database, job: JobId) -> Any: """Gets a compiled yara rule belinging to the provided job. Uses cache to speed up compilation. :param job: ID of the job to compile yara for. :type job: JobId :raises SyntaxError: When yara rule has invalid syntax. :return: Compiled yara rule. :rtype: Any """ yara_rule = db.get_yara_by_job(job)
import sys from mirai import Mirai from plugins import load_plugins if __name__ == '__main__': if len(sys.argv) >= 2: app = Mirai(sys.argv[1]) load_plugins(app) app.run() else: print(f'Usage: python3 {sys.argv[0]} mirai://localhost:8080/ws?authKey=$authKey&qq=$qq\n\n' 'Visit https://natriumlab.github.io/tutorial/hello-world.html#hello-world-2 for more details.') exit(1)
def main(argd): """ Main entry point, expects doctopt arg dict as argd """ global DEBUG DEBUG = argd['--debug'] if not DEBUG: plugins.debugprinter.disable() if argd['--customhelp']: return 0 if plugins.custom_plugin_help() else 1 try: # Load all available plugins. plugins.load_plugins(PLUGINDIR) except plugins.InvalidConfig as ex: print_err(ex) return 1 # Do any procedures that don't require a file name/type. if argd['--plugins']: plugins.list_plugins() return 0 elif argd['--config']: return 0 if plugins.config_dump() else 1 # Determine plugin based on file name/file type/explicit name. use_default_plugin = not (argd['--pluginhelp'] or argd['--pluginconfig']) debug('Use default plugin?: {}'.format(use_default_plugin)) plugin = get_plugin(argd, use_default=use_default_plugin) if not plugin: # Not a valid plugin name, user cancelled text plugin use. return 1 if DEBUG_PLUGIN: plugins.print_json(plugin.attributes(), sort_keys=True) # Notify plugin that this might be a dry run. plugin.dryrun = argd['--dryrun'] if argd['--executable'] and 'chmodx' in plugin.ignore_post: # Current behaviour says files are made executable unless told # otherwise, so to 'force chmodx' simply means to remove it from the # 'ignored' list. try: plugin.ignore_post.remove('chmodx') except (AttributeError, KeyError): pass pluginname = plugin.get_name().title() debug('Using plugin: {}'.format(pluginname)) # Do plugin help. if argd['--pluginhelp']: return 0 if plugin.help() else 1 elif argd['--pluginconfig']: return 0 if plugin.config_dump() else 1 elif hasattr(plugin, 'run'): # This is a post plugin, it should only be used as a command. debug('Running post-processing plugin as command: {}'.format( pluginname )) try: exitcode = plugin._run(args=argd['ARGS']) except NotImplementedError as ex: print_err(str(ex)) exitcode = 1 except plugins.SignalExit as excancel: exitcode = handle_signalexit(excancel) except Exception: exitcode = handle_exception( '{} error:'.format(pluginname), *sys.exc_info()) return exitcode # Get valid file name for this file. fname = expand_path( ensure_file_ext(argd['FILENAME'], plugin) ) # Make sure the file name doesn't conflict with any plugins. # ...mainly during development and testing. if plugins.conflicting_file(plugin, argd['FILENAME'], fname): return 1 try: content = plugin._create(fname, argd['ARGS']) except plugins.SignalAction as action: # See if we have content to write # No-content is fatal unless explicitly allowed. if not (action.content or plugin.allow_blank): errmsg = 'Plugin action with no content!\n {}' print_err(errmsg.format(action.message)) return 1 content = action.content # Print plugin notification of any major changes (file name changes) if action.message: for line in action.message.split('\n'): plugin.print_status(line) # Plugin is changing the output file name. if action.filename: fname = action.filename # Plugin is adding ignore_post plugins. if action.ignore_post: debug('Adding ignore_post: {!r}'.format(action.ignore_post)) plugin.ignore_post.update(action.ignore_post) except plugins.SignalExit as excancel: # Plugin wants to stop immediately. return handle_signalexit(excancel) except Exception: return handle_exception( '{} error:'.format(pluginname), *sys.exc_info()) # Confirm overwriting existing files, exit on refusal. # Non-existant file names are considered valid, and need no confimation. if not valid_filename( fname, dryrun=argd['--dryrun'], overwrite=argd['--overwrite']): return 1 if not (plugin.allow_blank or content): debug('{} is not allowed to create a blank file.'.format(pluginname)) print_err('\nFailed to create file: {}'.format(fname)) return 1 if argd['--noopen']: # Don't open the file. debug('Cancelling open plugin for {}'.format(plugin.get_name())) plugin.ignore_deferred.add('open') return handle_content(fname, content, plugin, dryrun=argd['--dryrun'])
def test_load(self): plugs=load_plugins()