[yum-git] 6 commits - cli.py yumcommands.py
James Bowes
jbowes at linux.duke.edu
Fri Jan 25 13:35:03 UTC 2008
cli.py | 31 +++++++--
yumcommands.py | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 205 insertions(+), 13 deletions(-)
New commits:
commit 161542e167aa6555ff287b32c1fe9fffb7e3eb05
Author: James Bowes <jbowes at redhat.com>
Date: Fri Jan 25 08:34:54 2008 -0500
package names are optional arguments to 'update'
diff --git a/yumcommands.py b/yumcommands.py
index a10ea1b..81adc28 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -175,7 +175,7 @@ class UpdateCommand(YumCommand):
return ['update']
def getUsage(self):
- return "PACKAGE..."
+ return "[PACKAGE...]"
def getSummary(self):
return "Update a package or packages on your system"
commit c19a94f26a21674438857af8c1ed849411aa7954
Author: James Bowes <jbowes at redhat.com>
Date: Fri Jan 25 08:18:07 2008 -0500
Be watchful of plugin commands that mightn't have the help methods
Catch exceptions that might be thrown by missing getUsage and getSummary
methods on YumCommands implemented by plugins. We should remove this
after a while, once enough plugins implement these methods.
diff --git a/cli.py b/cli.py
index c806b6d..a211c7c 100644
--- a/cli.py
+++ b/cli.py
@@ -134,8 +134,12 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
commands = yum.misc.unique(self.yum_cli_commands.values())
commands.sort(cmp=lambda x,y : cmp(x.getNames()[0], y.getNames()[0]))
for command in commands:
- usage += "%-15s%s\n" % (command.getNames()[0],
- command.getSummary())
+ # XXX Remove this when getSummary is common in plugins
+ try:
+ summary = command.getSummary()
+ usage += "%-15s%s\n" % (command.getNames()[0], summary)
+ except (AttributeError, NotImplementedError):
+ usage += "%s\n" % command.getNames()[0]
return usage
diff --git a/yumcommands.py b/yumcommands.py
index 253b29a..a10ea1b 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -124,13 +124,13 @@ class YumCommand:
"""
@return: A usage string for the command, including arguments.
"""
- return "No usage for command"
+ raise NotImplementedError
def getSummary(self):
"""
@return: A one line summary of what the command does.
"""
- return "No summary for command"
+ raise NotImplementedError
def doCheck(self, base, basecmd, extcmds):
pass
@@ -667,14 +667,39 @@ class HelpCommand(YumCommand):
base.usage()
raise cli.CliError
+ @staticmethod
+ def _makeOutput(command):
+ canonical_name = command.getNames()[0]
+
+ # Check for the methods in case we have plugins that don't
+ # implement these.
+ # XXX Remove this once usage/summary are common enough
+ try:
+ usage = command.getUsage()
+ except (AttributeError, NotImplementedError):
+ usage = None
+ try:
+ summary = command.getSummary()
+ except (AttributeError, NotImplementedError):
+ summary = None
+
+ # XXX need detailed help here, too
+ help_output = ""
+ if usage is not None:
+ help_output += "%s %s" % (canonical_name, usage)
+ if summary is not None:
+ help_output += "\n\n%s" % summary
+
+ if usage is None and summary is None:
+ help_output = "No help available for %s" % canonical_name
+
+ return help_output
+
def doCommand(self, base, basecmd, extcmds):
if base.yum_cli_commands.has_key(extcmds[0]):
command = base.yum_cli_commands[extcmds[0]]
- canonical_name = command.getNames()[0]
- # XXX need detailed help here, too
- usagestr = "%s %s\n\n%s" % (canonical_name, command.getUsage(),
- command.getSummary())
- base.verbose_logger.log(logginglevels.INFO_2, usagestr)
+ base.verbose_logger.log(logginglevels.INFO_2,
+ self._makeOutput(command))
return 0, []
def needTs(self, base, basecmd, extcmds):
commit 2aba5408331705474f3828a6bbbd0f4ca6efd43b
Merge: de709c4... e339487...
Author: James Bowes <jbowes at redhat.com>
Date: Fri Jan 25 05:14:44 2008 -0500
Merge commit 'origin/master'
commit de709c490450392605b72222db9232b1dbd45bc9
Merge: ef87f64... 5a44686...
Author: James Bowes <jbowes at redhat.com>
Date: Thu Jan 24 19:24:44 2008 -0500
Merge commit 'origin/master'
commit ef87f64e34d8deb3ede0ab62d8e38f7df685e3f4
Author: James Bowes <jbowes at redhat.com>
Date: Thu Jan 24 19:23:34 2008 -0500
Display subcommand summaries on --help
--help used to output subcommand names on the same line. Instead format
them one per line, along with their summary string.
diff --git a/cli.py b/cli.py
index 5d6f160..c806b6d 100644
--- a/cli.py
+++ b/cli.py
@@ -124,16 +124,27 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
self._getSacks(thisrepo=thisrepo)
return self._repos
-
+
+ def _makeUsage(self):
+ """
+ Format an attractive usage string for yum, listing subcommand
+ names and summary usages.
+ """
+ usage = 'yum [options] COMMAND\n\nList of Commands:\n\n'
+ commands = yum.misc.unique(self.yum_cli_commands.values())
+ commands.sort(cmp=lambda x,y : cmp(x.getNames()[0], y.getNames()[0]))
+ for command in commands:
+ usage += "%-15s%s\n" % (command.getNames()[0],
+ command.getSummary())
+
+ return usage
+
def 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"""
-
-
- self.optparser = YumOptionParser(base=self,
- usage='yum [options] < %s >' % (', '.join(self.yum_cli_commands)))
-
+
+ self.optparser = YumOptionParser(base=self, usage=self._makeUsage())
# Parse only command line options that affect basic yum setup
opts = self.optparser.firstParse(args)
@@ -169,8 +180,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
sys.exit(1)
# update usage in case plugins have added commands
- self.optparser.set_usage('yum [options] < %s >''' % (
- ', '.join(self.yum_cli_commands)))
+ self.optparser.set_usage(self._makeUsage())
# Now parse the command line for real and
# apply some of the options to self.conf
commit 6856757535ad4af0ba636c12968b4e7d37c149ee
Author: James Bowes <jbowes at redhat.com>
Date: Thu Jan 24 18:54:04 2008 -0500
Add a help command, to display command usage
diff --git a/cli.py b/cli.py
index 581776a..5d6f160 100644
--- a/cli.py
+++ b/cli.py
@@ -92,6 +92,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
self.registerCommand(yumcommands.ShellCommand())
self.registerCommand(yumcommands.DepListCommand())
self.registerCommand(yumcommands.RepoListCommand())
+ self.registerCommand(yumcommands.HelpCommand())
def registerCommand(self, command):
for name in command.getNames():
diff --git a/yumcommands.py b/yumcommands.py
index 7286f04..bc22a3b 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -121,7 +121,16 @@ class YumCommand:
return []
def getUsage(self):
- return ''
+ """
+ @return: A usage string for the command, including arguments.
+ """
+ return "No usage for command"
+
+ def getSummary(self):
+ """
+ @return: A one line summary of what the command does.
+ """
+ return "No summary for command"
def doCheck(self, base, basecmd, extcmds):
pass
@@ -142,6 +151,12 @@ class InstallCommand(YumCommand):
def getNames(self):
return ['install']
+ def getUsage(self):
+ return "PACKAGE..."
+
+ def getSummary(self):
+ return "Install a package or packages on your system"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGPGKey(base)
@@ -159,6 +174,12 @@ class UpdateCommand(YumCommand):
def getNames(self):
return ['update']
+ def getUsage(self):
+ return "PACKAGE..."
+
+ def getSummary(self):
+ return "Update a package or packages on your system"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGPGKey(base)
@@ -175,6 +196,12 @@ class InfoCommand(YumCommand):
def getNames(self):
return ['info', 'list']
+ def getUsage(self):
+ return "[PACKAGE|all|installed|updates|extras|obsoletes|recent]"
+
+ def getSummary(self):
+ return "Display details about a package or group of packages"
+
def doCommand(self, base, basecmd, extcmds):
try:
ypl = base.returnPkgLists(extcmds)
@@ -213,6 +240,12 @@ class EraseCommand(YumCommand):
def getNames(self):
return ['erase', 'remove']
+ def getUsage(self):
+ return "PACKAGE..."
+
+ def getSummary(self):
+ return "Remove a package or packages from your system"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkPackageArg(base, basecmd, extcmds)
@@ -246,6 +279,12 @@ class GroupListCommand(GroupCommand):
def getNames(self):
return ['grouplist']
+ def getUsage(self):
+ return ""
+
+ def getSummary(self):
+ return "List available package groups"
+
def doCommand(self, base, basecmd, extcmds):
GroupCommand.doCommand(self, base, basecmd, extcmds)
return base.returnGroupLists(extcmds)
@@ -257,6 +296,12 @@ class GroupInstallCommand(GroupCommand):
def getNames(self):
return ['groupinstall', 'groupupdate']
+ def getUsage(self):
+ return "GROUP..."
+
+ def getSummary(self):
+ return "Install the packages in a group on your system"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGPGKey(base)
@@ -273,6 +318,12 @@ class GroupRemoveCommand(GroupCommand):
def getNames(self):
return ['groupremove', 'grouperase']
+ def getUsage(self):
+ return "GROUP..."
+
+ def getSummary(self):
+ return "Remove the packages in a group from your system"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGroupArg(base, basecmd, extcmds)
@@ -291,6 +342,12 @@ class GroupInfoCommand(GroupCommand):
def getNames(self):
return ['groupinfo']
+ def getUsage(self):
+ return "GROUP..."
+
+ def getSummary(self):
+ return "Display details about a package group"
+
def doCheck(self, base, basecmd, extcmds):
checkGroupArg(base, basecmd, extcmds)
@@ -309,6 +366,12 @@ class MakeCacheCommand(YumCommand):
def getNames(self):
return ['makecache']
+ def getUsage(self):
+ return ""
+
+ def getSummary(self):
+ return "Generate the metadata cache"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
@@ -336,6 +399,12 @@ class CleanCommand(YumCommand):
def getNames(self):
return ['clean']
+ def getUsage(self):
+ return "[headers|packages|metadata|dbcache|plugins|all]"
+
+ def getSummary(self):
+ return "Remove cached data"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkCleanArg(base, basecmd, extcmds)
@@ -351,6 +420,12 @@ class ProvidesCommand(YumCommand):
def getNames(self):
return ['provides', 'whatprovides']
+ def getUsage(self):
+ return "SOME_STRING"
+
+ def getSummary(self):
+ return "Find what package provides the given value"
+
def doCheck(self, base, basecmd, extcmds):
checkItemArg(base, basecmd, extcmds)
@@ -365,6 +440,12 @@ class CheckUpdateCommand(YumCommand):
def getNames(self):
return ['check-update']
+ def getUsage(self):
+ return "[PACKAGE...]"
+
+ def getSummary(self):
+ return "Check for available package updates"
+
def doCommand(self, base, basecmd, extcmds):
base.extcmds.insert(0, 'updates')
result = 0
@@ -382,6 +463,12 @@ class SearchCommand(YumCommand):
def getNames(self):
return ['search']
+ def getUsage(self):
+ return "SOME_STRING"
+
+ def getSummary(self):
+ return "Search package details for the given string"
+
def doCheck(self, base, basecmd, extcmds):
checkItemArg(base, basecmd, extcmds)
@@ -399,6 +486,12 @@ class UpgradeCommand(YumCommand):
def getNames(self):
return ['upgrade']
+ def getUsage(self):
+ return 'PACKAGE...'
+
+ def getSummary(self):
+ return "Update packages taking obsoletes into account"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGPGKey(base)
@@ -416,6 +509,12 @@ class LocalInstallCommand(YumCommand):
def getNames(self):
return ['localinstall', 'localupdate']
+ def getUsage(self):
+ return "FILE"
+
+ def getSummary(self):
+ return "Install a local RPM"
+
def doCheck(self, base, basecmd, extcmds):
checkRootUID(base)
checkGPGKey(base)
@@ -438,6 +537,12 @@ class ResolveDepCommand(YumCommand):
def getNames(self):
return ['resolvedep']
+ def getUsage(self):
+ return "DEPENDENCY"
+
+ def getSummary(self):
+ return "Determine which package provides the given dependency"
+
def doCommand(self, base, basecmd, extcmds):
base.logger.debug("Searching Packages for Dependency:")
try:
@@ -449,6 +554,12 @@ class ShellCommand(YumCommand):
def getNames(self):
return ['shell']
+ def getUsage(self):
+ return "[FILENAME]"
+
+ def getSummary(self):
+ return "Run an interactive yum shell"
+
def doCheck(self, base, basecmd, extcmds):
checkShellArg(base, basecmd, extcmds)
@@ -467,6 +578,12 @@ class DepListCommand(YumCommand):
def getNames(self):
return ['deplist']
+ def getUsage(self):
+ return 'PACKAGE...'
+
+ def getSummary(self):
+ return "List a package's dependencies"
+
def doCheck(self, base, basecmd, extcmds):
checkPackageArg(base, basecmd, extcmds)
@@ -478,13 +595,16 @@ class DepListCommand(YumCommand):
return 1, [str(e)]
-class RepoListCommand:
- usage = 'repolist [all|enabled|disabled]'
+class RepoListCommand(YumCommand):
+
def getNames(self):
return ('repolist',)
def getUsage(self):
- return usage
+ return '[all|enabled|disabled]'
+
+ def getSummary(self):
+ return 'Display the configured software repositories'
def doCheck(self, base, basecmd, extcmds):
if len(extcmds) == 0:
@@ -517,4 +637,36 @@ class RepoListCommand:
def needTs(self, base, basecmd, extcmds):
return False
-
+
+
+class HelpCommand(YumCommand):
+
+ def getNames(self):
+ return ['help']
+
+ def getUsage(self):
+ return "COMMAND"
+
+ def getSummary(self):
+ return "Display a helpful usage message"
+
+ def doCheck(self, base, basecmd, extcmds):
+ if len(extcmds) == 0:
+ base.usage()
+ raise cli.CliError
+ elif len(extcmds) > 1 or extcmds[0] not in base.yum_cli_commands:
+ base.usage()
+ raise cli.CliError
+
+ def doCommand(self, base, basecmd, extcmds):
+ if base.yum_cli_commands.has_key(extcmds[0]):
+ command = base.yum_cli_commands[extcmds[0]]
+ canonical_name = command.getNames()[0]
+ # XXX need detailed help here, too
+ usagestr = "%s %s\n\n%s" % (canonical_name, command.getUsage(),
+ command.getSummary())
+ base.verbose_logger.log(logginglevels.INFO_2, usagestr)
+ return 0, []
+
+ def needTs(self, base, basecmd, extcmds):
+ return False
More information about the Yum-cvs-commits
mailing list