def copy_secrets(plugin): """ Copy any potential secrets a plugin could have from the AIGIS secret dump to the specified location. Will not copy anything is a file is missing. :param AigisPlugin plugin: plugin registered in core :raises MissingSecretFileError: if a specified secret cannot be found. """ missing_secrets = [] for secret in plugin.config.SECRETS: if not os.path.exists( os.path.join(path_utils.SECRET_DUMP, os.path.join(plugin.name, secret))): missing_secrets.append( os.path.join(path_utils.SECRET_DUMP, os.path.join(plugin.name, secret))) if not missing_secrets: for secret in plugin.config.SECRETS: path_utils.ensure_path_exists(plugin.config.SECRETS[secret]) shutil.copy2( os.path.join(path_utils.SECRET_DUMP, os.path.join(plugin.name, secret)), plugin.config.SECRETS[secret]) else: raise MissingSecretFileError( "The following secret files are missing:\n" + "\n".join(missing_secrets))
def cleanup(self): """ Clean up all loggers registered in the LogManager """ LOG.shutdown("Cleaning up registered loggers...") for logger in self.loggers: self.loggers[logger].cleanup() LOG.shutdown("Backing up logs to timestamped dir...") log_dump_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), "../", datetime.now().strftime("%Y-%m-%d_%X"))) path_utils.ensure_path_exists(log_dump_dir) shutil.move(path_utils.LOG_LOCATION, log_dump_dir)
def _git_download_plugin(plugin, github_path, plugin_path): """ Download a plugin from github to a local path :param AigisPlugin plugin: plugin object :param str github_path: path to download :param str plugin_path: path to download to :returns: if instruction was successful :rtype: bool """ if path_utils.ensure_path_exists(plugin_path): try: plugin.log.info("Plugin already installed, making sure it's up to date...") subprocess.check_output(["git", "pull"], cwd=plugin_path) except Exception: #pylint: disable=broad-except plugin.log.warning("Unable to update plugin. Git Pull failed.") return True try: _download(github_path, plugin_path) except IOError: plugin.log.error("Problem accessing filepath, skipping plugin") return False return True
def boot(self, message, *args, **kws): #pylint: disable=missing-docstring if self.isEnabledFor(BOOTUP): # Yes, logger takes its '*args' as 'args'. self._log(BOOTUP, message, args, **kws) logging.Logger.boot = boot SHUTDOWN = logging.ERROR + 2 logging.addLevelName(SHUTDOWN, "SHUTDOWN") def shutdown(self, message, *args, **kws): #pylint: disable=missing-docstring if self.isEnabledFor(SHUTDOWN): # Yes, logger takes its '*args' as 'args'. self._log(SHUTDOWN, message, args, **kws) logging.Logger.shutdown = shutdown path_utils.ensure_path_exists(path_utils.LOG_LOCATION) path_utils.ensure_path_exists(path_utils.PLUGIN_LOG_LOCATION) _SH = logging.StreamHandler(sys.stdout) _SH.setFormatter( logging.Formatter('%(asctime)s : %(levelname)s : %(message)s')) LOG = logging.getLogger("AIGIS") _add_log_handlers(LOG, os.path.join(os.path.dirname(__file__), "../log/core.log"))
def __init__(self): super().__init__(self) path_utils.ensure_path_exists(path_utils.PLUGIN_ROOT_PATH)
""" Process AIGIS plugin. """ #pylint: disable=import-error import os import sys import time import shutil import asyncio import subprocess from threading import Thread from utils import path_utils, mod_utils, exc_utils from plugins.external.WatchDog import jiii # Set the dump location for plugin secrets path_utils.ensure_path_exists(path_utils.SECRET_DUMP) # Setup the asyncio event loop for subprocess management ALOOP = asyncio.get_event_loop() ALOOP_FOREVER = Thread(target=ALOOP.run_forever, daemon=True) ALOOP_FOREVER.start() # Max number of seconds to launch a plugin. PLUGIN_LAUNCH_TIMEOUT = 10 class PluginIO(): """ Parent class for loading plugins, containing all the logic that is independent to the plugin type. """ @classmethod