def add_plugins(engine_id, plugin_files): """ Adds the collection of plugins to the registered engine. """ engine_registry = cryregistry.load_engines() engine = engine_registry[engine_id] plugins = engine.get('plugins', {}) for plugin_file in plugin_files: plugin = cryplugin.CryPlugin() try: plugin.load(plugin_file) except Exception: print("Unable to read plugin file %s" % (plugin_file)) sys.excepthook(*sys.exc_info()) continue serialized_plugin = {} serialized_plugin['uri'] = plugin_file serialized_plugin['name'] = plugin.name() plugins[plugin.guid()] = serialized_plugin engine['plugins'] = plugins cryregistry.save_engines(engine_registry)
def cmd_remove(args): engine_registry = cryregistry.load_engines() removed = [] for engine_file in args.project_files: engine = cryproject.load(engine_file) engine_id = engine['info']['id'] if engine_id in engine_registry: del engine_registry[engine_id] removed.append(engine_id) if removed: cryregistry.save_engines(engine_registry)
def remove_plugin_by_guid(engine_id, guid): """ Removes the plugin from the registered engine. """ engine_registry = cryregistry.load_engines() engine = engine_registry[engine_id] plugins = engine.get('plugins', {}) del plugins[guid] if not plugins: del engine['plugins'] cryregistry.save_engines(engine_registry)
def clean_engines(): """ Removes all engines that no longer exist """ engine_registry = cryregistry.load_engines() orphaned_engine_ids = [] for engine_id in engine_registry.keys(): engine_file = cryregistry.engine_file(engine_registry, engine_id) if not os.path.exists(engine_file) or not os.path.isfile(engine_file): orphaned_engine_ids.append(engine_id) if orphaned_engine_ids: for orphan_id in orphaned_engine_ids: del engine_registry[orphan_id] cryregistry.save_engines(engine_registry)
def add_engines(*engine_files, silent=False): """ Adds the collection of engines to the registered engines. """ engine_registry = cryregistry.load_engines() # Delete orphaned engines first clean_engines() added = [] for engine_file in engine_files: if os.path.splitext(engine_file)[1] != cryregistry.ENGINE_EXTENSION: continue engine = load_engine_file(engine_file) if not engine: error_engine_json_decode(engine_file, silent) info = engine['info'] engine_id = info['id'] engine_data = {'uri': os.path.abspath(engine_file), 'info': info} prev = engine_registry.setdefault(engine_id, engine_data) if prev is engine_data or prev != engine_data: engine_registry[engine_id] = engine_data added.append(engine_id) if added: return cryregistry.save_engines(engine_registry, register_action=True, silent=silent) return 0
def add_engines(*engine_files): engine_registry = cryregistry.load_engines() added = [] for engine_file in engine_files: if os.path.splitext(engine_file)[1] != cryregistry.ENGINE_EXTENSION: continue engine = cryproject.load(engine_file) info = engine['info'] engine_id = info['id'] engine_data = {'uri': os.path.abspath(engine_file), 'info': info} prev = engine_registry.setdefault(engine_id, engine_data) if prev is engine_data or prev != engine_data: engine_registry[engine_id] = engine_data added.append(engine_id) if added: cryregistry.save_engines(engine_registry)
def cmd_remove(args): """ Removes the engine from the registery-file. """ engine_registry = cryregistry.load_engines() removed = [] for engine_file in args.engine_files: engine = load_engine_file(engine_file) engine_id = engine['info']['id'] if engine_id in engine_registry: del engine_registry[engine_id] removed.append(engine_id) if removed: sys.exit( cryregistry.save_engines(engine_registry, register_action=False, silent=args.silent))