[GRASS-SVN] r62859 - in grass/branches/releasebranch_7_0: include/defs lib/gis lib/gis/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 22 14:03:32 PST 2014
Author: huhabla
Date: 2014-11-22 14:03:32 -0800 (Sat, 22 Nov 2014)
New Revision: 62859
Added:
grass/branches/releasebranch_7_0/lib/gis/testsuite/
grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py
Removed:
grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py
Modified:
grass/branches/releasebranch_7_0/include/defs/gis.h
grass/branches/releasebranch_7_0/lib/gis/env.c
Log:
gis library: backport of r61956 to allow mapset specific temporal databases
Modified: grass/branches/releasebranch_7_0/include/defs/gis.h
===================================================================
--- grass/branches/releasebranch_7_0/include/defs/gis.h 2014-11-22 21:54:43 UTC (rev 62858)
+++ grass/branches/releasebranch_7_0/include/defs/gis.h 2014-11-22 22:03:32 UTC (rev 62859)
@@ -225,6 +225,8 @@
int G_get_gisrc_mode(void);
void G_create_alt_env(void);
void G_switch_env(void);
+void G__read_mapset_env(void);
+void G__read_gisrc_env(void);
/* error.c */
jmp_buf *G_fatal_longjmp(int);
Modified: grass/branches/releasebranch_7_0/lib/gis/env.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/env.c 2014-11-22 21:54:43 UTC (rev 62858)
+++ grass/branches/releasebranch_7_0/lib/gis/env.c 2014-11-22 22:03:32 UTC (rev 62859)
@@ -47,6 +47,8 @@
static int unset_env(const char *, int);
static const char *get_env(const char *, int);
static void write_env(int);
+static void parse_env(FILE *, int);
+static void force_read_env(int);
static FILE *open_env(const char *, int);
/*!
@@ -84,21 +86,41 @@
read_env(G_VAR_MAPSET);
}
-static int read_env(int loc)
+/*!
+ * \brief Force to read the mapset environment file VAR
+ *
+ * The mapset specific VAR file of the mapset set with G_setenv()
+ * will be read into memory, ignoring if it was readed before.
+ * Existing values will be overwritten, new values appended.
+ *
+ * \return
+ */
+void G__read_mapset_env(void)
{
+ force_read_env(G_VAR_MAPSET);
+}
+
+/*!
+ * \brief Force to read the GISRC environment file
+ *
+ * The GISRC file
+ * will be read into memory, ignoring if it was readed before.
+ * Existing values will be overwritten, new values appended.
+ *
+ * \return
+ */
+void G__read_gisrc_env(void)
+{
+ force_read_env(G_VAR_GISRC);
+}
+
+static void parse_env(FILE *fd, int loc)
+{
char buf[200];
char *name;
char *value;
- FILE *fd;
- if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
- return 0; /* don't use file for GISRC */
-
- if (G_is_initialized(&st->init[loc]))
- return 1;
-
- if ((fd = open_env("r", loc))) {
- while (G_getl2(buf, sizeof buf, fd)) {
+ while (G_getl2(buf, sizeof buf, fd)) {
for (name = value = buf; *value; value++)
if (*value == ':')
break;
@@ -111,14 +133,43 @@
if (*name && *value)
set_env(name, value, loc);
}
+}
- fclose(fd);
+static int read_env(int loc)
+{
+
+ FILE *fd;
+
+ if (loc == G_VAR_GISRC && st->varmode == G_GISRC_MODE_MEMORY)
+ return 0; /* don't use file for GISRC */
+
+ if (G_is_initialized(&st->init[loc]))
+ return 1;
+
+ if ((fd = open_env("r", loc))) {
+ parse_env(fd, loc);
+ fclose(fd);
}
G_initialize_done(&st->init[loc]);
return 0;
}
+/*!
+ * \brief Force the reading or the GISRC or MAPSET/VAR files
+ * and overwrite/append the specified variables
+ *
+ */
+static void force_read_env(int loc)
+{
+ FILE *fd;
+ if ((fd = open_env("r", loc))) {
+ parse_env(fd, loc);
+ fclose(fd);
+ }
+}
+
+
static int set_env(const char *name, const char *value, int loc)
{
int n;
Deleted: grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py
===================================================================
--- grass/trunk/lib/gis/testsuite/gis_lib_env_test.py 2014-09-14 19:37:08 UTC (rev 61957)
+++ grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py 2014-11-22 22:03:32 UTC (rev 62859)
@@ -1,75 +0,0 @@
-"""Test of gis library environment management
-
- at author Soeren Gebbert
-"""
-from grass.gunittest.case import TestCase
-import grass.lib.gis as libgis
-
-class GisLibraryTestEnv(TestCase):
-
- @classmethod
- def setUpClass(cls):
- libgis.G_gisinit("GisLibraryTestEnv")
-
- def test_gisrc(self):
- # File access
- libgis.G_setenv("TEST", "A");
-
- value = libgis.G_getenv("TEST")
- self.assertEqual(value, "A")
- value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
- self.assertEqual(value, "A")
-
- # In memory management
- libgis.G__setenv("TEST", "B");
-
- value = libgis.G__getenv("TEST")
- self.assertEqual(value, "B")
- value = libgis.G__getenv2("TEST", libgis.G_VAR_GISRC)
- self.assertEqual(value, "B")
- # Force reading
- libgis.G__read_gisrc_env()
- value = libgis.G_getenv("TEST")
- self.assertEqual(value, "A")
- value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
- self.assertEqual(value, "A")
-
- def test_switch_env(self):
- libgis.G__setenv("TEST", "SWITCH");
- libgis.G__setenv2("TEST", "SWITCH2", libgis.G_VAR_MAPSET);
- # Create alternative env
- libgis.G_create_alt_env()
- libgis.G__setenv("TEST", "TARGET");
- libgis.G__setenv2("TEST", "TARGET2", libgis.G_VAR_MAPSET);
- value = libgis.G_getenv("TEST")
- self.assertEqual(value, "TARGET")
- value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
- self.assertEqual(value, "TARGET2")
- # Switch back to orig env
- libgis.G_switch_env()
- value = libgis.G_getenv("TEST")
- self.assertEqual(value, "SWITCH")
- value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
- self.assertEqual(value, "SWITCH2")
-
- def test_mapset(self):
- # Mapset VAR file
- libgis.G_setenv2("TEST", "C", libgis.G_VAR_MAPSET);
- value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
- self.assertEqual(value, "C")
-
- libgis.G__setenv2("TEST", "D", libgis.G_VAR_MAPSET);
- value = libgis.G__getenv2("TEST", libgis.G_VAR_MAPSET)
- self.assertEqual(value, "D")
- # Force reading
- libgis.G__read_mapset_env()
- value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
- self.assertEqual(value, "C")
-
-
-
-if __name__ == '__main__':
- from grass.gunittest.main import test
- test()
-
-
Copied: grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py (from rev 61957, grass/trunk/lib/gis/testsuite/gis_lib_env_test.py)
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py (rev 0)
+++ grass/branches/releasebranch_7_0/lib/gis/testsuite/gis_lib_env_test.py 2014-11-22 22:03:32 UTC (rev 62859)
@@ -0,0 +1,75 @@
+"""Test of gis library environment management
+
+ at author Soeren Gebbert
+"""
+from grass.gunittest.case import TestCase
+import grass.lib.gis as libgis
+
+class GisLibraryTestEnv(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ libgis.G_gisinit("GisLibraryTestEnv")
+
+ def test_gisrc(self):
+ # File access
+ libgis.G_setenv("TEST", "A");
+
+ value = libgis.G_getenv("TEST")
+ self.assertEqual(value, "A")
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
+ self.assertEqual(value, "A")
+
+ # In memory management
+ libgis.G__setenv("TEST", "B");
+
+ value = libgis.G__getenv("TEST")
+ self.assertEqual(value, "B")
+ value = libgis.G__getenv2("TEST", libgis.G_VAR_GISRC)
+ self.assertEqual(value, "B")
+ # Force reading
+ libgis.G__read_gisrc_env()
+ value = libgis.G_getenv("TEST")
+ self.assertEqual(value, "A")
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
+ self.assertEqual(value, "A")
+
+ def test_switch_env(self):
+ libgis.G__setenv("TEST", "SWITCH");
+ libgis.G__setenv2("TEST", "SWITCH2", libgis.G_VAR_MAPSET);
+ # Create alternative env
+ libgis.G_create_alt_env()
+ libgis.G__setenv("TEST", "TARGET");
+ libgis.G__setenv2("TEST", "TARGET2", libgis.G_VAR_MAPSET);
+ value = libgis.G_getenv("TEST")
+ self.assertEqual(value, "TARGET")
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
+ self.assertEqual(value, "TARGET2")
+ # Switch back to orig env
+ libgis.G_switch_env()
+ value = libgis.G_getenv("TEST")
+ self.assertEqual(value, "SWITCH")
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
+ self.assertEqual(value, "SWITCH2")
+
+ def test_mapset(self):
+ # Mapset VAR file
+ libgis.G_setenv2("TEST", "C", libgis.G_VAR_MAPSET);
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
+ self.assertEqual(value, "C")
+
+ libgis.G__setenv2("TEST", "D", libgis.G_VAR_MAPSET);
+ value = libgis.G__getenv2("TEST", libgis.G_VAR_MAPSET)
+ self.assertEqual(value, "D")
+ # Force reading
+ libgis.G__read_mapset_env()
+ value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
+ self.assertEqual(value, "C")
+
+
+
+if __name__ == '__main__':
+ from grass.gunittest.main import test
+ test()
+
+
More information about the grass-commit
mailing list