kopia lustrzana https://github.com/OpenDroneMap/WebODM
Merge pull request #843 from pierotofy/grasspythonpaths
Fixed python path imports with plugins that have extra depspull/847/head
commit
f56667c591
|
@ -35,7 +35,7 @@ class GrassEngine:
|
||||||
|
|
||||||
|
|
||||||
class GrassContext:
|
class GrassContext:
|
||||||
def __init__(self, grass_binary, tmpdir = None, script_opts = {}, location = None, auto_cleanup=True):
|
def __init__(self, grass_binary, tmpdir = None, script_opts = {}, location = None, auto_cleanup=True, python_path=None):
|
||||||
self.grass_binary = grass_binary
|
self.grass_binary = grass_binary
|
||||||
if tmpdir is None:
|
if tmpdir is None:
|
||||||
tmpdir = os.path.basename(tempfile.mkdtemp('_grass_engine', dir=settings.MEDIA_TMP))
|
tmpdir = os.path.basename(tempfile.mkdtemp('_grass_engine', dir=settings.MEDIA_TMP))
|
||||||
|
@ -43,6 +43,7 @@ class GrassContext:
|
||||||
self.script_opts = script_opts.copy()
|
self.script_opts = script_opts.copy()
|
||||||
self.location = location
|
self.location = location
|
||||||
self.auto_cleanup = auto_cleanup
|
self.auto_cleanup = auto_cleanup
|
||||||
|
self.python_path = python_path
|
||||||
|
|
||||||
def get_cwd(self):
|
def get_cwd(self):
|
||||||
return os.path.join(settings.MEDIA_TMP, self.tmpdir)
|
return os.path.join(settings.MEDIA_TMP, self.tmpdir)
|
||||||
|
@ -92,6 +93,13 @@ class GrassContext:
|
||||||
out = ""
|
out = ""
|
||||||
err = ""
|
err = ""
|
||||||
|
|
||||||
|
# Setup env
|
||||||
|
env = None
|
||||||
|
if self.python_path:
|
||||||
|
env = os.environ.copy()
|
||||||
|
sep = ";" if platform.system() == "Windows" else ":"
|
||||||
|
env["PYTHONPATH"] = "%s%s%s" % (self.python_path, sep, env.get("PYTHONPATH", ""))
|
||||||
|
|
||||||
# Execute it
|
# Execute it
|
||||||
logger.info("Executing grass script from {}: {} -c {} location --exec python {} {}".format(self.get_cwd(), self.grass_binary, self.location, script, " ".join(params)))
|
logger.info("Executing grass script from {}: {} -c {} location --exec python {} {}".format(self.get_cwd(), self.grass_binary, self.location, script, " ".join(params)))
|
||||||
|
|
||||||
|
@ -99,13 +107,13 @@ class GrassContext:
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
# communicate() hangs on Windows so we use check_output instead
|
# communicate() hangs on Windows so we use check_output instead
|
||||||
try:
|
try:
|
||||||
out = subprocess.check_output(command, cwd=self.get_cwd()).decode('utf-8').strip()
|
out = subprocess.check_output(command, cwd=self.get_cwd(), env=env).decode('utf-8').strip()
|
||||||
success = True
|
success = True
|
||||||
except:
|
except:
|
||||||
success = False
|
success = False
|
||||||
err = out
|
err = out
|
||||||
else:
|
else:
|
||||||
p = subprocess.Popen(command, cwd=self.get_cwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.Popen(command, cwd=self.get_cwd(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
|
|
||||||
|
@ -123,7 +131,8 @@ class GrassContext:
|
||||||
'tmpdir': self.tmpdir,
|
'tmpdir': self.tmpdir,
|
||||||
'script_opts': self.script_opts,
|
'script_opts': self.script_opts,
|
||||||
'location': self.location,
|
'location': self.location,
|
||||||
'auto_cleanup': self.auto_cleanup
|
'auto_cleanup': self.auto_cleanup,
|
||||||
|
'python_path': self.python_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TaskElevationMapGenerate(TaskView):
|
||||||
return Response({'error': 'No DTM layer is available. You need one to set the ground as reference.'}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({'error': 'No DTM layer is available. You need one to set the ground as reference.'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
context = grass.create_context({'auto_cleanup' : False, 'location': 'epsg:3857'})
|
context = grass.create_context({'auto_cleanup' : False, 'location': 'epsg:3857', 'python_path': plugin.get_python_packages_path()})
|
||||||
dsm = os.path.abspath(task.get_asset_download_path("dsm.tif"))
|
dsm = os.path.abspath(task.get_asset_download_path("dsm.tif"))
|
||||||
dtm = os.path.abspath(task.get_asset_download_path("dtm.tif")) if reference.lower() == 'ground' else None
|
dtm = os.path.abspath(task.get_asset_download_path("dtm.tif")) if reference.lower() == 'ground' else None
|
||||||
epsg = int(request.data.get('epsg', '3857'))
|
epsg = int(request.data.get('epsg', '3857'))
|
||||||
|
|
Ładowanie…
Reference in New Issue