Changeset 514 for yum/vendor/current/yumcommands.py
- Timestamp:
- Feb 3, 2015, 8:28:05 AM (11 years ago)
- File:
-
- 1 edited
-
yum/vendor/current/yumcommands.py (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
yum/vendor/current/yumcommands.py
r2 r514 34 34 import yum.config 35 35 36 def _err_mini_usage(base, basecmd): 37 if basecmd not in base.yum_cli_commands: 38 base.usage() 39 return 40 cmd = base.yum_cli_commands[basecmd] 41 txt = base.yum_cli_commands["help"]._makeOutput(cmd) 42 base.logger.critical(_(' Mini usage:\n')) 43 base.logger.critical(txt) 44 36 45 def checkRootUID(base): 37 46 """ … … 47 56 if not base.gpgKeyCheck(): 48 57 for repo in base.repos.listEnabled(): 49 if (repo.gpgcheck or repo.repo_gpgcheck) and repo.gpgkey == '':58 if (repo.gpgcheck or repo.repo_gpgcheck) and not repo.gpgkey: 50 59 msg = _(""" 51 60 You have enabled checking of packages via GPG keys. This is a good thing. … … 63 72 """) 64 73 base.logger.critical(msg) 74 base.logger.critical(_("Problem repository: %s"), repo) 65 75 raise cli.CliError 66 76 … … 69 79 base.logger.critical( 70 80 _('Error: Need to pass a list of pkgs to %s') % basecmd) 71 base.usage()81 _err_mini_usage(base, basecmd) 72 82 raise cli.CliError 73 83 … … 75 85 if len(extcmds) == 0: 76 86 base.logger.critical(_('Error: Need an item to match')) 77 base.usage()87 _err_mini_usage(base, basecmd) 78 88 raise cli.CliError 79 89 … … 81 91 if len(extcmds) == 0: 82 92 base.logger.critical(_('Error: Need a group or list of groups')) 83 base.usage()93 _err_mini_usage(base, basecmd) 84 94 raise cli.CliError 85 95 … … 95 105 if cmd not in VALID_ARGS: 96 106 base.logger.critical(_('Error: invalid clean argument: %r') % cmd) 97 base.usage()107 _err_mini_usage(base, basecmd) 98 108 raise cli.CliError 99 109 … … 123 133 raise cli.CliError 124 134 135 def checkEnabledRepo(base, possible_local_files=[]): 136 """ 137 Verify that there is at least one enabled repo. 138 139 @param base: a YumBase object. 140 """ 141 if base.repos.listEnabled(): 142 return 143 144 for lfile in possible_local_files: 145 if lfile.endswith(".rpm") and os.path.exists(lfile): 146 return 147 148 msg = _('There are no enabled repos.\n' 149 ' Run "yum repolist all" to see the repos you have.\n' 150 ' You can enable repos with yum-config-manager --enable <repo>') 151 base.logger.critical(msg) 152 raise cli.CliError 153 125 154 class YumCommand: 126 155 127 156 def __init__(self): 128 157 self.done_command_once = False 158 self.hidden = False 129 159 130 160 def doneCommand(self, base, msg, *args): 131 161 if not self.done_command_once: 132 base.verbose_logger. log(logginglevels.INFO_2,msg, *args)162 base.verbose_logger.info(msg, *args) 133 163 self.done_command_once = True 134 164 … … 177 207 checkGPGKey(base) 178 208 checkPackageArg(base, basecmd, extcmds) 209 checkEnabledRepo(base, extcmds) 179 210 180 211 def doCommand(self, base, basecmd, extcmds): … … 187 218 class UpdateCommand(YumCommand): 188 219 def getNames(self): 189 return ['update' ]220 return ['update', 'update-to'] 190 221 191 222 def getUsage(self): … … 198 229 checkRootUID(base) 199 230 checkGPGKey(base) 231 checkEnabledRepo(base, extcmds) 200 232 201 233 def doCommand(self, base, basecmd, extcmds): 202 234 self.doneCommand(base, _("Setting up Update Process")) 203 235 try: 204 return base.updatePkgs(extcmds) 236 return base.updatePkgs(extcmds, update_to=(basecmd == 'update-to')) 237 except yum.Errors.YumBaseError, e: 238 return 1, [str(e)] 239 240 class DistroSyncCommand(YumCommand): 241 def getNames(self): 242 return ['distribution-synchronization', 'distro-sync'] 243 244 def getUsage(self): 245 return _("[PACKAGE...]") 246 247 def getSummary(self): 248 return _("Synchronize installed packages to the latest available versions") 249 250 def doCheck(self, base, basecmd, extcmds): 251 checkRootUID(base) 252 checkGPGKey(base) 253 checkEnabledRepo(base, extcmds) 254 255 def doCommand(self, base, basecmd, extcmds): 256 self.doneCommand(base, _("Setting up Distribution Synchronization Process")) 257 try: 258 base.conf.obsoletes = 1 259 return base.distroSyncPkgs(extcmds) 205 260 except yum.Errors.YumBaseError, e: 206 261 return 1, [str(e)] … … 239 294 240 295 def getUsage(self): 241 return "[PACKAGE|all| installed|updates|extras|obsoletes|recent]"296 return "[PACKAGE|all|available|installed|updates|extras|obsoletes|recent]" 242 297 243 298 def getSummary(self): … … 376 431 return True 377 432 378 class GroupCommand(YumCommand): 379 def doCommand(self, base, basecmd, extcmds): 433 434 class GroupsCommand(YumCommand): 435 """ Single sub-command interface for most groups interaction. """ 436 437 direct_commands = {'grouplist' : 'list', 438 'groupinstall' : 'install', 439 'groupupdate' : 'install', 440 'groupremove' : 'remove', 441 'grouperase' : 'remove', 442 'groupinfo' : 'info'} 443 444 def getNames(self): 445 return ['groups', 'group'] + self.direct_commands.keys() 446 447 def getUsage(self): 448 return "[list|info|summary|install|upgrade|remove|mark] [GROUP]" 449 450 def getSummary(self): 451 return _("Display, or use, the groups information") 452 453 def _grp_setup_doCommand(self, base): 380 454 self.doneCommand(base, _("Setting up Group Process")) 381 455 … … 388 462 return 1, [str(e)] 389 463 390 391 class GroupListCommand(GroupCommand): 392 def getNames(self): 393 return ['grouplist'] 464 def _grp_cmd(self, basecmd, extcmds): 465 if basecmd in self.direct_commands: 466 cmd = self.direct_commands[basecmd] 467 elif extcmds: 468 cmd = extcmds[0] 469 extcmds = extcmds[1:] 470 else: 471 cmd = 'summary' 472 473 remap = {'update' : 'upgrade', 474 'erase' : 'remove', 475 'mark-erase' : 'mark-remove', 476 } 477 cmd = remap.get(cmd, cmd) 478 479 return cmd, extcmds 480 481 def doCheck(self, base, basecmd, extcmds): 482 cmd, extcmds = self._grp_cmd(basecmd, extcmds) 483 484 checkEnabledRepo(base) 485 486 if cmd in ('install', 'remove', 487 'mark-install', 'mark-remove', 488 'mark-members', 'info', 'mark-members-sync'): 489 checkGroupArg(base, cmd, extcmds) 490 491 if cmd in ('install', 'remove', 'upgrade', 492 'mark-install', 'mark-remove', 493 'mark-members', 'mark-members-sync'): 494 checkRootUID(base) 495 496 if cmd in ('install', 'upgrade'): 497 checkGPGKey(base) 498 499 cmds = ('list', 'info', 'remove', 'install', 'upgrade', 'summary', 500 'mark-install', 'mark-remove', 501 'mark-members', 'mark-members-sync') 502 if cmd not in cmds: 503 base.logger.critical(_('Invalid groups sub-command, use: %s.'), 504 ", ".join(cmds)) 505 raise cli.CliError 506 507 def doCommand(self, base, basecmd, extcmds): 508 cmd, extcmds = self._grp_cmd(basecmd, extcmds) 509 510 self._grp_setup_doCommand(base) 511 if cmd == 'summary': 512 return base.returnGroupSummary(extcmds) 513 514 if cmd == 'list': 515 return base.returnGroupLists(extcmds) 516 517 try: 518 if cmd == 'info': 519 return base.returnGroupInfo(extcmds) 520 if cmd == 'install': 521 return base.installGroups(extcmds) 522 if cmd == 'upgrade': 523 return base.installGroups(extcmds, upgrade=True) 524 if cmd == 'remove': 525 return base.removeGroups(extcmds) 526 527 except yum.Errors.YumBaseError, e: 528 return 1, [str(e)] 529 530 531 def needTs(self, base, basecmd, extcmds): 532 cmd, extcmds = self._grp_cmd(basecmd, extcmds) 533 534 if cmd in ('list', 'info', 'remove', 'summary'): 535 return False 536 return True 537 538 def needTsRemove(self, base, basecmd, extcmds): 539 cmd, extcmds = self._grp_cmd(basecmd, extcmds) 540 541 if cmd in ('remove',): 542 return True 543 return False 544 545 class MakeCacheCommand(YumCommand): 546 547 def getNames(self): 548 return ['makecache'] 394 549 395 550 def getUsage(self): … … 397 552 398 553 def getSummary(self): 399 return _("List available package groups")400 401 def doCommand(self, base, basecmd, extcmds):402 GroupCommand.doCommand(self, base, basecmd, extcmds)403 return base.returnGroupLists(extcmds)404 405 def needTs(self, base, basecmd, extcmds):406 return False407 408 class GroupInstallCommand(GroupCommand):409 def getNames(self):410 return ['groupinstall', 'groupupdate']411 412 def getUsage(self):413 return "GROUP..."414 415 def getSummary(self):416 return _("Install the packages in a group on your system")417 418 def doCheck(self, base, basecmd, extcmds):419 checkRootUID(base)420 checkGPGKey(base)421 checkGroupArg(base, basecmd, extcmds)422 423 def doCommand(self, base, basecmd, extcmds):424 GroupCommand.doCommand(self, base, basecmd, extcmds)425 try:426 return base.installGroups(extcmds)427 except yum.Errors.YumBaseError, e:428 return 1, [str(e)]429 430 class GroupRemoveCommand(GroupCommand):431 def getNames(self):432 return ['groupremove', 'grouperase']433 434 def getUsage(self):435 return "GROUP..."436 437 def getSummary(self):438 return _("Remove the packages in a group from your system")439 440 def doCheck(self, base, basecmd, extcmds):441 checkRootUID(base)442 checkGroupArg(base, basecmd, extcmds)443 444 def doCommand(self, base, basecmd, extcmds):445 GroupCommand.doCommand(self, base, basecmd, extcmds)446 try:447 return base.removeGroups(extcmds)448 except yum.Errors.YumBaseError, e:449 return 1, [str(e)]450 451 def needTs(self, base, basecmd, extcmds):452 return False453 454 def needTsRemove(self, base, basecmd, extcmds):455 return True456 457 class GroupInfoCommand(GroupCommand):458 def getNames(self):459 return ['groupinfo']460 461 def getUsage(self):462 return "GROUP..."463 464 def getSummary(self):465 return _("Display details about a package group")466 467 def doCheck(self, base, basecmd, extcmds):468 checkGroupArg(base, basecmd, extcmds)469 470 def doCommand(self, base, basecmd, extcmds):471 GroupCommand.doCommand(self, base, basecmd, extcmds)472 try:473 return base.returnGroupInfo(extcmds)474 except yum.Errors.YumBaseError, e:475 return 1, [str(e)]476 477 def needTs(self, base, basecmd, extcmds):478 return False479 480 class MakeCacheCommand(YumCommand):481 482 def getNames(self):483 return ['makecache']484 485 def getUsage(self):486 return ""487 488 def getSummary(self):489 554 return _("Generate the metadata cache") 490 555 491 556 def doCheck(self, base, basecmd, extcmds): 492 pass557 checkEnabledRepo(base) 493 558 494 559 def doCommand(self, base, basecmd, extcmds): … … 533 598 def doCheck(self, base, basecmd, extcmds): 534 599 checkCleanArg(base, basecmd, extcmds) 600 checkEnabledRepo(base) 535 601 536 602 def doCommand(self, base, basecmd, extcmds): … … 571 637 return _("Check for available package updates") 572 638 573 def doCommand(self, base, basecmd, extcmds): 639 def doCheck(self, base, basecmd, extcmds): 640 checkEnabledRepo(base) 641 642 def doCommand(self, base, basecmd, extcmds): 643 obscmds = ['obsoletes'] + extcmds 574 644 base.extcmds.insert(0, 'updates') 575 645 result = 0 … … 578 648 if (base.conf.obsoletes or 579 649 base.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)): 580 typl = base.returnPkgLists( ['obsoletes'])650 typl = base.returnPkgLists(obscmds) 581 651 ypl.obsoletes = typl.obsoletes 582 652 ypl.obsoletesTuples = typl.obsoletesTuples … … 636 706 class UpgradeCommand(YumCommand): 637 707 def getNames(self): 638 return ['upgrade' ]708 return ['upgrade', 'upgrade-to'] 639 709 640 710 def getUsage(self): … … 647 717 checkRootUID(base) 648 718 checkGPGKey(base) 719 checkEnabledRepo(base, extcmds) 649 720 650 721 def doCommand(self, base, basecmd, extcmds): … … 652 723 self.doneCommand(base, _("Setting up Upgrade Process")) 653 724 try: 654 return base.updatePkgs(extcmds )725 return base.updatePkgs(extcmds, update_to=(basecmd == 'upgrade-to')) 655 726 except yum.Errors.YumBaseError, e: 656 727 return 1, [str(e)] 657 728 658 729 class LocalInstallCommand(YumCommand): 730 def __init__(self): 731 YumCommand.__init__(self) 732 self.hidden = True 733 659 734 def getNames(self): 660 735 return ['localinstall', 'localupdate'] … … 913 988 out += [base.fmtKeyValFill(_("Repo-mirrors : "), 914 989 repo.mirrorlist)] 990 if enabled and repo.urls and not baseurls: 991 url = repo.urls[0] 992 if len(repo.urls) > 1: 993 url += ' (%d more)' % (len(repo.urls) - 1) 994 out += [base.fmtKeyValFill(_("Repo-baseurl : "), 995 url)] 915 996 916 997 if not os.path.exists(repo.metadata_cookie): … … 941 1022 out += [base.fmtKeyValFill(_("Repo-excluded: "), 942 1023 ui_excludes_num)] 1024 1025 if repo.repofile: 1026 out += [base.fmtKeyValFill(_("Repo-filename: "), 1027 repo.repofile)] 943 1028 944 1029 base.verbose_logger.log(logginglevels.DEBUG_3, … … 981 1066 txt_rnam = utf8_width_fill(_('repo name'), nm_len, nm_len) 982 1067 if arg == 'disabled': # Don't output a status column. 983 base.verbose_logger. log(logginglevels.INFO_2,"%s %s",1068 base.verbose_logger.info("%s %s", 984 1069 txt_rid, txt_rnam) 985 1070 else: 986 base.verbose_logger. log(logginglevels.INFO_2,"%s %s %s",1071 base.verbose_logger.info("%s %s %s", 987 1072 txt_rid, txt_rnam, _('status')) 988 1073 for (rid, rname, (ui_enabled, ui_endis_wid), ui_num) in cols: 989 1074 if arg == 'disabled': # Don't output a status column. 990 base.verbose_logger. log(logginglevels.INFO_2,"%s %s",1075 base.verbose_logger.info("%s %s", 991 1076 utf8_width_fill(rid, id_len), 992 1077 utf8_width_fill(rname, nm_len, … … 996 1081 if ui_num: 997 1082 ui_num = utf8_width_fill(ui_num, ui_len, left=False) 998 base.verbose_logger. log(logginglevels.INFO_2,"%s %s %s%s",1083 base.verbose_logger.info("%s %s %s%s", 999 1084 utf8_width_fill(rid, id_len), 1000 1085 utf8_width_fill(rname, nm_len, nm_len), … … 1065 1150 if extcmds[0] in base.yum_cli_commands: 1066 1151 command = base.yum_cli_commands[extcmds[0]] 1067 base.verbose_logger.log(logginglevels.INFO_2, 1068 self._makeOutput(command)) 1152 base.verbose_logger.info(self._makeOutput(command)) 1069 1153 return 0, [] 1070 1154 … … 1083 1167 checkGPGKey(base) 1084 1168 checkPackageArg(base, basecmd, extcmds) 1169 checkEnabledRepo(base, extcmds) 1085 1170 1086 1171 def doCommand(self, base, basecmd, extcmds): … … 1109 1194 checkGPGKey(base) 1110 1195 checkPackageArg(base, basecmd, extcmds) 1196 checkEnabledRepo(base, extcmds) 1111 1197 1112 1198 def doCommand(self, base, basecmd, extcmds): … … 1208 1294 if lastdbv is not None: 1209 1295 lastdbv = lastdbv.end_rpmdbversion 1210 if lastdbv is None ordata[0] != lastdbv:1296 if lastdbv is not None and data[0] != lastdbv: 1211 1297 base._rpmdb_warn_checks(warn=lastdbv is not None) 1212 1298 if vcmd not in ('group-installed', 'group-all'): … … 1216 1302 if groups: 1217 1303 for grp in sorted(data[2]): 1304 if (vcmd.startswith("group-") and 1305 len(extcmds) > 1 and grp not in extcmds[1:]): 1306 continue 1218 1307 cols.append(("%s %s" % (_("Group-Installed:"), grp), 1219 1308 str(data[2][grp]))) … … 1231 1320 if groups: 1232 1321 for grp in sorted(data[2]): 1322 if (vcmd.startswith("group-") and 1323 len(extcmds) > 1 and grp not in extcmds[1:]): 1324 continue 1233 1325 cols.append(("%s %s" % (_("Group-Available:"), grp), 1234 1326 str(data[2][grp]))) … … 1267 1359 1268 1360 def getUsage(self): 1269 return "[info|list| summary|redo|undo|new]"1361 return "[info|list|packages-list|summary|addon-info|redo|undo|rollback|new]" 1270 1362 1271 1363 def getSummary(self): … … 1292 1384 return 2, ["Undoing transaction %u" % (old.tid,)] 1293 1385 1386 def _hcmd_rollback(self, base, extcmds): 1387 force = False 1388 if len(extcmds) > 1 and extcmds[1] == 'force': 1389 force = True 1390 extcmds = extcmds[:] 1391 extcmds.pop(0) 1392 1393 old = base._history_get_transaction(extcmds) 1394 if old is None: 1395 return 1, ['Failed history rollback, no transaction'] 1396 last = base.history.last() 1397 if last is None: 1398 return 1, ['Failed history rollback, no last?'] 1399 if old.tid == last.tid: 1400 return 0, ['Rollback to current, nothing to do'] 1401 1402 mobj = None 1403 for tid in base.history.old(range(old.tid + 1, last.tid + 1)): 1404 if not force and (tid.altered_lt_rpmdb or tid.altered_gt_rpmdb): 1405 if tid.altered_lt_rpmdb: 1406 msg = "Transaction history is incomplete, before %u." 1407 else: 1408 msg = "Transaction history is incomplete, after %u." 1409 print msg % tid.tid 1410 print " You can use 'history rollback force', to try anyway." 1411 return 1, ['Failed history rollback, incomplete'] 1412 1413 if mobj is None: 1414 mobj = yum.history.YumMergedHistoryTransaction(tid) 1415 else: 1416 mobj.merge(tid) 1417 1418 tm = time.ctime(old.beg_timestamp) 1419 print "Rollback to transaction %u, from %s" % (old.tid, tm) 1420 print base.fmtKeyValFill(" Undoing the following transactions: ", 1421 ", ".join((str(x) for x in mobj.tid))) 1422 base.historyInfoCmdPkgsAltered(mobj) 1423 if base.history_undo(mobj): 1424 return 2, ["Rollback to transaction %u" % (old.tid,)] 1425 1294 1426 def _hcmd_new(self, base, extcmds): 1295 1427 base.history._create_db_file() 1296 1428 1297 1429 def doCheck(self, base, basecmd, extcmds): 1298 cmds = ('list', 'info', 'summary', 'repeat', 'redo', 'undo', 'new') 1430 cmds = ('list', 'info', 'summary', 'repeat', 'redo', 'undo', 'new', 1431 'rollback', 1432 'addon', 'addon-info', 1433 'pkg', 'pkgs', 'pkg-list', 'pkgs-list', 1434 'package', 'package-list', 'packages', 'packages-list') 1299 1435 if extcmds and extcmds[0] not in cmds: 1300 1436 base.logger.critical(_('Invalid history sub-command, use: %s.'), 1301 1437 ", ".join(cmds)) 1302 1438 raise cli.CliError 1303 if extcmds and extcmds[0] in ('repeat', 'redo', 'undo', ' new'):1439 if extcmds and extcmds[0] in ('repeat', 'redo', 'undo', 'rollback', 'new'): 1304 1440 checkRootUID(base) 1305 1441 checkGPGKey(base) 1442 elif not os.access(base.history._db_file, os.R_OK): 1443 base.logger.critical(_("You don't have access to the history DB.")) 1444 raise cli.CliError 1306 1445 1307 1446 def doCommand(self, base, basecmd, extcmds): … … 1317 1456 elif vcmd == 'summary': 1318 1457 ret = base.historySummaryCmd(extcmds) 1458 elif vcmd in ('addon', 'addon-info'): 1459 ret = base.historyAddonInfoCmd(extcmds) 1460 elif vcmd in ('pkg', 'pkgs', 'pkg-list', 'pkgs-list', 1461 'package', 'package-list', 'packages', 'packages-list'): 1462 ret = base.historyPackageListCmd(extcmds) 1319 1463 elif vcmd == 'undo': 1320 1464 ret = self._hcmd_undo(base, extcmds) 1321 1465 elif vcmd in ('redo', 'repeat'): 1322 1466 ret = self._hcmd_redo(base, extcmds) 1467 elif vcmd == 'rollback': 1468 ret = self._hcmd_rollback(base, extcmds) 1323 1469 elif vcmd == 'new': 1324 1470 ret = self._hcmd_new(base, extcmds) … … 1332 1478 if extcmds: 1333 1479 vcmd = extcmds[0] 1334 return vcmd in ('repeat', 'redo', 'undo' )1480 return vcmd in ('repeat', 'redo', 'undo', 'rollback') 1335 1481 1336 1482 … … 1348 1494 chkcmd = 'all' 1349 1495 if extcmds: 1350 chkcmd = extcmds [0]1496 chkcmd = extcmds 1351 1497 1352 1498 def _out(x): 1353 print x1499 print to_unicode(x.__str__()) 1354 1500 1355 1501 rc = 0 1356 if base._rpmdb_warn_checks(_out, False, chkcmd): 1502 if base._rpmdb_warn_checks(out=_out, warn=False, chkcmd=chkcmd, 1503 header=lambda x: None): 1357 1504 rc = 1 1358 1505 return rc, ['%s %s' % (basecmd, chkcmd)] … … 1361 1508 return False 1362 1509 1510 class LoadTransactionCommand(YumCommand): 1511 def getNames(self): 1512 return ['load-transaction', 'load-ts'] 1513 1514 def getUsage(self): 1515 return "filename" 1516 1517 def getSummary(self): 1518 return _("load a saved transaction from filename") 1519 1520 def doCommand(self, base, basecmd, extcmds): 1521 if not extcmds: 1522 base.logger.critical(_("No saved transaction file specified.")) 1523 raise cli.CliError 1524 1525 load_file = extcmds[0] 1526 self.doneCommand(base, _("loading transaction from %s") % load_file) 1527 1528 try: 1529 base.load_ts(load_file) 1530 except yum.Errors.YumBaseError, e: 1531 return 1, [to_unicode(e)] 1532 return 2, [_('Transaction loaded from %s with %s members') % (load_file, len(base.tsInfo.getMembers()))] 1533 1534 1535 def needTs(self, base, basecmd, extcmds): 1536 return True 1537
Note:
See TracChangeset
for help on using the changeset viewer.
