Logo Search packages:      
Sourcecode: yum version File versions  Download package

def cli::YumBaseCli::getOptionsConfig (   self,
  args 
)

parses command line arguments, takes cli args:
sets up self.conf and self.cmds as well as logger objects 
in base instance

Definition at line 78 of file cli.py.

00078                                     :
        """parses command line arguments, takes cli args:
        sets up self.conf and self.cmds as well as logger objects 
        in base instance"""
        
        # setup our errorlog object 
        self.errorlog = Logger(threshold=2, file_object=sys.stderr)
    
        def repo_optcb(optobj, opt, value, parser):
            '''Callback for the enablerepo and disablerepo option. 
            
            Combines the values given for these options while preserving order
            from command line.
            '''
            dest = eval('parser.values.%s' % optobj.dest)
            dest.append((opt, value))

        self.optparser = YumOptionParser(base=self, usage='''\
yum [options] < update | install | info | remove | list |
    clean | provides | search | check-update | groupinstall | 
    groupupdate | grouplist | groupinfo | groupremove |
    makecache | localinstall | erase | upgrade | whatprovides |
    localupdate | resolvedep | shell | deplist >''')

        self.optparser.add_option("-t", "--tolerant", dest="tolerant",
                action="store_true", default=False, help="be tolerant of errors")
        self.optparser.add_option("-C", "", dest="cacheonly",
                action="store_true", default=False, 
                help="run entirely from cache, don't update cache")
        self.optparser.add_option("-c", "", dest="conffile", action="store", 
                default='/etc/yum.conf', help="config file location", 
                metavar=' [config file]')
        self.optparser.add_option("-R", "", dest="sleeptime", action="store", 
                type='int', default=None, help="maximum command wait time",
                metavar=' [minutes]')
        self.optparser.add_option("-d", "", dest="debuglevel", action="store", 
                default=None, help="debugging output level", type='int',
                metavar=' [debug level]')
        self.optparser.add_option("-e", "", dest="errorlevel", action="store", 
                default=None, help="error output level", type='int',
                metavar=' [error level]')
        self.optparser.add_option("-y", "", dest="assumeyes",
                action="store_true", default=False, 
                help="answer yes for all questions")
        self.optparser.add_option("", "--version", dest="version",
                default=False, action="store_true", 
                help="show Yum version and exit")
        self.optparser.add_option("", "--installroot", dest="installroot",
                action="store", default=None, help="set install root", 
                metavar='[path]')
        self.optparser.add_option("", "--enablerepo", action='callback',
                type='string', callback=repo_optcb, dest='repos', default=[],
                help="enable one or more repositories (wildcards allowed)",
                metavar='[repo]')
        self.optparser.add_option("", "--disablerepo", action='callback',
                type='string', callback=repo_optcb, dest='repos', default=[],
                help="disable one or more repositories (wildcards allowed)",
                metavar='[repo]')
        self.optparser.add_option("", "--exclude", dest="exclude", default=[], 
                action="append", help="exclude package(s) by name or glob",
                metavar='[package]')
        self.optparser.add_option("", "--obsoletes", dest="obsoletes",
                default=False, action="store_true", 
                help="enable obsoletes processing during updates")
        self.optparser.add_option("", "--noplugins", dest="noplugins",
                default=False, action="store_true", 
                help="disable Yum plugins")
        
        # Parse only command line options that affect basic yum setup
        try:
            args = _filtercmdline(
                        ('--noplugins',), 
                        ('-c', '-d', '-e', '--installroot'), 
                        args,
                    )
        except ValueError:
            self.usage()
            sys.exit(1)
        opts = self.optparser.parse_args(args=args)[0]

        try: 
            # If the conf file is inside the  installroot - use that.
            # otherwise look for it in the normal root
            if opts.installroot:
                if os.access(opts.installroot+'/'+opts.conffile, os.R_OK):
                    opts.conffile = opts.installroot+'/'+opts.conffile
                root=opts.installroot
            else:
                root = '/'
                    
            # Parse the configuration file
            try:
                self.doConfigSetup(fn=opts.conffile, root=root)
            except yum.Errors.ConfigError, e:
                self.errorlog(0, _('Config Error: %s') % e)
                sys.exit(1)
                
            # Initialise logger object
            self.log=Logger(threshold=self.conf.getConfigOption('debuglevel'), 
                    file_object=sys.stdout)

            # Setup debug and error levels
            if opts.debuglevel is not None:
                self.log.threshold=opts.debuglevel
                self.conf.setConfigOption('debuglevel', opts.debuglevel)

            if opts.errorlevel is not None:
                self.errorlog.threshold=opts.errorlevel
                self.conf.setConfigOption('errorlevel', opts.errorlevel)

        except ValueError, e:
            self.errorlog(0, _('Options Error: %s') % e)
            self.usage()
            sys.exit(1)

        # Initialise plugins if cmd line and config file say these should be in
        # use (this may add extra command line options)
        if not opts.noplugins and self.conf.plugins:
            self.doPluginSetup(self.optparser)

        # Now parse the command line for real
        (opts, self.cmds) = self.optparser.parse_args()

        # Just print out the version if that's what the user wanted
        if opts.version:
            print yum.__version__
            sys.exit(0)

        # Let the plugins know what happened on the command line
        self.plugins.setCmdLine(opts, self.cmds)

        try:
            # config file is parsed and moving us forward
            # set some things in it.
                
            # who are we:
            self.conf.setConfigOption('uid', os.geteuid())

            # version of yum
            self.conf.setConfigOption('yumversion', yum.__version__)
            
            # syslog-style log
            if self.conf.getConfigOption('uid') == 0:
                logpath = os.path.dirname(self.conf.logfile)
                if not os.path.exists(logpath):
                    try:
                        os.makedirs(logpath, mode=0755)
                    except OSError, e:
                        self.errorlog(0, _('Cannot make directory for logfile %s' % logpath))
                        sys.exit(1)
                try:
                    logfd = os.open(self.conf.logfile, os.O_WRONLY |
                                    os.O_APPEND | os.O_CREAT, 0644)
                except OSError, e:
                    self.errorlog(0, _('Cannot open logfile %s' % self.conf.logfile))
                    sys.exit(1)

                logfile =  os.fdopen(logfd, 'a')
                fcntl.fcntl(logfd, fcntl.F_SETFD)
                self.filelog = Logger(threshold = 10, file_object = logfile, 
                                preprefix = self.printtime)
            else:
                self.filelog = Logger(threshold = 10, file_object = None, 
                                preprefix = self.printtime)
            
            # Handle remaining options
            if opts.assumeyes:
                self.conf.setConfigOption('assumeyes',1)

            if opts.cacheonly:
                self.conf.setConfigOption('cache', 1)

            if opts.sleeptime is not None:
                sleeptime = random.randrange(opts.sleeptime*60)
            else:
                sleeptime = 0

            if opts.obsoletes:
                self.conf.setConfigOption('obsoletes', 1)

            if opts.installroot:
                self.conf.setConfigOption('installroot', opts.installroot)

            for exclude in opts.exclude:
                try:
                    excludelist = self.conf.getConfigOption('exclude')
                    excludelist.append(exclude)
                    self.conf.setConfigOption('exclude', excludelist)
                except yum.Errors.ConfigError, e:
                    self.errorlog(0, _(e))
                    self.usage()
                    sys.exit(1)
               
            # Process repo enables and disables in order
            for opt, repoexp in opts.repos:
                try:
                    if opt == '--enablerepo':
                        self.repos.enableRepo(repoexp)
                    elif opt == '--disablerepo':
                        self.repos.disableRepo(repoexp)
                except yum.Errors.ConfigError, e:
                    self.errorlog(0, _(e))
                    self.usage()
                    sys.exit(1)
                            
        except ValueError, e:
            self.errorlog(0, _('Options Error: %s') % e)
            self.usage()
            sys.exit(1)
         
        # setup the progress bars/callbacks
        self.setupProgessCallbacks()
        
        # save our original args out
        self.args = args
        # save out as a nice command string
        self.cmdstring = 'yum '
        for arg in self.args:
            self.cmdstring += '%s ' % arg

        try:
            self.parseCommands() # before we return check over the base command + args
                                 # make sure they match/make sense
        except CliError:
            sys.exit(1)
    
        # set our caching mode correctly
        
        if self.conf.getConfigOption('uid') != 0:
            self.conf.setConfigOption('cache', 1)
        # run the sleep - if it's unchanged then it won't matter
        time.sleep(sleeptime)


    def parseCommands(self, mycommands=[]):


Generated by  Doxygen 1.6.0   Back to index