1
"""!@package grass.script.setup
3
@brief GRASS Python scripting module (setup)
5
Setup functions to be used in Python scripts.
10
from grass.script import setup as grass
16
(C) 2010-2012 by the GRASS Development Team
17
This program is free software under the GNU General Public
18
License (>=v2). Read the file COPYING that comes with GRASS
21
@author Martin Landa <landa.martin gmail.com>
26
import tempfile as tmpfile
28
def init(gisbase, dbase = '', location = 'demolocation', mapset = 'PERMANENT'):
29
"""!Initialize system variables to run scripts without starting
32
User is resposible to delete gisrc file.
34
@param gisbase path to GRASS installation
35
@param dbase path to GRASS database (default: '')
36
@param location location name (default: 'demolocation')
37
@param mapset mapset within given location (default: 'PERMANENT')
38
@return path to gisrc file
41
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin')
42
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'scripts')
43
if sys.platform.startswith('win'): # added for winGRASS
44
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extralib')
45
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'msys', 'bin')
46
# define LD_LIBRARY_PATH
47
if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
48
os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
49
os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep + os.path.join(gisbase, 'lib')
51
os.environ['GIS_LOCK'] = str(os.getpid())
53
# Set PYTHONPATH to find GRASS Python modules
54
path = os.getenv('PYTHONPATH')
55
dir = os.path.join(gisbase, 'etc', 'python')
57
path = dir + os.pathsep + path
60
os.environ['PYTHONPATH'] = path
65
fd, gisrc = tmpfile.mkstemp()
66
os.environ['GISRC'] = gisrc
67
os.write(fd, "GISDBASE: %s\n" % dbase)
68
os.write(fd, "LOCATION_NAME: %s\n" % location)
69
os.write(fd, "MAPSET: %s\n" % mapset)