grassenv.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. MODULE: grassenv
  3. PURPOSE: GRASS environment variable management
  4. AUTHORS: The GRASS Development Team
  5. Jachym Cepicky (Mendel University of Agriculture)
  6. Martin Landa <landa.martin gmail.com>
  7. COPYRIGHT: (C) 2006-2007 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. """
  12. import os
  13. import sys
  14. import globalvar
  15. try:
  16. import subprocess
  17. except:
  18. CompatPath = os.path.join(globalvar.ETCWXDIR, "compat")
  19. sys.path.append(CompatPath)
  20. import subprocess
  21. # import gcmd
  22. def GetGRASSVariable(var):
  23. """Return GRASS variable or '' if variable is not defined"""
  24. # gisEnv = gcmd.Command(['g.gisenv'])
  25. gisEnv = subprocess.Popen(['g.gisenv' + globalvar.EXT_BIN],
  26. stdin=None,
  27. stdout=subprocess.PIPE,
  28. stderr=None)
  29. for item in gisEnv.stdout.readlines():
  30. if var in item:
  31. return item.split('=')[1].replace("'",'').replace(';','').strip()
  32. return None