-
Notifications
You must be signed in to change notification settings - Fork 2
/
patch_pygrass.diff
314 lines (283 loc) · 12.7 KB
/
patch_pygrass.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
Index: lib/python/pygrass/modules/interface/module.py
===================================================================
--- lib/python/pygrass/modules/interface/module.py (revision 73073)
+++ lib/python/pygrass/modules/interface/module.py (working copy)
@@ -8,6 +8,7 @@
from grass.exceptions import CalledModuleError, GrassError, ParameterError
from grass.script.core import Popen, PIPE, use_temp_region, del_temp_region
+from grass.script.utils import encode, decode
from .docstring import docstring_property
from .parameter import Parameter
from .flag import Flag
@@ -778,7 +779,11 @@
:return: A reference to this object
"""
if self._finished is False:
+ if self.stdin:
+ self.stdin = encode(self.stdin)
stdout, stderr = self.popen.communicate(input=self.stdin)
+ stdout = decode(stdout)
+ stderr = decode(stderr)
self.outputs['stdout'].value = stdout if stdout else ''
self.outputs['stderr'].value = stderr if stderr else ''
self.time = time.time() - self.start_time
Index: lib/python/pygrass/modules/interface/parameter.py
===================================================================
--- lib/python/pygrass/modules/interface/parameter.py (revision 73073)
+++ lib/python/pygrass/modules/interface/parameter.py (working copy)
@@ -22,7 +22,7 @@
def raiseexcpet(exc, param, ptype, value):
"""Function to modifa the error message"""
- msg = req % (param.name, param.typedesc, ptype, value, exc.message)
+ msg = req % (param.name, param.typedesc, ptype, value, str(exc))
if isinstance(exc, ValueError):
raise ValueError(msg)
elif isinstance(exc, TypeError):
Index: lib/python/pygrass/raster/abstract.py
===================================================================
--- lib/python/pygrass/raster/abstract.py (revision 73073)
+++ lib/python/pygrass/raster/abstract.py (working copy)
@@ -64,7 +64,7 @@
"""
self.name = name
self.mapset = mapset
- self.c_region = ctypes.pointer(libgis.Cell_head())
+ self.c_region = ctypes.pointer(libraster.struct_Cell_head())
self.c_range = None
def _get_range(self):
Index: lib/python/pygrass/raster/history.py
===================================================================
--- lib/python/pygrass/raster/history.py (revision 73073)
+++ lib/python/pygrass/raster/history.py (working copy)
@@ -7,6 +7,7 @@
import ctypes
import grass.lib.raster as libraster
import datetime
+from grass.script.utils import encode
class History(object):
@@ -57,6 +58,7 @@
libraster.HIST_CREATOR)
def _set_creator(self, creator):
+ creator = encode(creator)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_CREATOR,
ctypes.c_char_p(creator))
@@ -71,6 +73,7 @@
libraster.HIST_DATSRC_1)
def _set_src1(self, src1):
+ src1 = encode(src1)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_DATSRC_1,
ctypes.c_char_p(src1))
@@ -85,6 +88,7 @@
libraster.HIST_DATSRC_2)
def _set_src2(self, src2):
+ src2 = encode(src2)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_DATSRC_2,
ctypes.c_char_p(src2))
@@ -99,6 +103,7 @@
libraster.HIST_KEYWRD)
def _set_keyword(self, keyword):
+ keyword = encode(keyword)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_KEYWRD,
ctypes.c_char_p(keyword))
@@ -120,6 +125,7 @@
def _set_date(self, datetimeobj):
if datetimeobj:
date_str = datetimeobj.strftime(self.date_fmt)
+ date_str = encode(date_str)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_MAPID,
ctypes.c_char_p(date_str))
@@ -134,6 +140,7 @@
libraster.HIST_MAPSET)
def _set_mapset(self, mapset):
+ mapset = encode(mapset)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_MAPSET,
ctypes.c_char_p(mapset))
@@ -148,6 +155,7 @@
libraster.HIST_MAPTYPE)
def _set_maptype(self, maptype):
+ maptype = encode(maptype)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_MAPTYPE,
ctypes.c_char_p(maptype))
@@ -177,6 +185,7 @@
libraster.HIST_TITLE)
def _set_title(self, title):
+ title = encode(title)
return libraster.Rast_set_history(self.c_hist,
libraster.HIST_TITLE,
ctypes.c_char_p(title))
Index: lib/python/pygrass/raster/segment.py
===================================================================
--- lib/python/pygrass/raster/segment.py (revision 73073)
+++ lib/python/pygrass/raster/segment.py (working copy)
@@ -61,7 +61,7 @@
"""
if file_name == '':
file_name = libgis.G_tempfile()
- mapobj.temp_file = file(file_name, 'w')
+ mapobj.temp_file = open(file_name, 'w')
size = ctypes.sizeof(RTYPE[mapobj.mtype]['ctypes'])
if fill:
libseg.Segment_format(mapobj.temp_file.fileno(), self.rows(),
Index: lib/python/pygrass/raster/testsuite/test_history.py
===================================================================
--- lib/python/pygrass/raster/testsuite/test_history.py (revision 73073)
+++ lib/python/pygrass/raster/testsuite/test_history.py (working copy)
@@ -10,6 +10,7 @@
from grass.pygrass.raster import RasterRow
from grass.pygrass.raster.history import History
+from grass.script.utils import decode
class RasterHistoryTestCate(TestCase):
@@ -40,22 +41,22 @@
r = RasterRow(self.name)
r.open("r")
hist = r.hist
-
- self.assertEqual(hist.title, "A test map")
- self.assertEqual(hist.keyword, "This is a test map")
-
+
+ self.assertEqual(decode(hist.title), self.name)
+ self.assertEqual(decode(hist.keyword), "This is a test map")
+
hist1 = History(self.name)
hist1.read()
- self.assertEqual(hist1.title, "A test map")
- self.assertEqual(hist1.keyword, "This is a test map")
-
+ self.assertEqual(decode(hist1.title), self.name)
+ self.assertEqual(decode(hist1.keyword), "This is a test map")
+
self.assertEqual(hist, hist1)
- self.assertEqual(hist.creator, hist1.creator)
+ self.assertEqual(decode(hist.creator), decode(hist1.creator))
hist1.creator = "Markus"
- self.assertNotEqual(hist.creator, hist1.creator)
+ self.assertNotEqual(decode(hist.creator), decode(hist1.creator))
r.close()
-
+
hist1.title = "No such title"
hist1.keyword = "No such description"
hist1.src1 = "No such source 1"
@@ -65,12 +66,12 @@
r.open("r")
hist = r.hist
- self.assertEqual(hist.title, "No such title")
- self.assertEqual(hist.keyword, "No such description")
- self.assertEqual(hist.creator, "Markus")
- self.assertEqual(hist.creator, "Markus")
- self.assertEqual(hist.src1, "No such source 1")
- self.assertEqual(hist.src2, "No such source 2")
+ self.assertEqual(decode(hist.title), "No such title")
+ self.assertEqual(decode(hist.keyword), "No such description")
+ self.assertEqual(decode(hist.creator), "Markus")
+ self.assertEqual(decode(hist.creator), "Markus")
+ self.assertEqual(decode(hist.src1), "No such source 1")
+ self.assertEqual(decode(hist.src2), "No such source 2")
r.close()
if __name__ == '__main__':
Index: lib/python/pygrass/vector/geometry.py
===================================================================
--- lib/python/pygrass/vector/geometry.py (revision 73073)
+++ lib/python/pygrass/vector/geometry.py (working copy)
@@ -721,7 +721,8 @@
pnt.c_points.contents.x,
pnt.c_points.contents.y,
pnt.c_points.contents.z,
- angle, slope):
+ ctypes.c_double(angle),
+ ctypes.c_double(slope)):
raise ValueError("Vect_point_on_line give an error.")
pnt.is2D = self.is2D
return pnt
Index: lib/python/pygrass/vector/table.py
===================================================================
--- lib/python/pygrass/vector/table.py (revision 73073)
+++ lib/python/pygrass/vector/table.py (working copy)
@@ -30,8 +30,10 @@
from grass.pygrass.utils import table_exist
from grass.script.db import db_table_in_vector
from grass.script.core import warning
+from grass.script.utils import decode
from grass.pygrass.vector import sql
+from grass.lib.ctypes_preamble import String
# For test purposes
test_vector_name = "table_doctest_map"
@@ -70,6 +72,8 @@
path = path.replace('$LOCATION_NAME', mapset.location)
path = path.replace('$MAPSET', mapset.name)
if vect_name is not None:
+ if isinstance(vect_name, String):
+ vect_name = vect_name.data
path = path.replace('$MAP', vect_name)
return path
@@ -638,7 +642,7 @@
return self.c_fieldinfo.contents.name
def _set_name(self, name):
- self.c_fieldinfo.contents.name = name
+ self.c_fieldinfo.contents.name = String(name)
name = property(fget=_get_name, fset=_set_name,
doc="Set and obtain name vale")
@@ -647,7 +651,7 @@
return self.c_fieldinfo.contents.table
def _set_table(self, new_name):
- self.c_fieldinfo.contents.table = new_name
+ self.c_fieldinfo.contents.table = String(new_name)
table_name = property(fget=_get_table, fset=_set_table,
doc="Set and obtain table name value")
@@ -656,7 +660,7 @@
return self.c_fieldinfo.contents.key
def _set_key(self, key):
- self.c_fieldinfo.contents.key = key
+ self.c_fieldinfo.contents.key = String(key)
key = property(fget=_get_key, fset=_set_key,
doc="Set and obtain cat value")
@@ -665,7 +669,7 @@
return self.c_fieldinfo.contents.database
def _set_database(self, database):
- self.c_fieldinfo.contents.database = database
+ self.c_fieldinfo.contents.database = String(database)
database = property(fget=_get_database, fset=_set_database,
doc="Set and obtain database value")
@@ -677,7 +681,7 @@
if driver not in ('sqlite', 'pg'):
str_err = "Driver not supported, use: %s." % ", ".join(DRIVERS)
raise TypeError(str_err)
- self.c_fieldinfo.contents.driver = driver
+ self.c_fieldinfo.contents.driver = String(driver)
driver = property(fget=_get_driver, fset=_set_driver,
doc="Set and obtain driver value. The drivers supported \
@@ -746,7 +750,10 @@
>>> conn.close()
"""
- if self.driver == 'sqlite':
+ driver = self.driver
+ if isinstance(driver, String):
+ driver = decode(driver.data)
+ if driver == 'sqlite':
import sqlite3
# Numpy is using some custom integer data types to efficiently
# pack data into memory. Since these types aren't familiar to
@@ -756,10 +763,14 @@
sqlite3.register_adapter(t, long)
dbpath = get_path(self.database, self.table_name)
dbdirpath = os.path.split(dbpath)[0]
+ if isinstance(dbpath, String):
+ dbpath = dbpath.data
+ if isinstance(dbdirpath, String):
+ dbdirpath = dbdirpath.data
if not os.path.exists(dbdirpath):
os.mkdir(dbdirpath)
return sqlite3.connect(dbpath)
- elif self.driver == 'pg':
+ elif driver == 'pg':
try:
import psycopg2
psycopg2.paramstyle = 'qmark'