~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/python/script/setup.py.sed

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""!@package grass.script.setup
 
2
 
 
3
@brief GRASS Python scripting module (setup)
 
4
 
 
5
Setup functions to be used in Python scripts.
 
6
 
 
7
Usage:
 
8
 
 
9
@code
 
10
from grass.script import setup as grass
 
11
 
 
12
grass.init()
 
13
...
 
14
@endcode
 
15
 
 
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
 
19
for details.
 
20
 
 
21
@author Martin Landa <landa.martin gmail.com>
 
22
"""
 
23
 
 
24
import os
 
25
import sys
 
26
import tempfile as tmpfile
 
27
 
 
28
 
 
29
def write_gisrc(dbase, location, mapset):
 
30
    """Write the gisrc file and return the gisrc path."""
 
31
    fd, gisrc = tmpfile.mkstemp()
 
32
    os.write(fd, "GISDBASE: %s\n" % dbase)
 
33
    os.write(fd, "LOCATION_NAME: %s\n" % location)
 
34
    os.write(fd, "MAPSET: %s\n" % mapset)
 
35
    os.close(fd)
 
36
    return gisrc
 
37
 
 
38
 
 
39
def init(gisbase, dbase='', location='demolocation', mapset='PERMANENT'):
 
40
    """!Initialize system variables to run scripts without starting
 
41
    GRASS explicitly.
 
42
 
 
43
    User is resposible to delete gisrc file.
 
44
 
 
45
    @param gisbase path to GRASS installation
 
46
    @param dbase   path to GRASS database (default: '')
 
47
    @param location location name (default: 'demolocation')
 
48
    @param mapset   mapset within given location (default: 'PERMANENT')
 
49
    @return path to gisrc file
 
50
    """
 
51
    # define PATH
 
52
    os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin')
 
53
    os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'scripts')
 
54
    if sys.platform.startswith('win'):  # added for winGRASS
 
55
        os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extrabin')
 
56
 
 
57
    # define LD_LIBRARY_PATH
 
58
    if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
 
59
        os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
 
60
    os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep + os.path.join(gisbase, 'lib')
 
61
    
 
62
    os.environ['GIS_LOCK'] = str(os.getpid())
 
63
 
 
64
    # Set PYTHONPATH to find GRASS Python modules
 
65
    path = os.getenv('PYTHONPATH')
 
66
    etcpy = os.path.join(gisbase, 'etc', 'python')
 
67
    if path:
 
68
        path = etcpy + os.pathsep + path
 
69
    else:
 
70
        path = etcpy
 
71
    os.environ['PYTHONPATH'] = path
 
72
 
 
73
    if not dbase:
 
74
        dbase = gisbase
 
75
 
 
76
    os.environ['GISRC'] = write_gisrc(dbase, location, mapset)
 
77
    return os.environ['GISRC']