[yum-cvs] yum cli.py,1.201,1.202 shell.py,1.23,1.24

Seth Vidal skvidal at linux.duke.edu
Tue Dec 13 07:35:15 UTC 2005


Update of /home/groups/yum/cvs/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv17546

Modified Files:
	cli.py shell.py 
Log Message:

- make shell not traceback when user doesn't close a quoted string
- exit with a fatal error if running from file-based yum-shell script, though.
- add a shortened usage() output if calling from the shell as the --options
won't help a someone in the shell.



Index: cli.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/cli.py,v
retrieving revision 1.201
retrieving revision 1.202
diff -u -r1.201 -r1.202
--- cli.py	13 Dec 2005 06:51:20 -0000	1.201
+++ cli.py	13 Dec 2005 07:35:13 -0000	1.202
@@ -53,7 +53,8 @@
        
     def __init__(self):
         yum.YumBase.__init__(self)
-
+        self.in_shell = False
+        
     def doRepoSetup(self, thisrepo=None, dosack=1):
         """grabs the repomd.xml for each enabled repository 
            and sets up the basics of the repository"""
@@ -428,8 +429,10 @@
         """do a shell-like interface for yum commands"""
 
         self.log(2, 'Setting up Yum Shell')
+        self.in_shell = True
         self.doTsSetup()
         self.doRpmDBSetup()
+        
         if len(self.extcmds) == 0:
             yumshell = shell.YumShell(base=self)
             yumshell.cmdloop()
@@ -1405,8 +1408,13 @@
     def usage(self):
         '''Print out command line usage
         '''
-        print
-        self.optparser.print_help()
+        if not self.in_shell:
+            print self.optparser.print_help()
+        else:
+            print self.optparser.print_short_help()
+            
+            
+            
 
 class YumOptionParser(OptionParser):
     '''Subclass that makes some minor tweaks to make OptionParser do things the
@@ -1424,6 +1432,19 @@
         self.base.errorlog(0, "Command line error: "+msg)
         sys.exit(1)
 
+    def print_short_help(self):
+        '''print a shorter help - mostly for use in the shell'''
+        
+        msg="""
+    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 >
+    """
+        return msg
+
+        
 def _filtercmdline(novalopts, valopts, args):
     '''Keep only specific options from the command line argument list
 

Index: shell.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/shell.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- shell.py	25 Oct 2005 12:28:44 -0000	1.23
+++ shell.py	13 Dec 2005 07:35:13 -0000	1.24
@@ -29,6 +29,7 @@
         self.base = base
         self.prompt = '> '
         self.result = 0
+        self.from_file = False # if we're running from a file, set this
         self.resultmsgs = ['Leaving Shell']
         if (len(base.extcmds)) > 0:
             self.file = base.extcmds[0]
@@ -39,6 +40,19 @@
             'transaction', 'ts', 'update', 'config', 'deplist']
 
 
+    def _shlex_split(self, input_string):
+        """split the input using shlex rules, and error or exit accordingly"""
+        
+        inputs = []
+        try:
+            inputs = shlex.split(input_string)
+        except ValueError, e:
+            self.base.errorlog(0, 'Script Error: %s' % e)
+            if self.from_file:
+                raise Errors.YumBaseError, "Fatal error in script, exiting"
+        
+        return inputs
+        
     def script(self):
         try:
             fd = open(self.file, 'r')
@@ -46,6 +60,7 @@
             sys.exit("Error: Cannot open %s for reading")
         lines = fd.readlines()
         fd.close()
+        self.from_file = True
         for line in lines:
             self.onecmd(line)
         self.onecmd('EOF')
@@ -61,11 +76,12 @@
                 return False
             self.base.cmdstring = line
             self.base.cmdstring = self.base.cmdstring.replace('\n', '')
-            self.base.cmds = shlex.split(self.base.cmdstring)
+            self.base.cmds = self._shlex_split(self.base.cmdstring)
+
             try:
                 self.base.parseCommands()
             except Errors.YumBaseError:
-                self.do_help('')
+                pass
             else:
                 self.base.doCommands()
     
@@ -73,12 +89,7 @@
         pass
     
     def do_help(self, arg):
-        msg = """
-    commands:  clean, config, exit, groupinfo, groupinstall, grouplist,
-               groupremove, groupupdate, info, install, list,
-               localinstall, makecache, provides, quit, remove, 
-               repo, run, search, transaction, update, deplist
-    """
+        msg = self.base.optparser.print_short_help()
         if arg in ['transaction', 'ts']:
             msg = """
     %s arg
@@ -153,7 +164,7 @@
         (cmd, args, line) = self.parseline(line)
         # logs
         if cmd in ['debuglevel', 'errorlevel']:
-            opts = shlex.split(args)
+            opts = self._shlex_split(args)
             if not opts:
                 self.base.log(2, '%s: %s' % (cmd, getattr(self.base.conf, cmd)))
             else:
@@ -170,7 +181,7 @@
                     self.base.errorlog.threshold = val
         # bools
         elif cmd in ['gpgcheck', 'obsoletes', 'assumeyes']:
-            opts = shlex.split(args)
+            opts = self._shlex_split(args)
             if not opts:
                 self.base.log(2, '%s: %s' % (cmd, getattr(self.base.conf, cmd)))
             else:
@@ -186,7 +197,7 @@
         
         elif cmd in ['exclude']:
             args = args.replace(',', ' ')
-            opts = shlex.split(args)
+            opts = self._shlex_split(args)
             if not opts:
                 msg = '%s: ' % cmd
                 msg = msg + string.join(getattr(self.base.conf, cmd))
@@ -221,7 +232,7 @@
                     self.base.log(2, '%-20.20s %-40.40s  disabled' % (repo, repo.name))
         
         elif cmd == 'enable':
-            repos = shlex.split(args)
+            repos = self._shlex_split(args)
             for repo in repos:
                 try:
                     changed = self.base.repos.enableRepo(repo)
@@ -243,7 +254,7 @@
                         del self.base.up
             
         elif cmd == 'disable':
-            repos = shlex.split(args)
+            repos = self._shlex_split(args)
             for repo in repos:
                 try:
                     self.base.repos.disableRepo(repo)




More information about the Yum-cvs-commits mailing list