[GRASS-SVN] r44402 - grass/branches/releasebranch_6_4/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 24 10:00:46 EST 2010


Author: martinl
Date: 2010-11-24 07:00:46 -0800 (Wed, 24 Nov 2010)
New Revision: 44402

Added:
   grass/branches/releasebranch_6_4/lib/python/setup.py.sed
Modified:
   grass/branches/releasebranch_6_4/lib/python/Makefile
   grass/branches/releasebranch_6_4/lib/python/core.py
   grass/branches/releasebranch_6_4/lib/python/db.py
   grass/branches/releasebranch_6_4/lib/python/raster.py
   grass/branches/releasebranch_6_4/lib/python/vector.py
Log:
fix grass.init() & separated to new module 'setup'
(merge r44396 & r44397 from trunk)


Modified: grass/branches/releasebranch_6_4/lib/python/Makefile
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/Makefile	2010-11-24 14:01:01 UTC (rev 44401)
+++ grass/branches/releasebranch_6_4/lib/python/Makefile	2010-11-24 15:00:46 UTC (rev 44402)
@@ -9,12 +9,13 @@
 GDIR = $(PYDIR)/grass
 DSTDIR = $(GDIR)/script
 
-MODULES = core db raster vector array
+MODULES = core db raster vector array setup
 
 PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
 
 default: $(DSTDIR)
 	$(MAKE) $(PYFILES)
+EXTRA_CLEAN_FILES = setup.py
 
 $(PYDIR):
 	test -d $@ || $(MKDIR) -p $@
@@ -29,5 +30,10 @@
 $(DSTDIR)/%: %
 	$(INSTALL_DATA) $< $@
 
+setup.py: setup.py.sed
+	sed \
+	-e 's#@LD_LIBRARY_PATH_VAR@#$(LD_LIBRARY_PATH_VAR)#' \
+	$< > $@
+
 #doxygen:
 DOXNAME = python

Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py	2010-11-24 14:01:01 UTC (rev 44401)
+++ grass/branches/releasebranch_6_4/lib/python/core.py	2010-11-24 15:00:46 UTC (rev 44402)
@@ -1,6 +1,6 @@
 """!@package grass.script.core
 
- at brief GRASS Python scripting module
+ at brief GRASS Python scripting module (core functions)
 
 Core functions to be used in Python scripts.
 
@@ -30,7 +30,6 @@
 import atexit
 import subprocess
 import shutil
-import tempfile as tmpfile
 
 # i18N
 import gettext
@@ -1002,22 +1001,6 @@
     
     return 0
 
-def init(gisbase, dbase, location, mapset):
-    os.environ['PATH'] += ':' + os.path.join(gisbase, 'bin') + ':' + \
-        os.path.join(gisbase, 'scripts')
-    os.environ['LD_LIBRARY_PATH'] = os.path.join(gisbase, 'lib')
-    
-    os.environ['GIS_LOCK'] = str(os.getpid())
-    
-    fd, gisrc = tmpfile.mkstemp()
-    os.environ['GISRC'] = gisrc
-    fd.write("GISDBASE: %s\n" % dbase)
-    fd.write("LOCATION_NAME: %s\n" % location)
-    fd.write("MAPSET: %s\n" % mapset)
-    fd.close()
-    
-    return gisrc
-
 # get debug_level
 if find_program('g.gisenv', ['--help']):
     debug_level = int(gisenv().get('DEBUG', 0))

Modified: grass/branches/releasebranch_6_4/lib/python/db.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/db.py	2010-11-24 14:01:01 UTC (rev 44401)
+++ grass/branches/releasebranch_6_4/lib/python/db.py	2010-11-24 15:00:46 UTC (rev 44402)
@@ -1,6 +1,6 @@
 """!@package grass.script.db
 
- at brief GRASS Python scripting module
+ at brief GRASS Python scripting module (database functions)
 
 Database related functions to be used in Python scripts.
 

Modified: grass/branches/releasebranch_6_4/lib/python/raster.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/raster.py	2010-11-24 14:01:01 UTC (rev 44401)
+++ grass/branches/releasebranch_6_4/lib/python/raster.py	2010-11-24 15:00:46 UTC (rev 44402)
@@ -1,6 +1,6 @@
 """!@package grass.script.raster
 
- at brief GRASS Python scripting module
+ at brief GRASS Python scripting module (raster functions)
 
 Raster related functions to be used in Python scripts.
 

Copied: grass/branches/releasebranch_6_4/lib/python/setup.py.sed (from rev 44399, grass/branches/develbranch_6/lib/python/setup.py.sed)
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/setup.py.sed	                        (rev 0)
+++ grass/branches/releasebranch_6_4/lib/python/setup.py.sed	2010-11-24 15:00:46 UTC (rev 44402)
@@ -0,0 +1,55 @@
+"""!@package grass.script.setup
+
+ at brief GRASS Python scripting module (setup)
+
+Setup functions to be used in Python scripts.
+
+Usage:
+
+ at code
+from grass.script import setup as grass
+
+grass.init()
+...
+ at endcode
+
+(C) 2010 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import os
+import tempfile as tmpfile
+
+def init(gisbase, dbase, location, mapset):
+    """!Initialize system variables to run scripts without starting
+    GRASS explicitly.
+
+    User is resposible to delete gisrc file.
+
+    @param gisbase path to GRASS installation
+    @param dbase   path to GRASS database
+    @param location location name
+    @param mapset   mapset within given location
+    @return path to gisrc file
+    """
+    os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin') + \
+        os.pathsep + os.path.join(gisbase, 'scripts')
+    if not os.environ.has_key('LD_LIBRARY_PATH'):
+        os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
+    os.environ['@LD_LIBRARY_PATH_VAR@'] += os.path.join(gisbase, 'lib')
+    
+    os.environ['GIS_LOCK'] = str(os.getpid())
+    
+    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
+

Modified: grass/branches/releasebranch_6_4/lib/python/vector.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/vector.py	2010-11-24 14:01:01 UTC (rev 44401)
+++ grass/branches/releasebranch_6_4/lib/python/vector.py	2010-11-24 15:00:46 UTC (rev 44402)
@@ -1,6 +1,6 @@
 """!@package grass.script.vector
 
- at brief GRASS Python scripting module
+ at brief GRASS Python scripting module (vector functions)
 
 Vector related functions to be used in Python scripts.
 



More information about the grass-commit mailing list