def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugin-path", default=".", help="plugin directory path") arg_parser.add_argument("--ignore-already-installed", action="store_true", help="ignore already installed plugin " "(in dev mode)") arg_parser.add_argument("name", help="plugin name") args = arg_parser.parse_args() manager = PluginsManager() echo_running("- Devlinking plugin %s..." % args.name) try: manager.develop_plugin(args.plugin_path) except AlreadyInstalledPlugin: if args.ignore_already_installed: p = manager.make_plugin(args.plugin_path) if p.is_installed and p.is_dev_linked: echo_warning("(already installed)") sys.exit(0) echo_nok() echo_bold("ERROR: the plugin is already installed") sys.exit(3) except Exception as e: echo_nok() echo_bold(str(e)) sys.exit(2) echo_ok() p = manager.get_plugin(args.name) p.print_dangerous_state()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("name", type=str, help="plugin name") arg_parser.add_argument("--force", help="ignore some errors", action="store_true") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") args = arg_parser.parse_args() name = args.name if inside_a_plugin_env(): print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") sys.exit(1) echo_running("- Uninstalling plugin %s..." % name) try: uninstall_plugin(name, ignore_errors=args.force, plugins_base_dir=args.plugins_base_dir) except MFUtilPluginNotInstalled: echo_nok("not installed") sys.exit(1) except MFUtilPluginCantUninstall as e: echo_nok() print(e) sys.exit(2) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("PLUGIN_PATH", default=".", help="plugin directory path to check") arg_parser.add_argument("--debug", action="store_true", help="add some debug informations in " "case of problems") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") args = arg_parser.parse_args() echo_running("- Checking plugin...") manager = PluginsManager(args.plugins_base_dir) try: plugin = manager.make_plugin(args.PLUGIN_PATH) plugin.load_full() if args.debug: print(get_nice_dump(plugin._get_debug())) except Exception as e: echo_nok() echo_bold(str(e)) if args.debug: print("details of the problem:") raise (e) else: print("(note: use 'plugins.check --debug /plugin/path' " "for more details)") sys.exit(1) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugin-path", default=".", help="plugin directory path") arg_parser.add_argument("--debug", action="store_true", help="add some debug informations in " "case of problems") arg_parser.add_argument("--show-plugin-path", action="store_true", default=False, help="show the generated plugin path") args = arg_parser.parse_args() echo_running("- Building plugin...") manager = PluginsManager() try: plugin = manager.make_plugin(args.plugin_path) path = plugin.build() except Exception as e: echo_nok() print(e) if args.debug: print("details of the problem:") raise(e) else: print("note: use --debug option for more details") else: echo_ok() if args.show_plugin_path: echo_bold("plugin file is ready at %s" % path)
def i_plugin(typ, name, fil): echo_running("- Installing %s plugin: %s..." % (typ, name)) try: os.unlink("%s/config/plugins/%s.ini" % (MFMODULE_RUNTIME_HOME, name)) except Exception: pass try: plugins_manager.install_plugin(fil) except Exception as e: echo_nok() echo_bold("ERROR: %s" % e) else: echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugin-path", default=".", help="plugin directory path") arg_parser.add_argument("name", help="plugin name") args = arg_parser.parse_args() echo_running("- Devlinking plugin %s..." % args.name) try: develop_plugin(args.plugin_path, args.name) except MFUtilPluginAlreadyInstalled: echo_nok("already installed") sys.exit(1) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.parse_args() echo_running("- Creating plugins base...") try: init_plugins_base() except MFUtilPluginCantInit as e: echo_nok() print(e) sys.exit(1) if not is_plugins_base_initialized(): echo_nok() sys.exit(1) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("name", type=str, help="plugin name") args = arg_parser.parse_args() name = args.name echo_running("- Uninstalling plugin %s..." % name) try: uninstall_plugin(name) except MFUtilPluginNotInstalled as e: echo_nok("not installed") sys.exit(1) except MFUtilPluginCantUninstall as e: echo_nok() print(e) sys.exit(2) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("name", type=str, help="plugin name") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") arg_parser.add_argument("--debug", action="store_true", help="add some debug informations in " "case of problems") args = arg_parser.parse_args() name = args.name if inside_a_plugin_env(): print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") sys.exit(1) manager = PluginsManager(plugins_base_dir=args.plugins_base_dir) echo_running("- Repackaging plugin %s..." % name) try: f = io.StringIO() with contextlib.redirect_stderr(f): path = manager.repackage_plugin(name) except NotInstalledPlugin: echo_nok() echo_bold(" => not installed plugin") sys.exit(1) except Exception as e: echo_nok() stderr = f.getvalue() if stderr != '': print(stderr) print(e) if args.debug: print("details of the problem:") raise (e) else: print("note: use --debug option for more details") else: echo_ok() stderr = f.getvalue() if stderr != '': print(stderr) echo_bold("plugin file is ready at %s" % path)
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("name", type=str, help="plugin name") arg_parser.add_argument( "--clean", action="store_true", help="if set, we drop any configuration override " "under ${MODULE_HOME}/config/plugins/ for this " "plugin (warning: delete nothing under /etc/metwork.config.d/" f"{MFMODULE_LOWERCASE}/plugins/)") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") args = arg_parser.parse_args() name = args.name if inside_a_plugin_env(): print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") sys.exit(1) manager = PluginsManager(plugins_base_dir=args.plugins_base_dir) echo_running("- Uninstalling plugin %s..." % name) try: out = io.StringIO() err = io.StringIO() with contextlib.redirect_stdout(out): with contextlib.redirect_stderr(err): manager.uninstall_plugin(name) except NotInstalledPlugin: echo_nok("not installed") sys.exit(1) except Exception as e: echo_nok() print(err.getvalue(), file=sys.stderr) print(out.getvalue()) print(e) sys.exit(2) finally: try: os.unlink(f"{MFMODULE_RUNTIME_HOME}/config/plugins/{name}.ini") except Exception: pass echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugin-path", default=".", help="plugin directory path") arg_parser.add_argument("--show-plugin-path", action="store_true", default=False, help="show the generated plugin path") args = arg_parser.parse_args() echo_running("- Building plugin...") try: path = build_plugin(args.plugin_path) except MFUtilPluginCantBuild as e: echo_nok() print(e) sys.exit(1) echo_ok() if args.show_plugin_path: echo_bold("plugins is ready at %s" % path)
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("name", type=str, help="plugin name") arg_parser.add_argument("--force", help="ignore some errors", action="store_true") args = arg_parser.parse_args() name = args.name echo_running("- Uninstalling plugin %s..." % name) try: uninstall_plugin(name, ignore_errors=args.force) except MFUtilPluginNotInstalled as e: echo_nok("not installed") sys.exit(1) except MFUtilPluginCantUninstall as e: echo_nok() print(e) sys.exit(2) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") args = arg_parser.parse_args() echo_running("- Creating plugins base...") try: init_plugins_base(args.plugins_base_dir) except MFUtilPluginCantInit as e: echo_nok() print(e) sys.exit(1) if not is_plugins_base_initialized(): echo_nok() sys.exit(1) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("plugin_filepath", type=str, help="plugin filepath") arg_parser.add_argument("--force", help="ignore some errors", action="store_true") args = arg_parser.parse_args() echo_running("- Checking plugin file...") infos = get_plugin_info(args.plugin_filepath, mode="file") if not infos: echo_nok() sys.exit(1) echo_ok() name = infos['metadatas']['name'] echo_running("- Installing plugin %s..." % name) try: install_plugin(args.plugin_filepath, ignore_errors=args.force) except MFUtilPluginAlreadyInstalled as e: echo_nok("already installed") sys.exit(1) except MFUtilPluginCantInstall as e: echo_nok() print(e) sys.exit(2) echo_ok()
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("--plugin-path", default=".", help="plugin directory path") arg_parser.add_argument("name", help="plugin name") args = arg_parser.parse_args() if not is_plugins_base_initialized(): echo_bold("ERROR: the module is not initialized") echo_bold(" => start it once before installing your plugin") print() print("hint: you can use %s.start to do that" % MFMODULE_LOWERCASE) print() sys.exit(3) echo_running("- Devlinking plugin %s..." % args.name) try: develop_plugin(args.plugin_path, args.name) except MFUtilPluginAlreadyInstalled: echo_nok("already installed") sys.exit(1) echo_ok() is_dangerous_plugin(args.name)
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("plugin_filepath", type=str, help="plugin filepath") arg_parser.add_argument("--force", help="ignore some errors", action="store_true") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") args = arg_parser.parse_args() if inside_a_plugin_env(): print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") sys.exit(1) if not is_plugins_base_initialized(args.plugins_base_dir): echo_bold("ERROR: the module is not initialized") echo_bold(" => start it once before installing your plugin") print() print("hint: you can use %s.start to do that" % MFMODULE_LOWERCASE) print() sys.exit(3) echo_running("- Checking plugin file...") infos = get_plugin_info(args.plugin_filepath, mode="file", plugins_base_dir=args.plugins_base_dir) if not infos: echo_nok() sys.exit(1) echo_ok() name = infos['metadatas']['name'] echo_running("- Installing plugin %s..." % name) try: install_plugin(args.plugin_filepath, ignore_errors=args.force, plugins_base_dir=args.plugins_base_dir) except MFUtilPluginAlreadyInstalled: echo_nok("already installed") sys.exit(1) except MFUtilPluginCantInstall as e: echo_nok() print(e) sys.exit(2) echo_ok() is_dangerous_plugin(name, plugins_base_dir=args.plugins_base_dir)
def main(): arg_parser = argparse.ArgumentParser(description=DESCRIPTION) arg_parser.add_argument("plugin_filepath", type=str, help="plugin filepath") arg_parser.add_argument("--plugins-base-dir", type=str, default=None, help="can be use to set an alternate " "plugins-base-dir, if not set the value of " "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " "hardcoded standard value).") arg_parser.add_argument("--force", action="store_true", help="if set, automatically uninstall old plugin" "with the same name (if already installed)") arg_parser.add_argument("--new-name", type=str, default=None, help="install the plugin but with a new name " "given by this parameter") args = arg_parser.parse_args() if inside_a_plugin_env(): print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") sys.exit(1) if args.new_name is not None: try: validate_plugin_name(args.new_name) except BadPluginName as e: echo_bold("ERROR: bad plugin name for --new-name option") echo_bold(str(e)) sys.exit(3) manager = PluginsManager(plugins_base_dir=args.plugins_base_dir) echo_running("- Checking plugin file...") try: pf = PluginFile(args.plugin_filepath) pf.load() except BadPluginFile: echo_nok() sys.exit(1) echo_ok() name = pf.name new_name = args.new_name if args.new_name else name try: manager.get_plugin(new_name) if args.force: try: echo_running("- Uninstalling (old) plugin %s..." % new_name) with contextlib.redirect_stdout(open(os.devnull, "w")): with contextlib.redirect_stderr(open(os.devnull, "w")): manager.uninstall_plugin(new_name) echo_ok() except Exception: echo_nok() echo_bold("=> try uninstalling with plugins.uninstall for " "more details") sys.exit(1) except NotInstalledPlugin: pass if args.new_name is not None: echo_running("- Installing plugin %s as %s..." % (name, args.new_name)) else: echo_running("- Installing plugin %s..." % name) try: f = io.StringIO() with contextlib.redirect_stderr(f): manager.install_plugin(args.plugin_filepath, new_name=args.new_name) except AlreadyInstalledPlugin: echo_nok("already installed") sys.exit(1) except Exception as e: echo_nok() stderr = f.getvalue() if stderr != '': print(stderr) echo_bold(str(e)) sys.exit(2) stderr = f.getvalue() if stderr != '': echo_warning() print(stderr) else: echo_ok() p = manager.get_plugin( args.new_name if args.new_name is not None else name) p.print_dangerous_state()
def test_echo_nok(self): with stdout_redirected(to="/dev/null"): echo_nok("foo nok")
def test_echo_nok(self): echo_nok("foo nok")