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("--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 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) 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("- 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 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("--raw", action="store_true", help="raw mode") arg_parser.add_argument("--json", action="store_true", help="json mode " "(not compatible with raw mode)") 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 args.json and args.raw: print("ERROR: json and raw options are mutually exclusives") 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) plugins = get_installed_plugins(plugins_base_dir=args.plugins_base_dir) json_output = [] table_data = [] table_data.append(["Name", "Version", "Release", "Home"]) for plugin in plugins: name = plugin['name'] release = plugin['release'] version = plugin['version'] home = plugin['home'] if args.raw: print("%s~~~%s~~~%s~~~%s" % (name, version, release, home)) elif args.json: json_output.append({ "name": name, "release": release, "version": version, "home": home }) else: table_data.append([name, version, release, home]) if not args.raw and not args.json: t = SingleTable(title="Installed plugins (%i)" % len(plugins), table_data=table_data) print(t.table) elif args.json: print(json.dumps(json_output, indent=4))
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("--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("--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)
continue return True return False if __name__ == '__main__': parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument("PLUGIN_NAME", help="plugin name") args = parser.parse_args() manager = PluginsManager() try: plugin = manager.get_plugin(args.PLUGIN_NAME) except NotInstalledPlugin: echo_bold("ERROR: not installed plugin: " % args.PLUGIN_NAME) sys.exit(1) if plugin.is_dev_linked: sys.exit(0) target = "%s/config/plugins/%s.ini" % (MFMODULE_RUNTIME_HOME, args.PLUGIN_NAME) if os.path.exists(target): if not has_an_interesting_line(target): # There is a configuration file but nothing has been changed # so we can unlink it! try: os.unlink(target) except Exception as e:
def test_echo_bold(self): echo_bold("foo bold")
continue return True return False if __name__ == '__main__': parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument("PLUGIN_NAME", help="plugin name") args = parser.parse_args() manager = PluginsManager() try: plugin = manager.get_plugin(args.PLUGIN_NAME) except NotInstalledPlugin: echo_bold("ERROR: not installed plugin: " % args.PLUGIN_NAME) sys.exit(1) if plugin.is_dev_linked: sys.exit(0) conf_file = "%s/config.ini" % plugin.home try: with open(conf_file, "r") as f: lines = f.readlines() except Exception as e: echo_bold("ERROR: can't read %s, exception: %s" % (conf_file, e)) sys.exit(1) mkdir_p_or_die("%s/config/plugins" % MFMODULE_RUNTIME_HOME) target = "%s/config/plugins/%s.ini" % (MFMODULE_RUNTIME_HOME,
def test_echo_bold(self): with stdout_redirected(to="/dev/null"): echo_bold("foo bold")
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()