Ejemplo n.º 1
0
 def __init__(self):
     cmd.Cmd.__init__(self)
     confighelper.get_config_helper()
     self._init_logger()
     common.ssl_check()
     common.set_plugin_dict(self._get_plugins())
     self._load_plugins(common.get_plugin_dict())
Ejemplo n.º 2
0
 def __init__(self):
     cmd.Cmd.__init__(self)
     confighelper.get_config_helper()
     self._init_logger()
     common.ssl_check()
     common.set_plugin_dict(self._get_plugins())
     self._load_plugins(common.get_plugin_dict())
Ejemplo n.º 3
0
    def get_epilog(cls):
        '''
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        '''
        options = _('\nThe configuration file options which can be set are:\n')

        # query plugins for list of options
        plugins = common.get_plugin_dict()
        for p_name, p_class in plugins.items():
            func = getattr(p_class, 'config_help')
            options = options + func()

        return _('%s\n'
                 'Examples:\n'
                 '- %s user\n'
                 '- %s user my-rhn-username\n'
                 '- %s --unset user\n') % \
                 (options, cls.plugin_name, cls.plugin_name, cls.plugin_name)
Ejemplo n.º 4
0
    def non_interactive_action(self):
        if self._options['global']:
            global_config = True
        else:
            global_config = False

        # check for display mode
        if len(self._args) == 0:
            # TODO: maybe implement __repr__ on confighelper and print that?
            # get list of global config options
            # get list of local config options

            pass

        # get / set config option...
        else:
            # determine section and option.
            items = self._args[0].split('.')
            if len(items) == 1:
                section = 'RHHelp'
                option = items[0]
            else:
                section = items[0]
                option = items[1]

            # get option's owning class
            if section == 'RHHelp':
                opt_class = self.__class__
            else:
                opt_class = common.get_plugin_dict()[section]

            # process command...
            try:
                # handle 'unset' command
                if self._options['unset']:
                    cfg = confighelper.get_config_helper()
                    cfg.remove_option(section, option, global_config)

                # 'password' is a special case: a one-arg set...
                elif option == 'password':
                    self.config_set_password(global_config=global_config)

                # 'proxy_password' is the other special case: a one-arg set...
                elif option == 'proxy_password':
                    self.config_set_proxy_password(global_config=global_config)

                # is this a 'set' or a 'get'?
                # 'gets' have one arg...
                elif len(self._args) == 1:
                    func = getattr(opt_class, 'config_get_' + option)
                    print func()

                #  ... 'sets' will have two args
                elif len(self._args) == 2:
                    func = getattr(opt_class, 'config_set_' + option)
                    func(self._args[1], global_config=global_config)

            except AttributeError:
                msg = _('ERROR: %s is not a valid configuration file option.')\
                    % self._args[0]
                print msg
                logger.log(logging.WARNING, msg)
                raise
            except EmptyValueError, eve:
                print eve
                logger.log(logging.WARNING, eve)
                raise
            except Exception, e:
                logger.log(logging.WARNING, e)
                raise