From c0899c96ffb3314eaa66642aceecfeba76f5f6c0 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 16 Mar 2020 14:46:22 -0400 Subject: [PATCH] GRASS engine working --- app/plugins/grass_engine.py | 30 ++++++++++++++++++++++++------ requirements.txt | 12 ++++++------ webodm/settings.py | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/plugins/grass_engine.py b/app/plugins/grass_engine.py index 7695766b..3855a75f 100644 --- a/app/plugins/grass_engine.py +++ b/app/plugins/grass_engine.py @@ -3,6 +3,7 @@ import shutil import tempfile import subprocess import os +import platform from webodm import settings @@ -80,16 +81,33 @@ class GrassContext: # Create param list params = ["{}={}".format(opt,value) for opt,value in self.script_opts.items()] + # Track success, output + success = False + out = "" + err = "" + # Execute it logger.info("Executing grass script from {}: {} -c {} location --exec python {} {}".format(self.get_cwd(), self.grass_binary, self.location, script, " ".join(params))) - p = subprocess.Popen([self.grass_binary, '-c', self.location, 'location', '--exec', 'python', script] + params, - cwd=self.get_cwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = p.communicate() + + command = [self.grass_binary, '-c', self.location, 'location', '--exec', 'python', script] + params + if platform.system() == "Windows": + # communicate() hangs on Windows so we use check_output instead + try: + out = subprocess.check_output(command, cwd=self.get_cwd()).decode('utf-8').strip() + success = True + except subprocess.CalledProcessError: + success = False + err = out + else: + p = subprocess.Popen(command, cwd=self.get_cwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + out, err = p.communicate() - out = out.decode('utf-8').strip() - err = err.decode('utf-8').strip() + out = out.decode('utf-8').strip() + err = err.decode('utf-8').strip() + success = p.returncode == 0 - if p.returncode == 0: + if success: return out else: raise GrassEngineException("Could not execute GRASS script {} from {}: {}".format(script, self.get_cwd(), err)) diff --git a/requirements.txt b/requirements.txt index 90efaf19..a877bc8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ geojson==2.3.0 gunicorn==19.7.1 itypes==1.1.0 kombu==4.6.7 -libsass==0.13.3 +libsass==0.19.4 Markdown==2.6.7 olefile==0.44 openapi-codec==1.1.7 @@ -41,7 +41,7 @@ pyodm==1.5.3b1 pyparsing==2.1.10 pytz==2019.3 rcssmin==1.0.6 -redis==2.10.6 +redis==3.2.0 requests-toolbelt==0.9.1 requests==2.21.0 rfc3987==1.3.7 @@ -57,8 +57,8 @@ webcolors==1.5 rio-color==1.0.0 rio-cogeo==1.1.8 rasterio==1.1.0 ; sys_platform == 'linux' or sys_platform == 'darwin' -https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/rasterio-1.1.3-cp38-cp38-win_amd64.whl ; sys_platform == "win32" -https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/GDAL-3.0.4-cp38-cp38-win_amd64.whl ; sys_platform == "win32" +https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/rasterio-1.1.3-cp37-cp37m-win_amd64.whl ; sys_platform == "win32" +https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/GDAL-3.0.4-cp37-cp37m-win_amd64.whl ; sys_platform == "win32" Shapely==1.7.0 ; sys_platform == "win32" -waitress==1.4.3 ; sys_platform == "win32" -gevent==1.4.0 ; sys_platform == "win32" \ No newline at end of file +eventlet==0.25.1 ; sys_platform == "win32" +pyopenssl==19.1.0 ; sys_platform == "win32" \ No newline at end of file diff --git a/webodm/settings.py b/webodm/settings.py index c3420acf..33364ba6 100644 --- a/webodm/settings.py +++ b/webodm/settings.py @@ -338,6 +338,7 @@ CELERY_WORKER_HIJACK_ROOT_LOGGER = False if platform.system() == "Windows": GDAL_LIBRARY_PATH = ".venv/Lib/site-packages/osgeo/gdal300" GEOS_LIBRARY_PATH = ".venv/Lib/site-packages/shapely/DLLs/geos_c" + if TESTING: CELERY_TASK_ALWAYS_EAGER = True