def __init__(self, loglevel=None): config = ClientConfig(encryption_enabled=True, pickle_key=cfg.pickle_key, store_name=cfg.store_name, store_sync_tokens=True) if not os.path.exists(cfg.store_path): os.makedirs(cfg.store_path) self.http_session = aiohttp.ClientSession( headers={'User-Agent': self.user_agent}) self.client = AsyncClient( cfg.server, cfg.user, cfg.device_id, config=config, store_path=cfg.store_path ) logger_group.level = getattr( logbook, loglevel) if loglevel else logbook.CRITICAL logbook.StreamHandler(sys.stdout).push_application() self.logger = logbook.Logger('bot') logger_group.add_logger(self.logger) self.mli = MessageLinksInfo(self.http_session) self._register_commands() self.client.add_response_callback(self._sync_cb, SyncResponse) self.client.add_response_callback( self._key_query_cb, KeysQueryResponse) self.client.add_event_callback(self._invite_cb, InviteMemberEvent)
def __init__(self, name, handler, aliases, help, bot): self.name = name self.handler = handler self.aliases = aliases self.help = help self.bot = bot self.storage = Storage() self.logger = logbook.Logger(name) logger_group.add_logger(self.logger)
def load_plugins(self) -> None: """Dynamically loads all plugins from the plugins directory. New plugins can be added by creating new classes in the `plugins` module. """ self.plugins = {} importlib.import_module("plugins") modules = [] plugin_files = os.listdir(os.path.join(os.path.dirname(__file__), "plugins")) if len(plugin_files) == 0: print("NOTE: No plugin files found.") for plugin in plugin_files: if plugin.startswith("__") or not plugin.endswith(".py"): # Skip files like __init__.py and .gitignore continue module_name = "plugins." + plugin.rsplit(".")[0] modules.append(importlib.import_module(module_name, package="plugins")) for module in modules: if module.__name__ in sys.modules: importlib.reload(module) clsmembers = inspect.getmembers( module, lambda member: inspect.isclass(member) and member.__module__ == module.__name__, ) for name, cls in clsmembers: if not issubclass(cls, BasePlugin): # We only want plugins that derive from BasePlugin CORE_LOG.warn( f"Skipping {name} as it doesn't derive from the BasePlugin" ) continue CORE_LOG.info(f"Loading plugin {name} ...") # Create logger for each plugin plugin_logger = Logger(f"olive.plugin.{name}") plugin_logger.info(f"{name}'s logger is working hard!") logger_group.add_logger(plugin_logger) # Generate standard config config = PluginConfig(plugin_logger) # Instantiate the plugin! self.plugins[name] = cls(config) CORE_LOG.info("Loaded plugins")
#!/usr/bin/env python import json import os import pprint import sys import click from automation import Jenkins from log import Logger, logger_group, DEBUG from repo import Repo, EnterpriseDist, PeModulesVanagon from releases import releases from ticket import PullRequest, Ticket log = Logger(__name__) logger_group.add_logger(log) def parse_build_description(description): log.debug('Build Description: {}'.format(description)) parts = description.split('-') return parts[3][1:] if len(parts) == 4 else None @click.group() @click.option('--debug', is_flag=True) def cli(debug): if debug: logger_group.level = DEBUG
+ f"processing the event {event} in room {room.display_name}." + f"\n{err}", file=sys.stderr, ) _, _, tb = sys.exc_info() traceback.print_tb(tb) async def __sync_cb(self, response: SyncResponse) -> None: with open(self.config.next_batch_file, "w") as next_batch_token: next_batch_token.write(response.next_batch) if __name__ == "__main__": # Handle log output StreamHandler(sys.stdout).push_application() logger_group.add_logger(CORE_LOG) if True: logger_group.level = INFO # if (OUTPUT_NIO_LOGS): # nio_logger_group.level = nio_log.logbook.INFO conf = SessionConfig() session = Session(conf) try: CORE_LOG.info("Starting up") asyncio.get_event_loop().run_until_complete(session.start()) except KeyboardInterrupt: asyncio.get_event_loop().run_until_complete(session.stop())