Ejemplo n.º 1
0
def build_arg_parser():
    description_msg = "Grouper Background"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s %s" % __version__,
        help="Display version information.",
    )
    return parser
Ejemplo n.º 2
0
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
    ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths,
                           "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Ejemplo n.º 3
0
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
    ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args)
    logging.basicConfig(level=log_level, format=settings.log_format)

    if settings.plugin_dir:
        load_plugins(settings.plugin_dir,
                     settings.plugin_module_paths,
                     service_name="grouper-ctl")

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Ejemplo n.º 4
0
def build_arg_parser(description):
    # type(str) -> ArgumentParser

    parser = ArgumentParser(description=description)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s {}".format(__version__),
        help="Display version information.",
    )
    parser.add_argument("-a",
                        "--address",
                        type=str,
                        default=None,
                        help="Override address in config.")
    parser.add_argument("-p",
                        "--port",
                        type=int,
                        default=None,
                        help="Override port in config.")
    parser.add_argument("-n",
                        "--deployment-name",
                        type=str,
                        default="",
                        help="Name of the deployment.")
    parser.add_argument("-d",
                        "--database-url",
                        type=str,
                        default=None,
                        help="Override database URL in config.")
    parser.add_argument(
        "--listen-stdin",
        action="store_true",
        help="Ignore address and port and expect connections on standard input",
    )

    return parser
Ejemplo n.º 5
0
def build_arg_parser():
    description_msg = "Grouper Background"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c", "--config", default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v", "--verbose", action="count", default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q", "--quiet", action="count", default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V", "--version", action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")
    return parser
Ejemplo n.º 6
0
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c", "--config", default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v", "--verbose", action="count", default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q", "--quiet", action="count", default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V", "--version", action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
            ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths, "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Ejemplo n.º 7
0
Archivo: main.py Proyecto: rra/grouper
def main(sys_argv=sys.argv, start_config_thread=True):
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c", "--config", default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v", "--verbose", action="count", default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q", "--quiet", action="count", default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V", "--version", action="version",
                        version="%%(prog)s %s" % __version__,
                        help="Display version information.")

    subparsers = parser.add_subparsers(dest="command")

    for subcommand_module in [
            group,
            oneoff,
            shell,
            sync_db,
            user,
            user_proxy,
            ]:
        subcommand_module.add_parser(subparsers)

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args)
    logging.basicConfig(level=log_level, format=settings.log_format)

    if settings["plugin_dir"]:
        load_plugins(settings["plugin_dir"], service_name="grouper-ctl")

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    args.func(args)
Ejemplo n.º 8
0
def build_arg_parser(description):
    # type(str) -> ArgumentParser

    parser = ArgumentParser(description=description)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%%(prog)s {}".format(__version__),
                        help="Display version information.")
    parser.add_argument("-a",
                        "--address",
                        type=str,
                        default=None,
                        help="Override address in config.")
    parser.add_argument("-p",
                        "--port",
                        type=int,
                        default=None,
                        help="Override port in config.")
    parser.add_argument("-n",
                        "--deployment-name",
                        type=str,
                        default="",
                        help="Name of the deployment.")

    return parser
Ejemplo n.º 9
0
def build_arg_parser(description):
    # type(str) -> ArgumentParser

    parser = ArgumentParser(description=description)

    parser.add_argument(
        "-c", "--config", default=default_settings_path(), help="Path to config file."
    )
    parser.add_argument(
        "-v", "--verbose", action="count", default=0, help="Increase logging verbosity."
    )
    parser.add_argument(
        "-q", "--quiet", action="count", default=0, help="Decrease logging verbosity."
    )
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s {}".format(__version__),
        help="Display version information.",
    )
    parser.add_argument(
        "-a", "--address", type=str, default=None, help="Override address in config."
    )
    parser.add_argument("-p", "--port", type=int, default=None, help="Override port in config.")
    parser.add_argument(
        "-n", "--deployment-name", type=str, default="", help="Name of the deployment."
    )
    parser.add_argument(
        "-d", "--database-url", type=str, default=None, help="Override database URL in config."
    )
    parser.add_argument(
        "--listen-stdin",
        action="store_true",
        help="Ignore address and port and expect connections on standard input",
    )

    return parser
