Browse Source

Use -n flag for g.gisenv, g.findfile
Remove unused parse_key_val2 function


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

Glynn Clements 16 years ago
parent
commit
993d8f53b3
2 changed files with 9 additions and 28 deletions
  1. 5 5
      lib/python/Makefile
  2. 4 23
      lib/python/grass.py

+ 5 - 5
lib/python/Makefile

@@ -3,10 +3,10 @@ MODULE_TOPDIR = ../..
 include $(MODULE_TOPDIR)/include/Make/Other.make
 
 default: $(ETC)/python
+	$(MAKE) $(ETC)/python/grass.py $(ETC)/python/README.txt
 
-$(ETC)/python: grass.py README.txt
-	if [ ! -d $@ ]; then $(MKDIR) $@; fi
-	for file in $^ ; do $(INSTALL_DATA) $$file $@ ; done
-
-.PHONY: $(ETC)/python
+$(ETC)/python:
+	-if [ ! -d $@ ]; then $(MKDIR) $@; fi
 
+$(ETC)/python/%: %
+	$(INSTALL_DATA) $< $@

+ 4 - 23
lib/python/grass.py

@@ -230,33 +230,14 @@ def parse_key_val(s, sep = '=', dflt = None):
 	result[k] = v
     return result
 
-_kv_regex = None
-
-def parse_key_val2(s):
-    """Parse a string into a dictionary, where entries are separated
-    by newlines and the key and value are separated by `=', and the
-    value is enclosed in single quotes.
-    Suitable for parsing the output from g.findfile and g.gisenv.
-    """
-    global _kv_regex
-    if _kv_regex == None:
-	_kv_regex = re.compile("([^=]+)='(.*)';?")
-    result = []
-    for line in s.splitlines():
-	m = _kv_regex.match(line)
-	if m != None:
-	    result.append(m.groups())
-	else:
-	    result.append(line.split('=', 1))
-    return dict(result)
-
 # interface to g.gisenv
 
 def gisenv():
     """Returns the output from running g.gisenv (with no arguments), as a
     dictionary.
     """
-    return parse_key_val2(read_command("g.gisenv"))
+    s = read_command("g.gisenv", flags='n')
+    return parse_key_val(s)
 
 # interface to g.region
 
@@ -287,8 +268,8 @@ def del_temp_region():
 
 def find_file(name, element = 'cell', mapset = None):
     """Returns the output from running g.findfile as a dictionary."""
-    s = read_command("g.findfile", element = element, file = name, mapset = mapset)
-    return parse_key_val2(s)
+    s = read_command("g.findfile", flags='n', element = element, file = name, mapset = mapset)
+    return parse_key_val(s)
 
 # interface to g.list