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-2011 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>
25 import tempfile
as tmpfile
27 def init(gisbase, dbase = '', location = 'demolocation', mapset = 'PERMANENT'):
28 """!Initialize system variables to run scripts without starting
31 User is resposible to delete gisrc file.
33 @param gisbase path to GRASS installation
34 @param dbase path to GRASS database (default: '')
35 @param location location name (default: 'demolocation')
36 @param mapset mapset within given location (default: 'PERMANENT')
37 @return path to gisrc file
39 os.environ[
'PATH'] += os.pathsep + os.path.join(gisbase,
'bin') + \
40 os.pathsep + os.path.join(gisbase,
'scripts')
41 if 'LD_LIBRARY_PATH' not in os.environ:
42 os.environ[
'LD_LIBRARY_PATH'] =
''
43 os.environ[
'LD_LIBRARY_PATH'] += os.path.join(gisbase,
'lib')
45 os.environ[
'GIS_LOCK'] = str(os.getpid())
48 path = os.getenv(
'PYTHONPATH')
49 dir = os.path.join(gisbase,
'etc',
'python')
51 path = dir + os.pathsep + path
54 os.environ[
'PYTHONPATH'] = path
59 fd, gisrc = tmpfile.mkstemp()
60 os.environ[
'GISRC'] = gisrc
61 os.write(fd,
"GISDBASE: %s\n" % dbase)
62 os.write(fd,
"LOCATION_NAME: %s\n" % location)
63 os.write(fd,
"MAPSET: %s\n" % mapset)