[GRASS-SVN] r66119 - in grass/trunk/lib/python/pygrass: raster rpc vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Sep 5 19:43:23 PDT 2015
Author: huhabla
Date: 2015-09-05 19:43:23 -0700 (Sat, 05 Sep 2015)
New Revision: 66119
Modified:
grass/trunk/lib/python/pygrass/raster/history.py
grass/trunk/lib/python/pygrass/rpc/__init__.py
grass/trunk/lib/python/pygrass/vector/abstract.py
Log:
pygrass rpc,raster,vector: Added try/except/finally to RPC server functions
and date conversion functions
Modified: grass/trunk/lib/python/pygrass/raster/history.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/history.py 2015-09-05 22:39:31 UTC (rev 66118)
+++ grass/trunk/lib/python/pygrass/raster/history.py 2015-09-06 02:43:23 UTC (rev 66119)
@@ -112,7 +112,10 @@
date_str = libraster.Rast_get_history(self.c_hist,
libraster.HIST_MAPID)
if date_str:
- return datetime.datetime.strptime(date_str, self.date_fmt)
+ try:
+ return datetime.datetime.strptime(date_str, self.date_fmt)
+ except:
+ return date_str
def _set_date(self, datetimeobj):
if datetimeobj:
Modified: grass/trunk/lib/python/pygrass/rpc/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/rpc/__init__.py 2015-09-05 22:39:31 UTC (rev 66118)
+++ grass/trunk/lib/python/pygrass/rpc/__init__.py 2015-09-06 02:43:23 UTC (rev 66119)
@@ -45,101 +45,100 @@
:param conn: A multiprocessing.Pipe instance used to send True or False
:param data: The list of data entries [function_id, raster_name, extent, color]
"""
- raster_name = data[1]
- extent = data[2]
- color = data[3]
-
- rast = RasterRow(raster_name)
array = None
-
- if rast.exist():
+ try:
+ raster_name = data[1]
+ extent = data[2]
+ color = data[3]
+
+ rast = RasterRow(raster_name)
- reg = Region()
- reg.from_rast(raster_name)
-
- if extent is not None:
- if "north" in extent:
- reg.north = extent["north"]
- if "south" in extent:
- reg.south = extent["south"]
- if "east" in extent:
- reg.east = extent["east"]
- if "west" in extent:
- reg.west = extent["west"]
- if "rows" in extent:
- reg.rows = extent["rows"]
- if "cols" in extent:
- reg.cols = extent["cols"]
- reg.adjust()
+ if rast.exist():
+
+ reg = Region()
+ reg.from_rast(raster_name)
+
+ if extent is not None:
+ if "north" in extent:
+ reg.north = extent["north"]
+ if "south" in extent:
+ reg.south = extent["south"]
+ if "east" in extent:
+ reg.east = extent["east"]
+ if "west" in extent:
+ reg.west = extent["west"]
+ if "rows" in extent:
+ reg.rows = extent["rows"]
+ if "cols" in extent:
+ reg.cols = extent["cols"]
+ reg.adjust()
- array = raster2numpy_img(raster_name, reg, color)
-
- conn.send(array)
+ array = raster2numpy_img(raster_name, reg, color)
+ except:
+ raise
+ finally:
+ conn.send(array)
def _get_vector_table_as_dict(lock, conn, data):
"""Get the table of a vector map layer as dictionary
- The value to be send via pipe is True in case the map exists and False
- if not.
-
:param lock: A multiprocessing.Lock instance
:param conn: A multiprocessing.Pipe instance used to send True or False
:param data: The list of data entries [function_id, name, where]
"""
- name = data[1]
- where = data[2]
- layer = VectorTopo(name)
ret = None
-
- if layer.exist() is True:
- layer.open("r")
- columns = None
- table = None
- if layer.table is not None:
- columns = layer.table.columns
- table = layer.table_to_dict(where=where)
- layer.close()
+ try:
+ name = data[1]
+ where = data[2]
+ layer = VectorTopo(name)
- ret = {}
- ret["table"] = table
- ret["columns"] = columns
+ if layer.exist() is True:
+ layer.open("r")
+ columns = None
+ table = None
+ if layer.table is not None:
+ columns = layer.table.columns
+ table = layer.table_to_dict(where=where)
+ layer.close()
+
+ ret = {}
+ ret["table"] = table
+ ret["columns"] = columns
+ except:
+ raise
+ finally:
+ conn.send(ret)
- conn.send(ret)
-
def _get_vector_features_as_wkb_list(lock, conn, data):
"""Return vector layer features as wkb list
supported feature types:
point, centroid, line, boundary, area
- The value to be send via pipe is True in case the map exists and False
- if not.
-
:param lock: A multiprocessing.Lock instance
:param conn: A multiprocessing.Pipe instance used to send True or False
:param data: The list of data entries [function_id,name,extent,
feature_type, field]
"""
- name = data[1]
- extent = data[2]
- feature_type = data[3]
- field = data[4]
-
wkb_list = None
- bbox = None
-
- layer = VectorTopo(name)
-
try:
+ name = data[1]
+ extent = data[2]
+ feature_type = data[3]
+ field = data[4]
+ bbox = None
+
+ layer = VectorTopo(name)
+
if layer.exist() is True:
if extent is not None:
bbox = basic.Bbox(north=extent["north"],
south=extent["south"],
east=extent["east"],
west=extent["west"])
- logging.warning(str(bbox))
+
layer.open("r")
if feature_type.lower() == "area":
wkb_list = layer.areas_to_wkb_list(bbox=bbox, field=field)
@@ -148,10 +147,10 @@
feature_type=feature_type,
field=field)
layer.close()
- except Exception, e:
- print(e)
-
- conn.send(wkb_list)
+ except:
+ raise
+ finally:
+ conn.send(wkb_list)
###############################################################################
Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py 2015-09-05 22:39:31 UTC (rev 66118)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py 2015-09-06 02:43:23 UTC (rev 66119)
@@ -162,7 +162,10 @@
def _get_map_date(self):
"""Private method to obtain the Vector map date"""
date_str = libvect.Vect_get_map_date(self.c_mapinfo)
- return datetime.datetime.strptime(date_str, self.date_fmt)
+ try:
+ return datetime.datetime.strptime(date_str, self.date_fmt)
+ except:
+ return date_str
def _set_map_date(self, datetimeobj):
"""Private method to change the Vector map date"""
More information about the grass-commit
mailing list