[GRASS-SVN] r65374 - grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 4 22:33:55 PDT 2015
Author: zarch
Date: 2015-06-04 22:33:55 -0700 (Thu, 04 Jun 2015)
New Revision: 65374
Added:
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/env.py
Modified:
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/Makefile
grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
Log:
pygrass: backport r65336, rm get_msgr from modules to avoid the ctypes use
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/Makefile
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/Makefile 2015-06-05 05:31:15 UTC (rev 65373)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/Makefile 2015-06-05 05:33:55 UTC (rev 65374)
@@ -9,7 +9,7 @@
PGDIR = $(GDIR)/pygrass
DSTDIR= $(PGDIR)/modules/interface
-MODULES = docstring read typedict flag parameter module
+MODULES = docstring read typedict flag parameter module env
PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
Copied: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/env.py (from rev 65336, grass/trunk/lib/python/pygrass/modules/interface/env.py)
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/env.py (rev 0)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/env.py 2015-06-05 05:33:55 UTC (rev 65374)
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Thu May 28 17:41:32 2015
+
+ at author: pietro
+"""
+from __future__ import print_function
+import os
+import sys
+
+
+def get_env():
+ """Parse the GISRC file and return the GRASS variales"""
+ gisrc = os.environ.get('GISRC')
+ if gisrc is None:
+ raise RuntimeError('You are not in a GRASS session, GISRC not found.')
+ with open(gisrc, mode='r') as grc:
+ env = {k.strip(): v.strip() for k, v in [row.split(':')
+ for row in grc if row]}
+ return env
+
+
+def get_debug_level():
+ """Return the debug level"""
+ debug = get_env().get('DEBUG')
+ return int(debug) if debug else 0
+
+
+def G_debug(level, *msg):
+ """Print or write a debug message, this is a pure python implementation
+ of the G_debug function in the C API."""
+ debug_level = get_debug_level()
+ if debug_level >= level:
+ dfile = os.environ.get("GRASS_DEBUG_FILE")
+ fd = sys.stderr if dfile is None else open(dfile, mode='a')
+ print("D%d/%d: " % (level, debug_level), *msg, end='\n', file=fd)
Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2015-06-05 05:31:15 UTC (rev 65373)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/modules/interface/module.py 2015-06-05 05:33:55 UTC (rev 65374)
@@ -3,13 +3,8 @@
with_statement, print_function, unicode_literals)
import sys
from multiprocessing import cpu_count
-
-if sys.version_info[0] == 2:
- from itertools import izip_longest as zip_longest
-else:
- from itertools import zip_longest
+import time
from xml.etree.ElementTree import fromstring
-import time
from grass.exceptions import CalledModuleError, GrassError, ParameterError
from grass.script.core import Popen, PIPE
@@ -18,9 +13,15 @@
from .flag import Flag
from .typedict import TypeDict
from .read import GETFROMTAG, DOC
-from grass.pygrass.messages import get_msgr
+from .env import G_debug
+if sys.version_info[0] == 2:
+ from itertools import izip_longest as zip_longest
+else:
+ from itertools import zip_longest
+
+
def _get_bash(self, *args, **kargs):
return self.get_bash()
@@ -677,7 +678,7 @@
termination. The handling of stdout and stderr must then be done
outside of this function.
"""
- get_msgr().debug(1, self.get_bash())
+ G_debug(1, self.get_bash())
if self.inputs['stdin'].value:
self.stdin = self.inputs['stdin'].value
self.stdin_ = PIPE
More information about the grass-commit
mailing list