Ejemplo n.º 1
0
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()
        first = tmp[0]
        if first in ('[', '#'):
            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:
Ejemplo n.º 3
0
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()