Пример #1
0
    def setUp(self):
        super(PulpClientTests, self).setUp()

        self.config = SafeConfigParser()
        config_filename = os.path.join(DATA_DIR, 'test-override-client.conf')
        self.config = Config(config_filename)

        self.server_mock = mock.Mock()
        self.pulp_connection = PulpConnection('',
                                              server_wrapper=self.server_mock)
        self.bindings = Bindings(self.pulp_connection)

        # Disabling color makes it easier to grep results since the character codes aren't there
        self.recorder = okaara.prompt.Recorder()
        self.prompt = PulpPrompt(enable_color=False,
                                 output=self.recorder,
                                 record_tags=True)

        self.logger = logging.getLogger('pulp')
        self.exception_handler = ExceptionHandler(self.prompt, self.config)

        self.context = ClientContext(self.bindings, self.config, self.logger,
                                     self.prompt, self.exception_handler)

        self.cli = PulpCli(self.context)
        self.context.cli = self.cli
Пример #2
0
 def setUp(self):
     TestCase.setUp(self)
     self.config = SafeConfigParser()
     path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data',
                         'client.conf')
     self.config = Config(path)
     self.server_mock = mock.Mock()
     self.pulp_connection = \
         PulpConnection('', server_wrapper=self.server_mock)
     self.bindings = Bindings(self.pulp_connection)
     self.recorder = okaara.prompt.Recorder()
     self.prompt = PulpPrompt(enable_color=False,
                              output=self.recorder,
                              record_tags=True)
     self.logger = logging.getLogger('pulp')
     self.exception_handler = ExceptionHandler(self.prompt, self.config)
     self.context = ClientContext(self.bindings, self.config, self.logger,
                                  self.prompt, self.exception_handler)
     self.cli = PulpCli(self.context)
     self.context.cli = self.cli
Пример #3
0
def main(config_filenames, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config_filenames: ordered list of files to load configuration from
    @type  config_filenames: list

    @return: exit code suitable to return to the shell launching the client
    """

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option('-u', '--username', dest='username', action='store', default=None,
                      help=_('credentials for the Pulp server; if specified will bypass the stored certificate'))
    parser.add_option('-p', '--password', dest='password', action='store', default=None,
                      help=_('credentials for the Pulp server; must be specified with --username'))
    parser.add_option('--debug', dest='debug', action='store_true', default=False,
                      help=_('enables debug logging'))
    parser.add_option('--config', dest='config', default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map', dest='print_map', action='store_true', default=False,
                      help=_('prints a map of the CLI sections and commands'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config_filenames = [options.config]
    config = _load_configuration(config_filenames)
    logger = _initialize_logging(config, debug=options.debug)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password
    if username and not password:
        prompt_msg = 'Enter password: '******'Login cancelled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(_('The following extensions failed to load: %(f)s' % {'f' : ', '.join(e.failed_packs)}))
        prompt.write(_('More information on the failures can be found in %(l)s' % {'l' : config['logging']['filename']}))
        return os.EX_OSFILE
Пример #4
0
    def setUp(self):
        super(ExtensionLoaderTests, self).setUp()

        self.prompt = PulpPrompt()
        self.cli = PulpCli(self.prompt)
        self.context = ClientContext(None, None, None, self.prompt, None, cli=self.cli)
Пример #5
0
def main(config_filenames):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config_filenames: ordered list of files to load configuration from
    @type  config_filenames: list

    @return: exit code suitable to return to the shell launching the client
    """

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option(
        "-u",
        "--username",
        dest="username",
        action="store",
        default=None,
        help=_("credentials for the Pulp server; if specified will bypass the stored certificate"),
    )
    parser.add_option(
        "-p",
        "--password",
        dest="password",
        action="store",
        default=None,
        help=_("credentials for the Pulp server; must be specified with --username"),
    )
    parser.add_option("--debug", dest="debug", action="store_true", default=False, help=_("enables debug logging"))
    parser.add_option("--config", dest="config", default=None, help=_("absolute path to the configuration file"))
    parser.add_option(
        "--map",
        dest="print_map",
        action="store_true",
        default=False,
        help=_("prints a map of the CLI sections and commands"),
    )

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config_filenames = [options.config]
    config = _load_configuration(config_filenames)
    logger = _initialize_logging(config, debug=options.debug)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = ExceptionHandler(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password
    if username and not password:
        prompt_msg = "Enter password: "******"Login cancelled"))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config["filesystem"]["extensions_dir"]
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config["client"]["role"]
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(_("The following extensions failed to load: %(f)s" % {"f": ", ".join(e.failed_packs)}))
        prompt.write(_("More information on the failures can be found in %(l)s" % {"l": config["logging"]["filename"]}))
        return os.EX_OSFILE
Пример #6
0
def main(config_filenames, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config_filenames: ordered list of files to load configuration from
    @type  config_filenames: list

    @return: exit code suitable to return to the shell launching the client
    """

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option(
        '-u',
        '--username',
        dest='username',
        action='store',
        default=None,
        help=
        _('credentials for the Pulp server; if specified will bypass the stored certificate'
          ))
    parser.add_option(
        '-p',
        '--password',
        dest='password',
        action='store',
        default=None,
        help=_(
            'credentials for the Pulp server; must be specified with --username'
        ))
    parser.add_option('--debug',
                      dest='debug',
                      action='store_true',
                      default=False,
                      help=_('enables debug logging'))
    parser.add_option('--config',
                      dest='config',
                      default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map',
                      dest='print_map',
                      action='store_true',
                      default=False,
                      help=_('prints a map of the CLI sections and commands'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config_filenames = [options.config]
    config = _load_configuration(config_filenames)
    logger = _initialize_logging(config, debug=options.debug)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password
    if username and not password:
        prompt_msg = 'Enter password: '******'Login cancelled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(
            _('The following extensions failed to load: %(f)s' %
              {'f': ', '.join(e.failed_packs)}))
        prompt.write(
            _('More information on the failures can be found in %(l)s' %
              {'l': config['logging']['filename']}))
        return os.EX_OSFILE
Пример #7
0
def main(config, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config: The CLI configuration.
    @type  config: Config

    @return: exit code suitable to return to the shell launching the client
    """
    ensure_user_pulp_dir()

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option('-u', '--username', dest='username', action='store', default=None,
                      help=_('username for the Pulp server; if used will bypass the stored '
                             'certificate and override a username specified in ~/.pulp/admin.conf'))
    parser.add_option('-p', '--password', dest='password', action='store', default=None,
                      help=_('password for the Pulp server; must be used with --username. '
                             'if used will bypass the stored certificate and override a password '
                             'specified in ~/.pulp/admin.conf'))
    parser.add_option('--config', dest='config', default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map', dest='print_map', action='store_true', default=False,
                      help=_('prints a map of the CLI sections and commands'))
    parser.add_option(
        '-v', dest='verbose', action='count',
        help=_('enables verbose output; use twice for increased verbosity with debug information'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config.update(Config(options.config))
    logger = _initialize_logging(verbose=options.verbose)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password

    if not username and not password:
        # Try to get username/password from config if not explicitly set. username and password are
        # not included by default so we need to catch KeyError Exceptions.
        try:
            username = config['auth']['username']
            password = config['auth']['password']
        except KeyError:
            pass

    if username and not password:
        prompt_msg = 'Enter password: '******'Login canceled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password, verbose=options.verbose)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(
            _('The following extensions failed to load: %(f)s' % {'f': ', '.join(e.failed_packs)}))
        prompt.write(_('More information on the failures may be found by using -v option one or '
                       'more times'))
        return os.EX_OSFILE