[GRASS-SVN] r55604 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 3 03:53:55 PDT 2013


Author: zarch
Date: 2013-04-03 03:53:55 -0700 (Wed, 03 Apr 2013)
New Revision: 55604

Modified:
   grass/trunk/lib/python/script/setup.py.sed
Log:
Add a new function, rename dit to etcpy

Modified: grass/trunk/lib/python/script/setup.py.sed
===================================================================
--- grass/trunk/lib/python/script/setup.py.sed	2013-04-03 10:45:53 UTC (rev 55603)
+++ grass/trunk/lib/python/script/setup.py.sed	2013-04-03 10:53:55 UTC (rev 55604)
@@ -25,7 +25,18 @@
 import sys
 import tempfile as tmpfile
 
-def init(gisbase, dbase = '', location = 'demolocation', mapset = 'PERMANENT'):
+
+def write_gisrc(dbase, location, mapset):
+    """Write the gisrc file and return the gisrc path."""
+    fd, gisrc = tmpfile.mkstemp()
+    os.write(fd, "GISDBASE: %s\n" % dbase)
+    os.write(fd, "LOCATION_NAME: %s\n" % location)
+    os.write(fd, "MAPSET: %s\n" % mapset)
+    os.close(fd)
+    return gisrc
+
+
+def init(gisbase, dbase='', location='demolocation', mapset='PERMANENT'):
     """!Initialize system variables to run scripts without starting
     GRASS explicitly.
 
@@ -40,32 +51,27 @@
     # define PATH
     os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin')
     os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'scripts')
-    if sys.platform.startswith('win'): # added for winGRASS
-         os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extralib')
+    if sys.platform.startswith('win'):  # added for winGRASS
+        os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extralib')
+
     # define LD_LIBRARY_PATH
     if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
         os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
     os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep + os.path.join(gisbase, 'lib')
     
     os.environ['GIS_LOCK'] = str(os.getpid())
-    
+
     # Set PYTHONPATH to find GRASS Python modules
     path = os.getenv('PYTHONPATH')
-    dir  = os.path.join(gisbase, 'etc', 'python')
+    etcpy = os.path.join(gisbase, 'etc', 'python')
     if path:
-        path = dir + os.pathsep + path
+        path = etcpy + os.pathsep + path
     else:
-        path = dir
+        path = etcpy
     os.environ['PYTHONPATH'] = path
-    
+
     if not dbase:
         dbase = gisbase
-    
-    fd, gisrc = tmpfile.mkstemp()
-    os.environ['GISRC'] = gisrc
-    os.write(fd, "GISDBASE: %s\n" % dbase)
-    os.write(fd, "LOCATION_NAME: %s\n" % location)
-    os.write(fd, "MAPSET: %s\n" % mapset)
-    os.close(fd)
-    
-    return gisrc
+
+    os.environ['GISRC'] = write_gisrc(dbase, location, mapset)
+    return os.environ['GISRC']



More information about the grass-commit mailing list