def setup_plugins(): import sys import os import pip import importlib # noqa from importlib.util import module_from_spec, spec_from_file_location # noqa: E402 from indy_common.config_util import getConfigOnce # noqa: E402 import indy_node.server.plugin # noqa: E402 def find_and_load_plugin(plugin_name, plugin_root, installed_packages): if plugin_name in installed_packages: # TODO: Need a test for installed packages plugin_name = plugin_name.replace('-', '_') plugin = importlib.import_module(plugin_name) else: plugin_path = os.path.join(plugin_root.__path__[0], plugin_name, '__init__.py') spec = spec_from_file_location('__init__.py', plugin_path) plugin = module_from_spec(spec) spec.loader.exec_module(plugin) return plugin # TODO: Refactor to use plenum's setup_plugins # TODO: Should have a check to make sure no plugin defines any conflicting ledger id or request field global PLUGIN_LEDGER_IDS global PLUGIN_CLIENT_REQUEST_FIELDS global PLUGIN_CLIENT_REQ_OP_TYPES config = getConfigOnce(ignore_external_config_update_errors=True) plugin_root = config.PLUGIN_ROOT try: plugin_root = importlib.import_module(plugin_root) except ImportError: raise ImportError( 'Incorrect plugin root {}. No such package found'.format( plugin_root)) sys.path.insert(0, plugin_root.__path__[0]) enabled_plugins = config.ENABLED_PLUGINS installed_packages = { p.project_name: p for p in pip.get_installed_distributions() } for plugin_name in enabled_plugins: plugin = find_and_load_plugin(plugin_name, plugin_root, installed_packages) plugin_globals = plugin.__dict__ # The following lines are idempotent so loading the same plugin twice is not the problem. if 'LEDGER_IDS' in plugin_globals: PLUGIN_LEDGER_IDS.update(plugin_globals['LEDGER_IDS']) if 'CLIENT_REQUEST_FIELDS' in plugin_globals: PLUGIN_CLIENT_REQUEST_FIELDS.update( plugin_globals['CLIENT_REQUEST_FIELDS']) if 'REQ_OP_TYPES' in plugin_globals: PLUGIN_CLIENT_REQ_OP_TYPES.update(plugin_globals['REQ_OP_TYPES']) # Reloading message types since some some schemas would have been changed import indy_common.types importlib.reload(indy_common.types)
def migrate_config(): config = getConfigOnce() general_config_path = os.path.join(config.GENERAL_CONFIG_DIR, config.GENERAL_CONFIG_FILE) if not os.path.exists(general_config_path): return if not os.path.isfile(general_config_path): logger.error( "General config '{}' exists, but it is not a regular file, abort migration." .format(general_config_path)) else: logger.info( "Open '{}' for appending missing paths configuration.".format( general_config_path)) general_config_file = open(general_config_path, "a") logger.info("Open '{}' to get missing paths configuration.".format( indy_config.__file__)) indy_config_file = open(indy_config.__file__, "r") general_config_file.write("\n") for line in indy_config_file: if not line.startswith( "NETWORK_NAME") and not line == "# Current network\n": logger.info("Append '{}' line to '{}'.".format( line, general_config_path)) general_config_file.write(line) general_config_file.close() indy_config_file.close()
def migrate_config(): config = getConfigOnce() general_config_path = os.path.join(config.GENERAL_CONFIG_DIR, config.GENERAL_CONFIG_FILE) if not os.path.exists(general_config_path): return if not os.path.isfile(general_config_path): logger.error("General config '{}' exists, but it is not a regular file, abort migration." .format(general_config_path)) else: logger.info("Open '{}' for appending missing paths configuration." .format(general_config_path)) general_config_file = open(general_config_path, "a") logger.info("Open '{}' to get missing paths configuration." .format(indy_config.__file__)) indy_config_file = open(indy_config.__file__, "r") general_config_file.write("\n") for line in indy_config_file: if not line.startswith("NETWORK_NAME") and not line == "# Current network\n": logger.info("Append '{}' line to '{}'." .format(line, general_config_path)) general_config_file.write(line) general_config_file.close() indy_config_file.close()
def setup_plugins(): # TODO: Refactor to use plenum's setup_plugins # TODO: Should have a check to make sure no plugin defines any conflicting ledger id or request field global PLUGIN_LEDGER_IDS global PLUGIN_CLIENT_REQUEST_FIELDS global PLUGIN_CLIENT_REQ_OP_TYPES config = getConfigOnce(ignore_external_config_update_errors=True) plugin_root = config.PLUGIN_ROOT try: plugin_root = importlib.import_module(plugin_root) except ImportError: raise ImportError( 'Incorrect plugin root {}. No such package found'.format( plugin_root)) enabled_plugins = config.ENABLED_PLUGINS for plugin_name in enabled_plugins: plugin_path = os.path.join(plugin_root.__path__[0], plugin_name, '__init__.py') spec = spec_from_file_location('__init__.py', plugin_path) init = module_from_spec(spec) spec.loader.exec_module(init) plugin_globals = init.__dict__ if 'LEDGER_IDS' in plugin_globals: PLUGIN_LEDGER_IDS.update(plugin_globals['LEDGER_IDS']) if 'CLIENT_REQUEST_FIELDS' in plugin_globals: PLUGIN_CLIENT_REQUEST_FIELDS.update( plugin_globals['CLIENT_REQUEST_FIELDS']) if 'REQ_OP_TYPES' in plugin_globals: PLUGIN_CLIENT_REQ_OP_TYPES.update(plugin_globals['REQ_OP_TYPES']) # Reloading message types since some some schemas would have been changed import indy_common.types importlib.reload(indy_common.types)
def setup_plugins(): # TODO: Refactor to use plenum's setup_plugins # TODO: Should have a check to make sure no plugin defines any conflicting ledger id or request field global PLUGIN_LEDGER_IDS global PLUGIN_CLIENT_REQUEST_FIELDS global PLUGIN_CLIENT_REQ_OP_TYPES config = getConfigOnce(ignore_external_config_update_errors=True) plugin_root = config.PLUGIN_ROOT try: plugin_root = importlib.import_module(plugin_root) except ImportError: raise ImportError('Incorrect plugin root {}. No such package found'. format(plugin_root)) sys.path.insert(0, plugin_root.__path__[0]) enabled_plugins = config.ENABLED_PLUGINS installed_packages = {p.project_name: p for p in pip.get_installed_distributions()} for plugin_name in enabled_plugins: plugin = find_and_load_plugin(plugin_name, plugin_root, installed_packages) plugin_globals = plugin.__dict__ # The following lines are idempotent so loading the same plugin twice is not the problem. if 'LEDGER_IDS' in plugin_globals: PLUGIN_LEDGER_IDS.update(plugin_globals['LEDGER_IDS']) if 'CLIENT_REQUEST_FIELDS' in plugin_globals: PLUGIN_CLIENT_REQUEST_FIELDS.update(plugin_globals['CLIENT_REQUEST_FIELDS']) if 'REQ_OP_TYPES' in plugin_globals: PLUGIN_CLIENT_REQ_OP_TYPES.update(plugin_globals['REQ_OP_TYPES']) # Reloading message types since some some schemas would have been changed import indy_common.types importlib.reload(indy_common.types)
def setup_plugins(): # TODO: Refactor to use plenum's setup_plugins # TODO: Should have a check to make sure no plugin defines any conflicting ledger id or request field global PLUGIN_LEDGER_IDS global PLUGIN_CLIENT_REQUEST_FIELDS global PLUGIN_CLIENT_REQ_OP_TYPES config = getConfigOnce(ignore_external_config_update_errors=True) plugin_root = config.PLUGIN_ROOT try: plugin_root = importlib.import_module(plugin_root) except ImportError: raise ImportError('Incorrect plugin root {}. No such package found'. format(plugin_root)) enabled_plugins = config.ENABLED_PLUGINS for plugin_name in enabled_plugins: plugin_path = os.path.join(plugin_root.__path__[0], plugin_name, '__init__.py') spec = spec_from_file_location('__init__.py', plugin_path) init = module_from_spec(spec) spec.loader.exec_module(init) plugin_globals = init.__dict__ if 'LEDGER_IDS' in plugin_globals: PLUGIN_LEDGER_IDS.update(plugin_globals['LEDGER_IDS']) if 'CLIENT_REQUEST_FIELDS' in plugin_globals: PLUGIN_CLIENT_REQUEST_FIELDS.update(plugin_globals['CLIENT_REQUEST_FIELDS']) if 'REQ_OP_TYPES' in plugin_globals: PLUGIN_CLIENT_REQ_OP_TYPES.update(plugin_globals['REQ_OP_TYPES']) # Reloading message types since some some schemas would have been changed import indy_common.types importlib.reload(indy_common.types)
def migrate_nodes_data(): config = getConfigOnce() config_helper = ConfigHelper(config) # Move data old_nodes_data_dir = os.path.join(config_helper.ledger_data_dir, 'nodes') new_node_data_dir = config_helper.ledger_data_dir try: visit_dirs = os.listdir(old_nodes_data_dir) except FileNotFoundError: visit_dirs = [] for node_name in visit_dirs: move_path = os.path.join(old_nodes_data_dir, node_name) to_path = os.path.join(new_node_data_dir, node_name) ext_copytree(move_path, to_path) shutil.rmtree(old_nodes_data_dir) set_own_perm("indy", [new_node_data_dir])