def set_defaults(self): """ Set the default values for config """ logger.debug("Setting defaults") self.set_globals() current_dir = os.path.dirname(__file__) for dirpath, _, filenames in os.walk(current_dir): default_files = [fname for fname in filenames if fname.endswith("_defaults.py")] if not default_files: continue base_path = os.path.dirname(os.path.realpath(sys.argv[0])) import_path = ".".join(full_path_split(dirpath.replace(base_path, ""))[1:]) plugin_type = import_path.split(".")[-1] for filename in default_files: self.load_module(filename, import_path, plugin_type)
def _defaults_from_plugin(self, plugin_folder): """ Scan the given plugins folder for config defaults.py files and update the default configuration. Parameters ---------- plugin_folder: str The folder to scan for plugins """ for dirpath, _, filenames in os.walk(plugin_folder): default_files = [fname for fname in filenames if fname.endswith("_defaults.py")] if not default_files: continue base_path = os.path.dirname(os.path.realpath(sys.argv[0])) # Can't use replace as there is a bug on some Windows installs that lowers some paths import_path = ".".join(full_path_split(dirpath[len(base_path):])[1:]) plugin_type = import_path.split(".")[-1] for filename in default_files: self._load_defaults_from_module(filename, import_path, plugin_type)