瀏覽代碼

v.db.droptable: check if map exists (#107)

Do existence check before checking for layer information.

Uses the g.findfile-supported dot notation to ask for
the current mapset only. Gets and shows name of the mapset
for the error message.
Vaclav Petras 5 年之前
父節點
當前提交
2061b4a066
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. 11 0
      scripts/v.db.droptable/v.db.droptable.py

+ 11 - 0
scripts/v.db.droptable/v.db.droptable.py

@@ -46,6 +46,17 @@ def main():
     table = options['table']
     layer = options['layer']
 
+    # We check for existence of the map in the current mapset before
+    # doing any other operation.
+    info = gscript.find_file(map, element='vector', mapset=".")
+    if not info['file']:
+        mapset = gscript.gisenv()["MAPSET"]
+        # Message is formulated in the way that it does not mislead
+        # in case where a map of the same name is in another mapset.
+        gscript.fatal(_("Vector map <{name}> not found"
+                        " in the current mapset ({mapset})").format(
+                            name=map, mapset=mapset))
+
     # do some paranoia tests as well:
     f = gscript.vector_layer_db(map, layer)