Ejemplo n.º 10
0
def main(sys_argv=sys.argv, start_config_thread=True, session=None):
    # type: (List[str], bool, Optional[Session]) -> None
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s %s" % __version__,
        help="Display version information.",
    )

    subparsers = parser.add_subparsers(dest="command")
    CtlCommandFactory.add_all_parsers(subparsers)

    # Add parsers for legacy commands that have not been refactored.
    for subcommand_module in [
            dump_sql,
            group,
            oneoff,
            service_account,
            shell,
            sync_db,
            user_proxy,
    ]:
        subcommand_module.add_parser(subparsers)  # type: ignore

    args = parser.parse_args(sys_argv[1:])

    if start_config_thread:
        settings.update_from_config(args.config)
        settings.start_config_thread(args.config)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    try:
        initialize_plugins(settings.plugin_dirs, settings.plugin_module_paths,
                           "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    usecase_factory = create_sql_usecase_factory(settings, session)
    command_factory = CtlCommandFactory(usecase_factory)

    # Old-style subcommands store a func in callable when setting up their arguments.  New-style
    # subcommands are handled via a factory that constructs and calls the correct object.
    if getattr(args, "func", None):
        args.func(args)
    else:
        command = command_factory.construct_command(args.command)
        command.run(args)
Ejemplo n.º 11
0
def main(sys_argv=sys.argv, session=None):
    # type: (List[str], Optional[Session]) -> None
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument(
        "-c", "--config", default=default_settings_path(), help="Path to config file."
    )
    parser.add_argument(
        "-d", "--database-url", type=str, default=None, help="Override database URL in config."
    )
    parser.add_argument(
        "-q", "--quiet", action="count", default=0, help="Decrease logging verbosity."
    )
    parser.add_argument(
        "-v", "--verbose", action="count", default=0, help="Increase logging verbosity."
    )
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s %s" % __version__,
        help="Display version information.",
    )

    subparsers = parser.add_subparsers(dest="command")
    CtlCommandFactory.add_all_parsers(subparsers)

    # Add parsers for legacy commands that have not been refactored.
    for subcommand_module in [group, oneoff, service_account, shell]:
        subcommand_module.add_parser(subparsers)  # type: ignore

    args = parser.parse_args(sys_argv[1:])

    # Construct the CtlSettings object used for all commands, and set it as the global Settings
    # object.  All code in grouper.ctl.* takes the CtlSettings object as an argument if needed, but
    # it may call other legacy code that requires the global Settings object be present.
    settings = CtlSettings.global_settings_from_config(args.config)
    if args.database_url:
        settings.database = args.database_url

    # Construct a session factory, which is passed into all the legacy commands that haven't been
    # converted to usecases yet.
    if session:
        session_factory = SingletonSessionFactory(session)  # type: SessionFactory
    else:
        session_factory = SessionFactory(settings)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    # Initialize plugins.  The global plugin proxy is used by legacy code.
    try:
        plugins = PluginProxy.load_plugins(settings, "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)
    set_global_plugin_proxy(plugins)

    # Set up factories.
    usecase_factory = create_sql_usecase_factory(settings, plugins, session_factory)
    command_factory = CtlCommandFactory(settings, usecase_factory)

    # Old-style subcommands store a func in callable when setting up their arguments.  New-style
    # subcommands are handled via a factory that constructs and calls the correct object.
    if getattr(args, "func", None):
        args.func(args, settings, session_factory)
    else:
        command = command_factory.construct_command(args.command)
        command.run(args)
Ejemplo n.º 12
0
def main(sys_argv=sys.argv, session=None):
    # type: (List[str], Optional[Session]) -> None
    description_msg = "Grouper Control"
    parser = argparse.ArgumentParser(description=description_msg)

    parser.add_argument("-c",
                        "--config",
                        default=default_settings_path(),
                        help="Path to config file.")
    parser.add_argument("-d",
                        "--database-url",
                        type=str,
                        default=None,
                        help="Override database URL in config.")
    parser.add_argument("-q",
                        "--quiet",
                        action="count",
                        default=0,
                        help="Decrease logging verbosity.")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="Increase logging verbosity.")
    parser.add_argument(
        "-V",
        "--version",
        action="version",
        version="%%(prog)s %s" % __version__,
        help="Display version information.",
    )

    subparsers = parser.add_subparsers(dest="command")
    CtlCommandFactory.add_all_parsers(subparsers)

    # Add parsers for legacy commands that have not been refactored.
    for subcommand_module in [group, oneoff, service_account, shell]:
        subcommand_module.add_parser(subparsers)  # type: ignore

    args = parser.parse_args(sys_argv[1:])

    # Construct the CtlSettings object used for all commands, and set it as the global Settings
    # object.  All code in grouper.ctl.* takes the CtlSettings object as an argument if needed, but
    # it may call other legacy code that requires the global Settings object be present.
    settings = CtlSettings.global_settings_from_config(args.config)
    if args.database_url:
        settings.database = args.database_url

    # Construct a session factory, which is passed into all the legacy commands that haven't been
    # converted to usecases yet.
    if session:
        session_factory = SingletonSessionFactory(
            session)  # type: SessionFactory
    else:
        session_factory = SessionFactory(settings)

    log_level = get_loglevel(args, base=logging.INFO)
    logging.basicConfig(level=log_level, format=settings.log_format)

    if log_level < 0:
        sa_log.setLevel(logging.INFO)

    # Initialize plugins.  The global plugin proxy is used by legacy code.
    try:
        plugins = PluginProxy.load_plugins(settings, "grouper-ctl")
    except PluginsDirectoryDoesNotExist as e:
        logging.fatal("Plugin directory does not exist: {}".format(e))
        sys.exit(1)
    set_global_plugin_proxy(plugins)

    # Set up factories.
    usecase_factory = create_sql_usecase_factory(settings, plugins,
                                                 session_factory)
    command_factory = CtlCommandFactory(settings, usecase_factory)

    # Old-style subcommands store a func in callable when setting up their arguments.  New-style
    # subcommands are handled via a factory that constructs and calls the correct object.
    if getattr(args, "func", None):
        args.func(args, settings, session_factory)
    else:
        command = command_factory.construct_command(args.command)
        command.run(args)