[GRASS-SVN] r44399 - grass/branches/develbranch_6/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 24 08:51:17 EST 2010


Author: martinl
Date: 2010-11-24 05:51:16 -0800 (Wed, 24 Nov 2010)
New Revision: 44399

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


Modified: grass/branches/develbranch_6/lib/python/Makefile
===================================================================
--- grass/branches/develbranch_6/lib/python/Makefile	2010-11-24 13:49:55 UTC (rev 44398)
+++ grass/branches/develbranch_6/lib/python/Makefile	2010-11-24 13:51:16 UTC (rev 44399)
@@ -10,12 +10,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__)
 PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
 
 CLEAN_SUBDIRS = ctypes
+EXTRA_CLEAN_FILES = setup.py
 
 default: $(PYFILES) $(PYCFILES) $(GDIR)/__init__.py $(GDIR)/__init__.pyc
 	-$(MAKE) -C ctypes || echo $(CURDIR)/ctypes >> $(ERRORLOG)
@@ -35,5 +36,10 @@
 $(DSTDIR)/%: % | $(DSTDIR)
 	$(INSTALL_DATA) $< $@
 
+setup.py: setup.py.tmp
+	sed \
+	-e 's#@LD_LIBRARY_PATH_VAR@#$(LD_LIBRARY_PATH_VAR)#' \
+	$< > $@
+
 #doxygen:
 DOXNAME = python

Modified: grass/branches/develbranch_6/lib/python/core.py
===================================================================
--- grass/branches/develbranch_6/lib/python/core.py	2010-11-24 13:49:55 UTC (rev 44398)
+++ grass/branches/develbranch_6/lib/python/core.py	2010-11-24 13:51:16 UTC (rev 44399)
@@ -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/develbranch_6/lib/python/db.py
===================================================================
--- grass/branches/develbranch_6/lib/python/db.py	2010-11-24 13:49:55 UTC (rev 44398)
+++ grass/branches/develbranch_6/lib/python/db.py	2010-11-24 13:51:16 UTC (rev 44399)
@@ -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/develbranch_6/lib/python/raster.py
===================================================================
--- grass/branches/develbranch_6/lib/python/raster.py	2010-11-24 13:49:55 UTC (rev 44398)
+++ grass/branches/develbranch_6/lib/python/raster.py	2010-11-24 13:51:16 UTC (rev 44399)
@@ -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/develbranch_6/lib/python/setup.py.sed (from rev 44396, grass/trunk/lib/python/setup.py.sed)
===================================================================
--- grass/branches/develbranch_6/lib/python/setup.py.sed	                        (rev 0)
+++ grass/branches/develbranch_6/lib/python/setup.py.sed	2010-11-24 13:51:16 UTC (rev 44399)
@@ -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/develbranch_6/lib/python/vector.py
===================================================================
--- grass/branches/develbranch_6/lib/python/vector.py	2010-11-24 13:49:55 UTC (rev 44398)
+++ grass/branches/develbranch_6/lib/python/vector.py	2010-11-24 13:51:16 UTC (rev 44399)
@@ -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