Просмотр исходного кода

Make find_file handle the not-found case
Extend make_command to allow option=None to omit the option entirely


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33515 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 лет назад
Родитель
Сommit
a622b4f373
1 измененных файлов с 12 добавлено и 4 удалено
  1. 12 4
      lib/python/grass.py

+ 12 - 4
lib/python/grass.py

@@ -32,7 +32,8 @@ def make_command(prog, flags = "", overwrite = False, quiet = False, verbose = F
     if flags:
 	args.append("-%s" % flags)
     for opt, val in options.iteritems():
-	args.append("%s=%s" % (opt, _make_val(val)))
+	if val != None:
+	    args.append("%s=%s" % (opt, _make_val(val)))
     return args
 
 def start_command(prog, flags = "", overwrite = False, quiet = False, verbose = False, **kwargs):
@@ -155,9 +156,16 @@ def del_temp_region():
 
 # interface to g.findfile
 
-def find_file(name, element = 'cell'):
-    lines = read_command("g.findfile", element = element, file = name).splitlines()
-    return dict([_kv_regex.match(line).groups() for line in lines])
+def find_file(name, element = 'cell', mapset = None):
+    lines = read_command("g.findfile", element = element, file = name, mapset = mapset).splitlines()
+    result = []
+    for line in lines:
+	m = _kv_regex.match(line)
+	if m != None:
+	    result.append(m.groups())
+	else:
+	    result.append(line.split('='))
+    return dict(result)
 
 # interface to g.list