Changeset 516 for yum/trunk/cli.py


Ignore:
Timestamp:
Feb 3, 2015, 9:39:54 AM (11 years ago)
Author:
Yuri Dario
Message:

yum: update trunk to 3.4.3.

Location:
yum/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • yum/trunk

  • yum/trunk/cli.py

    r19 r516  
    3939import yum.plugins
    4040from rpmUtils.arch import isMultiLibArch
    41 from yum import _
     41from yum import _, P_
    4242from yum.rpmtrans import RPMTransaction
    4343import signal
     
    4545
    4646from yum.i18n import to_unicode, to_utf8
     47
     48#  This is for yum-utils/yumdownloader in RHEL-5, where it isn't importing this
     49# directly but did do "from cli import *", and we did have this in 3.2.22. I
     50# just _love_ how python re-exports these by default.
     51from yum.packages import parsePackages
    4752
    4853def sigquit(signum, frame):
     
    7479        self.verbose_logger = logging.getLogger("yum.verbose.cli")
    7580        self.yum_cli_commands = {}
     81        self.use_txmbr_in_callback = True
    7682        self.registerCommand(yumcommands.InstallCommand())
    7783        self.registerCommand(yumcommands.UpdateCommand())
     
    7985        self.registerCommand(yumcommands.ListCommand())
    8086        self.registerCommand(yumcommands.EraseCommand())
    81         self.registerCommand(yumcommands.GroupCommand())
    82         self.registerCommand(yumcommands.GroupListCommand())
    83         self.registerCommand(yumcommands.GroupInstallCommand())
    84         self.registerCommand(yumcommands.GroupRemoveCommand())
    85         self.registerCommand(yumcommands.GroupInfoCommand())
     87        self.registerCommand(yumcommands.GroupsCommand())
    8688        self.registerCommand(yumcommands.MakeCacheCommand())
    8789        self.registerCommand(yumcommands.CleanCommand())
     
    101103        self.registerCommand(yumcommands.HistoryCommand())
    102104        self.registerCommand(yumcommands.CheckRpmdbCommand())
     105        self.registerCommand(yumcommands.DistroSyncCommand())
     106        self.registerCommand(yumcommands.LoadTransactionCommand())
    103107
    104108    def registerCommand(self, command):
     
    139143        """
    140144        usage = 'yum [options] COMMAND\n\nList of Commands:\n\n'
    141         commands = yum.misc.unique(self.yum_cli_commands.values())
     145        commands = yum.misc.unique([x for x in self.yum_cli_commands.values()
     146                                    if not (hasattr(x, 'hidden') and x.hidden)])
    142147        commands.sort(key=lambda x: x.getNames()[0])
    143148        for command in commands:
     
    150155
    151156        return usage
    152 
     157   
     158    def _parseSetOpts(self, setopts):
     159        """parse the setopts list handed to us and saves the results as
     160           repo_setopts and main_setopts in the yumbase object"""
     161
     162        repoopts = {}
     163        mainopts = yum.misc.GenericHolder()
     164        mainopts.items = []
     165
     166        for item in setopts:
     167            k,v = item.split('=')
     168            period = k.find('.')
     169            if period != -1:
     170                repo = k[:period]
     171                k = k[period+1:]
     172                if repo not in repoopts:
     173                    repoopts[repo] = yum.misc.GenericHolder()
     174                    repoopts[repo].items = []
     175                setattr(repoopts[repo], k, v)
     176                repoopts[repo].items.append(k)
     177            else:
     178                setattr(mainopts, k, v)
     179                mainopts.items.append(k)
     180       
     181        self.main_setopts = mainopts
     182        self.repo_setopts = repoopts
     183       
     184       
    153185    def getOptionsConfig(self, args):
    154186        """parses command line arguments, takes cli args:
     
    167199            opts.verbose = False
    168200
     201        # go through all the setopts and set the global ones
     202        self._parseSetOpts(opts.setopts)
     203       
     204        if self.main_setopts:
     205            for opt in self.main_setopts.items:
     206                setattr(opts, opt, getattr(self.main_setopts, opt))
     207           
    169208        # get the install root to use
    170209        root = self.optparser.getRoot(opts)
     
    190229            pc.releasever = opts.releasever
    191230            self.conf
    192                    
     231           
     232            # now set  all the non-first-start opts from main from our setopts
     233            if self.main_setopts:
     234                for opt in self.main_setopts.items:
     235                    if not hasattr(self.conf, opt):
     236                        msg ="Main config did not have a %s attr. before setopt"
     237                        self.logger.warning(msg % opt)
     238                    setattr(self.conf, opt, getattr(self.main_setopts, opt))
     239
    193240        except yum.Errors.ConfigError, e:
    194241            self.logger.critical(_('Config Error: %s'), e)
     
    205252        # apply some of the options to self.conf
    206253        (opts, self.cmds) = self.optparser.setupYumConfig(args=args)
     254
     255        if opts.version:
     256            opts.quiet = True
     257            opts.verbose = False
     258
     259        #  Check that firstParse didn't miss anything, and warn the user if it
     260        # did ... because this is really magic, and unexpected.
     261        if opts.quiet:
     262            opts.debuglevel = 0
     263        if opts.verbose:
     264            opts.debuglevel = opts.errorlevel = 6
     265        if opts.debuglevel != pc.debuglevel or opts.errorlevel != pc.errorlevel:
     266            self.logger.warning("Ignored option -q, -v, -d or -e (probably due to merging: -yq != -y -q)")
     267        #  getRoot() changes it, but then setupYumConfig() changes it back. So
     268        # don't test for this, if we are using --installroot.
     269        if root == '/' and opts.conffile != pc.fn:
     270            self.logger.warning("Ignored option -c (probably due to merging -yc != -y -c)")
    207271
    208272        if opts.version:
     
    288352        self.yum_cli_commands[self.basecmd].doCheck(self, self.basecmd, self.extcmds)
    289353
     354    def _shell_history_write(self):
     355        if not hasattr(self, '_shell_history_cmds'):
     356            return
     357        if not self._shell_history_cmds:
     358            return
     359
     360        data = self._shell_history_cmds
     361        # Turn: [["a", "b"], ["c", "d"]] => "a b\nc d\n"
     362        data = [" ".join(cmds) for cmds in data]
     363        data.append('')
     364        data = "\n".join(data)
     365        self.history.write_addon_data('shell-cmds', data)
     366
    290367    def doShell(self):
    291368        """do a shell-like interface for yum commands"""
    292369
    293370        yumshell = shell.YumShell(base=self)
     371
     372        # We share this array...
     373        self._shell_history_cmds = yumshell._shell_history_cmds
     374
    294375        if len(self.extcmds) == 0:
    295376            yumshell.cmdloop()
    296377        else:
    297378            yumshell.script()
     379
     380        del self._shell_history_cmds
     381
    298382        return yumshell.result, yumshell.resultmsgs
    299383
     
    306390        disk = {}
    307391        for m in p.finditer(errstring):
    308             if not disk.has_key(m.group(2)):
     392            if m.group(2) not in disk:
    309393                disk[m.group(2)] = int(m.group(1))
    310394            if disk[m.group(2)] < int(m.group(1)):
     
    314398            summary += _('Disk Requirements:\n')
    315399            for k in disk:
    316                 summary += _('  At least %dMB more space needed on the %s filesystem.\n') % (disk[k], k)
     400                summary += P_('  At least %dMB more space needed on the %s filesystem.\n', '  At least %dMB more space needed on the %s filesystem.\n', disk[k]) % (disk[k], k)
    317401
    318402        # TODO: simplify the dependency errors?
     
    363447        if len(self.tsInfo) == 0:
    364448            self.verbose_logger.info(_('Trying to run the transaction but nothing to do. Exiting.'))
    365             return 1
     449            return -1
    366450
    367451        # NOTE: In theory we can skip this in -q -y mode, for a slight perf.
     
    377461        # Check which packages have to be downloaded
    378462        downloadpkgs = []
     463        rmpkgs = []
    379464        stuff_to_download = False
    380465        install_only = True
     466        remove_only  = True
    381467        for txmbr in self.tsInfo.getMembers():
    382468            if txmbr.ts_state not in ('i', 'u'):
    383469                install_only = False
     470                po = txmbr.po
     471                if po:
     472                    rmpkgs.append(po)
    384473            else:
     474                remove_only = False
    385475                stuff_to_download = True
    386476                po = txmbr.po
     
    395485        # Report the total download size to the user, so he/she can base
    396486        # the answer on this info
    397         if stuff_to_download:
     487        if not stuff_to_download:
     488            self.reportRemoveSize(rmpkgs)
     489        else:
    398490            self.reportDownloadSize(downloadpkgs, install_only)
    399491       
     
    402494            if not self.userconfirm():
    403495                self.verbose_logger.info(_('Exiting on user Command'))
    404                 return 1
     496                return -1
    405497
    406498        self.verbose_logger.log(yum.logginglevels.INFO_2,
     
    419511        # Check GPG signatures
    420512        if self.gpgsigcheck(downloadpkgs) != 0:
    421             return 1
    422        
    423         if self.conf.rpm_check_debug:
    424             rcd_st = time.time()
    425             self.verbose_logger.log(yum.logginglevels.INFO_2,
    426                  _('Running rpm_check_debug'))
    427             msgs = self._run_rpm_check_debug()
    428             if msgs:
    429                 rpmlib_only = True
    430                 for msg in msgs:
    431                     if msg.startswith('rpmlib('):
    432                         continue
    433                     rpmlib_only = False
    434                 if rpmlib_only:
    435                     print _("ERROR You need to update rpm to handle:")
    436                 else:
    437                     print _('ERROR with rpm_check_debug vs depsolve:')
    438 
    439                 for msg in msgs:
    440                     print to_utf8(msg)
    441 
    442                 if rpmlib_only:
    443                     return 1, [_('RPM needs to be updated')]
    444                 return 1, [_('Please report this error in %s') % self.conf.bugtracker_url]
    445 
    446             self.verbose_logger.debug('rpm_check_debug time: %0.3f' % (time.time() - rcd_st))
     513            return -1
     514       
     515        self.initActionTs()
     516        # save our dsCallback out
     517        dscb = self.dsCallback
     518        self.dsCallback = None # dumb, dumb dumb dumb!
     519        self.populateTs(keepold=0) # sigh
     520
     521        rcd_st = time.time()
     522        self.verbose_logger.log(yum.logginglevels.INFO_2,
     523             _('Running Transaction Check'))
     524        msgs = self._run_rpm_check()
     525        if msgs:
     526            rpmlib_only = True
     527            for msg in msgs:
     528                if msg.startswith('rpmlib('):
     529                    continue
     530                rpmlib_only = False
     531            if rpmlib_only:
     532                print _("ERROR You need to update rpm to handle:")
     533            else:
     534                print _('ERROR with transaction check vs depsolve:')
     535
     536            for msg in msgs:
     537                print to_utf8(msg)
     538
     539            if rpmlib_only:
     540                return 1, [_('RPM needs to be updated')]
     541            return 1, [_('Please report this error in %s') % self.conf.bugtracker_url]
     542
     543        self.verbose_logger.debug('Transaction Check time: %0.3f' % (time.time() - rcd_st))
    447544
    448545        tt_st = time.time()           
     
    452549            self.tsInfo.probFilterFlags.append(rpm.RPMPROB_FILTER_DISKSPACE)
    453550           
     551        self.ts.order() # order the transaction
     552        self.ts.clean() # release memory not needed beyond this point
    454553       
    455554        testcb = RPMTransaction(self, test=True)
    456        
    457         self.initActionTs()
    458         # save our dsCallback out
    459         dscb = self.dsCallback
    460         self.dsCallback = None # dumb, dumb dumb dumb!
    461         self.populateTs(keepold=0) # sigh
    462555        tserrors = self.ts.test(testcb)
    463556        del testcb
     
    472565        self.verbose_logger.log(yum.logginglevels.INFO_2,
    473566             _('Transaction Test Succeeded'))
    474         del self.ts
    475567       
    476568        self.verbose_logger.debug('Transaction Test time: %0.3f' % (time.time() - tt_st))
     
    480572       
    481573        ts_st = time.time()
    482         self.initActionTs() # make a new, blank ts to populate
    483         self.populateTs(keepold=0) # populate the ts
    484         self.ts.check() #required for ordering
    485         self.ts.order() # order
     574
     575        #  Reinstalls broke in: 7115478c527415cb3c8317456cdf50024de89a94 ...
     576        # I assume there's a "better" fix, but this fixes reinstalls and lets
     577        # other options continue as is (and they seem to work).
     578        have_reinstalls = False
     579        for txmbr in self.tsInfo.getMembers():
     580            if txmbr.reinstall:
     581                have_reinstalls = True
     582                break
     583        if have_reinstalls:
     584            self.initActionTs() # make a new, blank ts to populate
     585            self.populateTs(keepold=0) # populate the ts
     586            self.ts.check() #required for ordering
     587            self.ts.order() # order
     588            self.ts.clean() # release memory not needed beyond this point
    486589
    487590        # put back our depcheck callback
     
    544647            msg = self.fmtKeyValFill(_('  * Maybe you meant: '),
    545648                                     ", ".join(matches))
    546             self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
    547 
    548     def _checkMaybeYouMeant(self, arg, always_output=True):
     649            self.verbose_logger.log(yum.logginglevels.INFO_2, to_unicode(msg))
     650
     651    def _checkMaybeYouMeant(self, arg, always_output=True, rpmdb_only=False):
    549652        """ If the update/remove argument doesn't match with case, or due
    550653            to not being installed, tell the user. """
    551654        # always_output is a wart due to update/remove not producing the
    552655        # same output.
    553         matches = self.doPackageLists(patterns=[arg], ignore_case=False)
     656        # if it is a grouppattern then none of this is going to make any sense
     657        # skip it.
     658        if not arg or arg[0] == '@':
     659            return
     660       
     661        pkgnarrow='all'
     662        if rpmdb_only:
     663            pkgnarrow='installed'
     664       
     665        matches = self.doPackageLists(pkgnarrow=pkgnarrow, patterns=[arg], ignore_case=False)
    554666        if (matches.installed or (not matches.available and
    555667                                  self.returnInstalledPackagesByDep(arg))):
     
    564676
    565677        # No package name, so do the maybeYouMeant thing here too
    566         matches = self.doPackageLists(patterns=[arg], ignore_case=True)
     678        matches = self.doPackageLists(pkgnarrow=pkgnarrow, patterns=[arg], ignore_case=True)
    567679        if not matches.installed and matches.available:
    568680            self.verbose_logger.log(yum.logginglevels.INFO_2,
     
    595707        oldcount = len(self.tsInfo)
    596708       
     709        done = False
    597710        for arg in userlist:
    598711            if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
     
    609722                                        self.term.MODE['normal'])
    610723                self._maybeYouMeant(arg)
     724            else:
     725                done = True
    611726        if len(self.tsInfo) > oldcount:
    612             return 2, [_('Package(s) to install')]
     727            change = len(self.tsInfo) - oldcount
     728            return 2, [P_('%d package to install', '%d packages to install', change) % change]
     729
     730        if not done:
     731            return 1, [_('Nothing to do')]
    613732        return 0, [_('Nothing to do')]
    614733       
    615     def updatePkgs(self, userlist, quiet=0):
     734    def updatePkgs(self, userlist, quiet=0, update_to=False):
    616735        """take user commands and populate transaction wrapper with
    617736           packages to be updated"""
     
    640759               
    641760            for arg in userlist:
    642                 if not self.update(pattern=arg):
     761                if not self.update(pattern=arg, update_to=update_to):
    643762                    self._checkMaybeYouMeant(arg)
    644763
    645764        if len(self.tsInfo) > oldcount:
    646765            change = len(self.tsInfo) - oldcount
    647             msg = _('%d packages marked for Update') % change
    648             return 2, [msg]
     766            return 2, [P_('%d package marked for Update', '%d packages marked for Update', change) % change]
    649767        else:
    650768            return 0, [_('No Packages marked for Update')]
     769
     770    #  Note that we aren't in __init__ yet for a couple of reasons, but we
     771    # probably will get there for 3.2.28.
     772    def distroSyncPkgs(self, userlist):
     773        """ This does either upgrade/downgrade, depending on if the latest
     774            installed version is older or newer. We allow "selection" but not
     775            local packages (use tmprepo, or something). """
     776
     777        level = 'diff'
     778        if userlist and userlist[0] in ('full', 'diff', 'different'):
     779            level = userlist[0]
     780            userlist = userlist[1:]
     781            if level == 'different':
     782                level = 'diff'
     783
     784        dupdates = []
     785        ipkgs = {}
     786        for pkg in sorted(self.rpmdb.returnPackages(patterns=userlist)):
     787            ipkgs[pkg.name] = pkg
     788
     789        obsoletes = []
     790        if self.conf.obsoletes:
     791            obsoletes = self.up.getObsoletesTuples(newest=1)
     792
     793        for (obsoleting, installed) in obsoletes:
     794            if installed[0] not in ipkgs:
     795                continue
     796            dupdates.extend(self.update(pkgtup=installed))
     797        for (obsoleting, installed) in obsoletes:
     798            if installed[0] not in ipkgs:
     799                continue
     800            del ipkgs[installed[0]]
     801
     802        apkgs = {}
     803        pkgs = []
     804        if ipkgs:
     805            try:
     806                pkgs = self.pkgSack.returnNewestByName(patterns=ipkgs.keys())
     807            except yum.Errors.PackageSackError:
     808                pkgs = []
     809
     810        for pkg in pkgs:
     811            if pkg.name not in ipkgs:
     812                continue
     813            apkgs[pkg.name] = pkg
     814
     815        for ipkgname in ipkgs:
     816            if ipkgname not in apkgs:
     817                continue
     818
     819            ipkg = ipkgs[ipkgname]
     820            apkg = apkgs[ipkgname]
     821            if ipkg.verEQ(apkg): # Latest installed == Latest avail.
     822                if level == 'diff':
     823                    continue
     824
     825                # level == full: do reinstalls if checksum doesn't match.
     826                #                do removals, if older installed versions.
     827                for napkg in self.rpmdb.searchNames([ipkgname]):
     828                    if (not self.allowedMultipleInstalls(apkg) and
     829                        not napkg.verEQ(ipkg)):
     830                        dupdates.extend(self.remove(po=napkg))
     831                        continue
     832
     833                    nayi = napkg.yumdb_info
     834                    for apkg in self.pkgSack.searchPkgTuple(napkg.pkgtup):
     835                        if ('checksum_type' in nayi and
     836                            'checksum_data' in nayi and
     837                            nayi.checksum_type == apkg.checksum_type and
     838                            nayi.checksum_data == apkg.pkgId):
     839                            found = True
     840                            break
     841                    if found:
     842                        continue
     843                    dupdates.extend(self.reinstall(pkgtup=napkg.pkgtup))
     844                continue
     845
     846            if self.allowedMultipleInstalls(apkg):
     847                found = False
     848                for napkg in self.rpmdb.searchNames([apkg.name]):
     849                    if napkg.verEQ(apkg):
     850                        found = True
     851                    elif napkg.verGT(apkg):
     852                        dupdates.extend(self.remove(po=napkg))
     853                if found:
     854                    continue
     855                dupdates.extend(self.install(pattern=apkg.name))
     856            elif ipkg.verLT(apkg):
     857                n,a,e,v,r = apkg.pkgtup
     858                dupdates.extend(self.update(name=n, epoch=e, ver=v, rel=r))
     859            else:
     860                n,a,e,v,r = apkg.pkgtup
     861                dupdates.extend(self.downgrade(name=n, epoch=e, ver=v, rel=r))
     862
     863        if dupdates:
     864            return 2, [P_('%d package marked for Distribution Synchronization', '%d packages marked for Distribution Synchronization', len(dupdates)) % len(dupdates)]
     865        else:
     866            return 0, [_('No Packages marked for Distribution Synchronization')]
    651867
    652868    def erasePkgs(self, userlist):
     
    655871       
    656872        oldcount = len(self.tsInfo)
    657        
     873
     874        all_rms = []
    658875        for arg in userlist:
    659             if not self.remove(pattern=arg):
    660                 self._checkMaybeYouMeant(arg, always_output=False)
    661        
    662         if len(self.tsInfo) > oldcount:
    663             change = len(self.tsInfo) - oldcount
    664             msg = _('%d packages marked for removal') % change
    665             return 2, [msg]
     876            rms = self.remove(pattern=arg)
     877            if not rms:
     878                self._checkMaybeYouMeant(arg, always_output=False, rpmdb_only=True)
     879            all_rms.extend(rms)
     880       
     881        if all_rms:
     882            return 2, [P_('%d package marked for removal', '%d packages marked for removal', len(all_rms)) % len(all_rms)]
    666883        else:
    667884            return 0, [_('No Packages marked for removal')]
     
    690907                self._maybeYouMeant(arg)
    691908        if len(self.tsInfo) > oldcount:
    692             return 2, [_('Package(s) to downgrade')]
     909            change = len(self.tsInfo) - oldcount
     910            return 2, [P_('%d package to downgrade', '%d packages to downgrade', change) % change]
    693911        return 0, [_('Nothing to do')]
    694912       
     
    711929                self._checkMaybeYouMeant(arg, always_output=False)
    712930            except yum.Errors.ReinstallInstallError, e:
    713                 ipkg = self.rpmdb.returnPackages(patterns=[arg])[0]
    714                 xmsg = ''
    715                 if 'from_repo' in ipkg.yumdb_info:
    716                     xmsg = ipkg.yumdb_info.from_repo
    717                     xmsg = _(' (from %s)') % xmsg
    718                 self.verbose_logger.log(yum.logginglevels.INFO_2,
    719                                         _('Installed package %s%s%s%s not available.'),
    720                                         self.term.MODE['bold'], ipkg,
    721                                         self.term.MODE['normal'], xmsg)
     931                for ipkg in e.failed_pkgs:
     932                    xmsg = ''
     933                    if 'from_repo' in ipkg.yumdb_info:
     934                        xmsg = ipkg.yumdb_info.from_repo
     935                        xmsg = _(' (from %s)') % xmsg
     936                    msg = _('Installed package %s%s%s%s not available.')
     937                    self.verbose_logger.log(yum.logginglevels.INFO_2, msg,
     938                                            self.term.MODE['bold'], ipkg,
     939                                            self.term.MODE['normal'], xmsg)
    722940            except yum.Errors.ReinstallError, e:
    723941                assert False, "Shouldn't happen, but just in case"
    724942                self.verbose_logger.log(yum.logginglevels.INFO_2, e)
    725943        if len(self.tsInfo) > oldcount:
    726             return 2, [_('Package(s) to reinstall')]
     944            change = len(self.tsInfo) - oldcount
     945            return 2, [P_('%d package to reinstall', '%d packages to reinstall', change) % change]
    727946        return 0, [_('Nothing to do')]
    728947
     
    741960        installing = False
    742961        for pkg in filelist:
     962            if not pkg.endswith('.rpm'):
     963                self.verbose_logger.log(yum.logginglevels.INFO_2,
     964                   "Skipping: %s, filename does not end in .rpm.", pkg)
     965                continue
    743966            txmbrs = self.installLocal(pkg, updateonly=updateonly)
    744967            if txmbrs:
     
    8051028        dups = self.conf.showdupesfromrepos
    8061029        args = map(to_unicode, args)
     1030
     1031        okeys = set()
     1032        akeys = set() # All keys, used to see if nothing matched
     1033        mkeys = set() # "Main" set of keys for N/S search (biggest term. hit).
     1034        pos   = set()
     1035
     1036        def _print_match_section(text):
     1037            # Print them in the order they were passed
     1038            used_keys = [arg for arg in args if arg in keys]
     1039            print self.fmtSection(text % ", ".join(used_keys))
     1040
     1041        #  First try just the name/summary fields, and if we get any hits
     1042        # don't do the other stuff. Unless the user overrides via. "all".
     1043        if len(args) > 1 and args[0] == 'all':
     1044            args.pop(0)
     1045        else:
     1046            matching = self.searchGenerator(['name', 'summary'], args,
     1047                                            showdups=dups, keys=True)
     1048            for (po, keys, matched_value) in matching:
     1049                if keys != okeys:
     1050                    if akeys:
     1051                        if len(mkeys) == len(args):
     1052                            break
     1053                        print ""
     1054                    else:
     1055                        mkeys = set(keys)
     1056                    _print_match_section(_('N/S Matched: %s'))
     1057                    okeys = keys
     1058                pos.add(po)
     1059                akeys.update(keys)
     1060                self.matchcallback(po, matched_value, args)
     1061
    8071062        matching = self.searchGenerator(searchlist, args,
    8081063                                        showdups=dups, keys=True)
    809        
     1064
    8101065        okeys = set()
    811         akeys = set()
     1066
     1067        #  If we got a hit with just name/summary then we only care about hits
     1068        # with _more_ search terms. Thus. if we hit all our search terms. do
     1069        # nothing.
     1070        if len(mkeys) == len(args):
     1071            print ""
     1072            if len(args) == 1:
     1073                msg = _('  Name and summary matches %sonly%s, use "search all" for everything.')
     1074            else:
     1075                msg = _('  Full name and summary matches %sonly%s, use "search all" for everything.')
     1076            print msg % (self.term.MODE['bold'], self.term.MODE['normal'])
     1077            matching = []
     1078
    8121079        for (po, keys, matched_value) in matching:
     1080            #  Don't print matches for "a", "b", "c" on N+S+D when we already
     1081            # matched that on just N+S.
     1082            if len(keys) <= len(mkeys):
     1083                continue
     1084             #  Just print the highest level of full matches, when we did
     1085             # minimal matches. Ie. "A", "B" match N+S, just print the
     1086             # "A", "B", "C", "D" full match, and not the "B", "C", "D" matches.
     1087            if mkeys and len(keys) < len(okeys):
     1088                continue
     1089
    8131090            if keys != okeys:
    8141091                if akeys:
    8151092                    print ""
    816                 # Print them in the order they were passed
    817                 used_keys = [arg for arg in args if arg in keys]
    818                 print self.fmtSection(_('Matched: %s') % ", ".join(used_keys))
     1093                _print_match_section(_('Matched: %s'))
    8191094                okeys = keys
    8201095                akeys.update(keys)
    8211096            self.matchcallback(po, matched_value, args)
     1097
     1098        if mkeys and len(mkeys) != len(args):
     1099            print ""
     1100            print _('  Name and summary matches %smostly%s, use "search all" for everything.') % (self.term.MODE['bold'], self.term.MODE['normal'])
    8221101
    8231102        for arg in args:
     
    8391118                thispkg = yum.packages.YumUrlPackage(self, self.ts, arg)
    8401119                pkgs.append(thispkg)
     1120            elif self.conf.showdupesfromrepos:
     1121                pkgs.extend(self.pkgSack.returnPackages(patterns=[arg]))
    8411122            else:               
    842                 ematch, match, unmatch = self.pkgSack.matchPackageNames([arg])
    843                 for po in ematch + match:
    844                     pkgs.append(po)
     1123                try:
     1124                    pkgs.extend(self.pkgSack.returnNewestByName(patterns=[arg]))
     1125                except yum.Errors.PackageSackError:
     1126                    pass
    8451127               
    846             results = self.findDeps(pkgs)
    847             self.depListOutput(results)
     1128        results = self.findDeps(pkgs)
     1129        self.depListOutput(results)
    8481130
    8491131        return 0, []
     
    8601142        matching = self.searchPackageProvides(args, callback=cb,
    8611143                                              callback_has_matchfor=True)
     1144        if len(matching) == 0:
     1145            #  Try to be a bit clever, for commands, and python modules.
     1146            # Maybe want something so we can do perl/etc. too?
     1147            paths = set(sys.path + os.environ['PATH'].split(':'))
     1148            nargs = []
     1149            for arg in args:
     1150                if yum.misc.re_filename(arg) or yum.misc.re_glob(arg):
     1151                    continue
     1152                for path in paths:
     1153                    if not path:
     1154                        continue
     1155                    nargs.append("%s/%s" % (path, arg))
     1156            matching = self.searchPackageProvides(nargs, callback=cb,
     1157                                                  callback_has_matchfor=True)
    8621158        self.conf.showdupesfromrepos = old_sdup
    863        
     1159
    8641160        if len(matching) == 0:
    865             for arg in args:
    866                 if '*' in arg or (arg and arg[0] == '/'):
    867                     continue
    868                 self.logger.warning(_('Warning: 3.0.x versions of yum would erroneously match against filenames.\n You can use "%s*/%s%s" and/or "%s*bin/%s%s" to get that behaviour'),
    869                                     self.term.MODE['bold'], arg,
    870                                     self.term.MODE['normal'],
    871                                     self.term.MODE['bold'], arg,
    872                                     self.term.MODE['normal'])
    8731161            return 0, ['No Matches found']
    8741162       
     
    8921180        hdrcode = pkgcode = xmlcode = dbcode = expccode = 0
    8931181        pkgresults = hdrresults = xmlresults = dbresults = expcresults = []
     1182        msg = self.fmtKeyValFill(_('Cleaning repos: '),
     1183                        ' '.join([ x.id for x in self.repos.listEnabled()]))
     1184        self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
    8941185        if 'all' in userlist:
    8951186            self.verbose_logger.log(yum.logginglevels.INFO_2,
     
    9511242                                                 patterns=userlist)
    9521243       
    953         if len(installed) > 0:
    954             self.verbose_logger.log(yum.logginglevels.INFO_2,
    955                 _('Installed Groups:'))
    956             for group in installed:
    957                 if self.verbose_logger.isEnabledFor(yum.logginglevels.DEBUG_3):
    958                     self.verbose_logger.log(yum.logginglevels.INFO_2,
    959                                             '   %s (%s)', group.ui_name,
    960                                             group.groupid)
    961                 else:
    962                     self.verbose_logger.log(yum.logginglevels.INFO_2,
    963                                             '   %s', group.ui_name)
    964        
    965         if len(available) > 0:
    966             self.verbose_logger.log(yum.logginglevels.INFO_2,
    967                 _('Available Groups:'))
    968             for group in available:
    969                 if self.verbose_logger.isEnabledFor(yum.logginglevels.DEBUG_3):
    970                     self.verbose_logger.log(yum.logginglevels.INFO_2,
    971                                             '   %s (%s)', group.ui_name,
    972                                             group.groupid)
    973                 else:
    974                     self.verbose_logger.log(yum.logginglevels.INFO_2,
    975                                             '   %s', group.ui_name)
     1244        if not installed and not available:
     1245            self.logger.error(_('Warning: No groups match: %s'),
     1246                              ", ".join(userlist))
     1247            return 0, []
     1248
     1249        def _out_grp(sect, group):
     1250            if not done:
     1251                self.verbose_logger.log(yum.logginglevels.INFO_2, sect)
     1252            msg = '   %s' % group.ui_name
     1253            if self.verbose_logger.isEnabledFor(yum.logginglevels.DEBUG_3):
     1254                msg += ' (%s)' % group.groupid
     1255            if group.langonly:
     1256                msg += ' [%s]' % group.langonly
     1257            self.verbose_logger.log(yum.logginglevels.INFO_2, '%s', msg)
     1258
     1259        done = False
     1260        for group in installed:
     1261            if group.langonly: continue
     1262            _out_grp(_('Installed Groups:'), group)
     1263            done = True
     1264
     1265        done = False
     1266        for group in installed:
     1267            if not group.langonly: continue
     1268            _out_grp(_('Installed Language Groups:'), group)
     1269            done = True
     1270
     1271        done = False
     1272        for group in available:
     1273            if group.langonly: continue
     1274            _out_grp(_('Available Groups:'), group)
     1275            done = True
     1276
     1277        done = False
     1278        for group in available:
     1279            if not group.langonly: continue
     1280            _out_grp(_('Available Language Groups:'), group)
     1281            done = True
     1282
     1283        return 0, [_('Done')]
     1284
     1285    def returnGroupSummary(self, userlist):
     1286
     1287        uservisible=1
     1288           
     1289        if len(userlist) > 0:
     1290            if userlist[0] == 'hidden':
     1291                uservisible=0
     1292                userlist.pop(0)
     1293        if not userlist:
     1294            userlist = None # Match everything...
     1295
     1296        installed, available = self.doGroupLists(uservisible=uservisible,
     1297                                                 patterns=userlist)
     1298       
     1299        def _out_grp(sect, num):
     1300            if not num:
     1301                return
     1302            self.verbose_logger.log(yum.logginglevels.INFO_2, '%s %u', sect,num)
     1303        done = 0
     1304        for group in installed:
     1305            if group.langonly: continue
     1306            done += 1
     1307        _out_grp(_('Installed Groups:'), done)
     1308
     1309        done = 0
     1310        for group in installed:
     1311            if not group.langonly: continue
     1312            done += 1
     1313        _out_grp(_('Installed Language Groups:'), done)
     1314
     1315        done = False
     1316        for group in available:
     1317            if group.langonly: continue
     1318            done += 1
     1319        _out_grp(_('Available Groups:'), done)
     1320
     1321        done = False
     1322        for group in available:
     1323            if not group.langonly: continue
     1324            done += 1
     1325        _out_grp(_('Available Language Groups:'), done)
    9761326
    9771327        return 0, [_('Done')]
     
    10161366            return 0, [_('No packages in any requested group available to install or update')]
    10171367        else:
    1018             return 2, [_('%d Package(s) to Install') % len(pkgs_used)]
     1368            return 2, [P_('%d package to Install', '%d packages to Install', len(pkgs_used)) % len(pkgs_used)]
    10191369
    10201370    def removeGroups(self, grouplist):
     
    10341384            return 0, [_('No packages to remove from groups')]
    10351385        else:
    1036             return 2, [_('%d Package(s) to remove') % len(pkgs_used)]
     1386            return 2, [P_('%d package to remove', '%d packages to remove', len(pkgs_used)) % len(pkgs_used)]
    10371387
    10381388
     
    11491499            args = _filtercmdline(
    11501500                        ('--noplugins','--version','-q', '-v', "--quiet", "--verbose"),
    1151                         ('-c', '-d', '-e', '--installroot',
    1152                          '--disableplugin', '--enableplugin', '--releasever'),
     1501                        ('-c', '--config', '-d', '--debuglevel',
     1502                         '-e', '--errorlevel',
     1503                         '--installroot',
     1504                         '--disableplugin', '--enableplugin', '--releasever',
     1505                         '--setopt'),
    11531506                        args)
    11541507        except ValueError, arg:
     
    11971550
    11981551            if opts.installroot:
     1552                self._checkAbsInstallRoot(opts)
    11991553                self.base.conf.installroot = opts.installroot
    12001554               
     
    12631617            # Disable all gpg key checking, if requested.
    12641618            if opts.nogpgcheck:
    1265                 self.base.conf.gpgcheck      = False
    1266                 self.base.conf.repo_gpgcheck = False
     1619                #  Altering the normal configs. doesn't work too well, esp. with
     1620                # regard to dynamically enabled repos.
     1621                self.base._override_sigchecks = True
    12671622                for repo in self.base.repos.listEnabled():
    1268                     repo.gpgcheck      = False
    1269                     repo.repo_gpgcheck = False
     1623                    repo._override_sigchecks = True
    12701624                           
    12711625        except ValueError, e:
     
    12761630        return opts, cmds
    12771631
     1632    def _checkAbsInstallRoot(self, opts):
     1633        if not opts.installroot:
     1634            return
     1635        if opts.installroot[0] == '/':
     1636            return
     1637        # We have a relative installroot ... haha
     1638        self.logger.critical(_('--installroot must be an absolute path: %s'),
     1639                             opts.installroot)
     1640        sys.exit(1)
     1641
    12781642    def getRoot(self,opts):
     1643        self._checkAbsInstallRoot(opts)
    12791644        # If the conf file is inside the  installroot - use that.
    12801645        # otherwise look for it in the normal root
     
    13841749        group.add_option("", "--releasever", dest="releasever", default=None,
    13851750                help=_("set value of $releasever in yum config and repo files"))
    1386 
     1751        group.add_option("", "--setopt", dest="setopts", default=[],
     1752                action="append", help=_("set arbitrary config and repo options"))
    13871753
    13881754       
     
    14011767    Will raise ValueError if there was a problem parsing the command line.
    14021768    '''
     1769    # ' xemacs syntax hack
    14031770    out = []
    14041771    args = list(args)       # Make a copy because this func is destructive
     
    14101777            if opt in valopts:
    14111778                out.append(a)
     1779
     1780        elif a == '--':
     1781            out.append(a)
    14121782
    14131783        elif a in novalopts:
Note: See TracChangeset for help on using the changeset viewer.