On Tue, 2007-06-05 at 09:31 -0400, James Bowes wrote: > Yeah, and maybe add an argument for search, like > yum search --and foo bar > where --and is replaced by a better argument name. > > So, who's going to implement proper arguments for yum subcommands?
So this is probably a good point to bring up a patch I've done to add generic "sub command" handling to yum. My main push was to allow plugins to register sub-commands, like "list foo" etc. Extending this so that it processes arguments too is probably the way to go, if we want that. Here is my initial attempt, roughly tested, which just contains the interfaces and has the info/list command converted. Comments? -- James Antill <[EMAIL PROTECTED]>
Index: cli.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/cli.py,v
retrieving revision 1.270
diff -u -r1.270 cli.py
--- cli.py 5 Jun 2007 07:52:58 -0000 1.270
+++ cli.py 5 Jun 2007 15:22:53 -0000
@@ -61,6 +61,7 @@
self.logger = logging.getLogger("yum.cli")
self.verbose_logger = logging.getLogger("yum.verbose.cli")
self.yum_cli_commands = {}
+ self.yum_cli_sub_commands = {}
self.registerCommand(yumcommands.InstallCommand())
self.registerCommand(yumcommands.UpdateCommand())
self.registerCommand(yumcommands.InfoCommand())
@@ -81,6 +82,8 @@
self.registerCommand(yumcommands.ShellCommand())
self.registerCommand(yumcommands.DepListCommand())
self.registerCommand(yumcommands.RepoListCommand())
+
+ self.registerSubCommand(yumcommands.InfoCoreCommands())
def registerCommand(self, command):
for name in command.getNames():
@@ -88,6 +91,26 @@
raise yum.Errors.ConfigError('Command "%s" already defined' % name)
self.yum_cli_commands[name] = command
+ def registerSubCommand(self, command):
+ for parentname in command.getNames():
+ if not self.yum_cli_sub_commands.has_key(parentname):
+ self.yum_cli_sub_commands[parentname] = {}
+ for name in command.getSubNames():
+ if self.yum_cli_sub_commands[parentname].has_key(name):
+ txt = 'Subcommand "%s" already defined for %s' % (name,
+ parentname)
+ raise yum.Errors.ConfigError(txt)
+ self.yum_cli_sub_commands[parentname][name] = command
+
+ def callSubCommand(self, basecmd, extcmds):
+ pcmds = self.yum_cli_sub_commands[basecmd]
+ if pcmds.has_key(extcmds[0]):
+ return pcmds[extcmds[0]].doCommand(self, basecmd, extcmds)
+ else:
+ for cmd in pcmds.values():
+ if cmd.defaultMatch():
+ return cmd.doCommand(self, basecmd, extcmds)
+
def doRepoSetup(self, thisrepo=None, dosack=1):
"""grabs the repomd.xml for each enabled repository
and sets up the basics of the repository"""
Index: yumcommands.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/yumcommands.py,v
retrieving revision 1.4
diff -u -r1.4 yumcommands.py
--- yumcommands.py 2 May 2007 23:19:32 -0000 1.4
+++ yumcommands.py 5 Jun 2007 15:23:52 -0000
@@ -151,9 +151,17 @@
except yum.Errors.YumBaseError, e:
return 1, [str(e)]
-class InfoCommand(YumCommand):
+class InfoCoreCommands:
def getNames(self):
return ['info', 'list']
+
+ def getSubNames(self):
+ return ['all', 'available', 'updates', 'installed', 'extras',
+ 'obsoletes', 'recent']
+
+ def defaultMatch(self):
+ """ yum list <glob_exp1> """
+ return True
def doCommand(self, base, basecmd, extcmds):
try:
@@ -175,6 +183,13 @@
base.listPkgs(ypl.recent, 'Recently Added Packages', basecmd)
return 0, []
+class InfoCommand(YumCommand):
+ def getNames(self):
+ return ['info', 'list']
+
+ def doCommand(self, base, basecmd, extcmds):
+ return base.callSubCommand(basecmd, extcmds)
+
class EraseCommand(YumCommand):
def getNames(self):
return ['erase', 'remove']
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Yum-devel mailing list [email protected] https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
