[GRASS-SVN] r46917 - grass/branches/releasebranch_6_4/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 1 08:53:58 EDT 2011
Author: martinl
Date: 2011-07-01 05:53:58 -0700 (Fri, 01 Jul 2011)
New Revision: 46917
Modified:
grass/branches/releasebranch_6_4/lib/python/core.py
grass/branches/releasebranch_6_4/lib/python/setup.py.sed
grass/branches/releasebranch_6_4/lib/python/vector.py
Log:
pythonlib: define 'delimiter' for parse_command()
don't use has_key()
(merge r46915 from trunk)
Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py 2011-07-01 12:45:49 UTC (rev 46916)
+++ grass/branches/releasebranch_6_4/lib/python/core.py 2011-07-01 12:53:58 UTC (rev 46917)
@@ -236,31 +236,41 @@
return _decode(ps.communicate()[0])
def parse_command(*args, **kwargs):
- """!Passes all arguments to read_command, then parses the output by
- parse_key_val().
+ """!Passes all arguments to read_command, then parses the output
+ by parse_key_val().
- Parsing function can be optionally given by <b>parse</b> parameter
+ Parsing function can be optionally given by <em>parse</em> parameter
including its arguments, e.g.
@code
parse_command(..., parse = (grass.parse_key_val, { 'sep' : ':' }))
@endcode
+ or you can simply define <em>delimiter</em>
+
+ @code
+ parse_command(..., delimiter = ':')
+ @endcode
+
@param args list of unnamed arguments (see start_command() for details)
@param kwargs list of named arguments (see start_command() for details)
@return parsed module output
"""
parse = None
- if kwargs.has_key('parse'):
+ parse_args = {}
+ if 'parse' in kwargs:
if type(kwargs['parse']) is types.TupleType:
parse = kwargs['parse'][0]
parse_args = kwargs['parse'][1]
del kwargs['parse']
+ if 'delimiter' in kwargs:
+ parse_args = { 'sep' : kwargs['delimiter'] }
+ del kwargs['delimiter']
+
if not parse:
parse = parse_key_val # use default fn
- parse_args = {}
res = read_command(*args, **kwargs)
@@ -712,7 +722,7 @@
warning(_("Invalid element '%s'") % line)
continue
- if result.has_key(mapset_element):
+ if mapset_element in result:
result[mapset_element].append(map)
else:
result[mapset_element] = [map, ]
Modified: grass/branches/releasebranch_6_4/lib/python/setup.py.sed
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/setup.py.sed 2011-07-01 12:45:49 UTC (rev 46916)
+++ grass/branches/releasebranch_6_4/lib/python/setup.py.sed 2011-07-01 12:53:58 UTC (rev 46917)
@@ -38,7 +38,7 @@
"""
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin') + \
os.pathsep + os.path.join(gisbase, 'scripts')
- if not os.environ.has_key('@LD_LIBRARY_PATH_VAR@'):
+ if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
os.environ['@LD_LIBRARY_PATH_VAR@'] += os.path.join(gisbase, 'lib')
Modified: grass/branches/releasebranch_6_4/lib/python/vector.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/vector.py 2011-07-01 12:45:49 UTC (rev 46916)
+++ grass/branches/releasebranch_6_4/lib/python/vector.py 2011-07-01 12:53:58 UTC (rev 46917)
@@ -161,7 +161,11 @@
@return parsed output
"""
s = read_command('v.info', flags = 't', map = map)
- return parse_key_val(s, val_type = int)
+ ret = parse_key_val(s, val_type = int)
+ if 'map3d' in ret:
+ ret['map3d'] = bool(ret['map3d'])
+
+ return ret
# interface for v.db.select
@@ -189,7 +193,7 @@
{ 'layer' : layer, 'map' : map })
return { 'columns' : [], 'values' : {} }
- if kwargs.has_key('columns'):
+ if 'columns' in kwargs:
if key not in kwargs['columns'].split(','):
# add key column if missing
debug("Adding key column to the output")
@@ -260,7 +264,7 @@
@return parsed list
"""
- if os.environ.has_key("LC_ALL"):
+ if "LC_ALL" in os.environ:
locale = os.environ["LC_ALL"]
os.environ["LC_ALL"] = "C"
@@ -283,7 +287,7 @@
east_north = ','.join(coord_list),
distance = float(distance))
- if os.environ.has_key("LC_ALL"):
+ if "LC_ALL" in os.environ:
os.environ["LC_ALL"] = locale
data = list()
More information about the grass-commit
mailing list