[GRASS-SVN] r50884 - grass/branches/releasebranch_6_4/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 19 16:32:40 EST 2012


Author: martinl
Date: 2012-02-19 13:32:40 -0800 (Sun, 19 Feb 2012)
New Revision: 50884

Modified:
   grass/branches/releasebranch_6_4/lib/python/core.py
   grass/branches/releasebranch_6_4/lib/python/task.py
Log:
pythonlib: sync'ed with devbr6


Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py	2012-02-19 20:44:13 UTC (rev 50883)
+++ grass/branches/releasebranch_6_4/lib/python/core.py	2012-02-19 21:32:40 UTC (rev 50884)
@@ -61,9 +61,9 @@
 class ScriptError(Exception):
     def __init__(self, msg):
         self.value = msg
-    
+        
     def __str__(self):
-        return repr(self.value)
+        return self.value
         
 raise_on_error = False # raise exception instead of calling fatal()
 debug_level = 0        # DEBUG level
@@ -710,7 +710,7 @@
             result[mapset] = []
     
     mapset = None
-    for line in read_command("g.mlist", flags = "m",
+    for line in read_command("g.mlist", quiet = True, flags = "m",
                              type = type, pattern = pattern).splitlines():
         try:
             name, mapset = line.split('@')
@@ -1027,8 +1027,8 @@
     @code
     print version()
 
-    {'date': '2011', 'libgis_date': '2011-04-13 13:19:03 +0200 (Wed, 13 Apr 2011)',
-    'version': '6.4.2svn', 'libgis_revision': '45934', 'revision': '47445'}
+    {'date': '2011', 'libgis_date': '2011-02-26 21:31:24 +0100 (Sat, 26 Feb 2011)',
+    'version': '6.4.3', 'libgis_revision': '45467', 'revision': '47305'}
     @endcode
     """
     data = parse_command('g.version',

Modified: grass/branches/releasebranch_6_4/lib/python/task.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/task.py	2012-02-19 20:44:13 UTC (rev 50883)
+++ grass/branches/releasebranch_6_4/lib/python/task.py	2012-02-19 21:32:40 UTC (rev 50884)
@@ -169,8 +169,8 @@
                 return f
         raise ValueError, _("Flag not found: %s") % aFlag
 
-    def getCmdError(self):
-        """!Get error string produced by getCmd(ignoreErrors = False)
+    def get_cmd_error(self):
+        """!Get error string produced by get_cmd(ignoreErrors = False)
         
         @return list of errors
         """
@@ -191,7 +191,7 @@
         
         return errorList
     
-    def getCmd(self, ignoreErrors = False, ignoreRequired = False):
+    def get_cmd(self, ignoreErrors = False, ignoreRequired = False, ignoreDefault = True):
         """!Produce an array of command name and arguments for feeding
         into some execve-like command processor.
 
@@ -199,6 +199,7 @@
         far, even though it would not be a correct command for GRASS
         @param ignoreRequired True to ignore required flags, otherwise
         '<required>' is shown
+        @param ignoreDefault True to ignore parameters with default values
         """
         cmd = [self.name]
         
@@ -212,16 +213,19 @@
                 if flag['suppress_required']:
                     suppress_required = True
         for p in self.params:
-            if p.get('value','') ==  '' and p.get('required', False):
+            if p.get('value', '') ==  '' and p.get('required', False):
                 if p.get('default', '') !=  '':
                     cmd +=  [ '%s=%s' % (p['name'], p['default']) ]
                 elif ignoreErrors and not suppress_required and not ignoreRequired:
                     cmd +=  [ '%s=%s' % (p['name'], _('<required>')) ]
-            elif p.get('value','') !=  '' and p['value'] !=  p.get('default','') :
-                # Output only values that have been set, and different from defaults
+            elif p.get('value', '') ==  '' and p.get('default', '') != '' and not ignoreDefault:
+                cmd +=  [ '%s=%s' % (p['name'], p['default']) ]
+            elif p.get('value', '') !=  '' and \
+                    (p['value'] !=  p.get('default', '') or not ignoreDefault):
+                # output only values that have been set, and different from defaults
                 cmd +=  [ '%s=%s' % (p['name'], p['value']) ]
         
-        errList = self.getCmdError()
+        errList = self.get_cmd_error()
         if ignoreErrors is False and errList:
             raise ValueError, '\n'.join(errList)
         
@@ -435,7 +439,9 @@
         
         cmdout, cmderr = Popen(args, stdout = PIPE,
                                stderr = PIPE).communicate()
-        
+        if cmderr:
+            raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
+                                 "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : decode(cmderr) }
     except OSError, e:
         raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
                              "\n\nDetails: %(det)s") % { 'cmd' : cmd, 'det' : e }



More information about the grass-commit mailing list