Coverage for py_tools_ds/processing/shell.py: 0%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1# -*- coding: utf-8 -*- 

2 

3# py_tools_ds - A collection of geospatial data analysis tools that simplify standard 

4# operations when handling geospatial raster and vector data as well as projections. 

5# 

6# Copyright (C) 2016-2021 

7# - Daniel Scheffler (GFZ Potsdam, daniel.scheffler@gfz-potsdam.de) 

8# - Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences Potsdam, 

9# Germany (https://www.gfz-potsdam.de/) 

10# 

11# This software was developed within the context of the GeoMultiSens project funded 

12# by the German Federal Ministry of Education and Research 

13# (project grant code: 01 IS 14 010 A-C). 

14# 

15# Licensed under the Apache License, Version 2.0 (the "License"); 

16# you may not use this file except in compliance with the License. 

17# You may obtain a copy of the License at 

18# 

19# http://www.apache.org/licenses/LICENSE-2.0 

20# 

21# Unless required by applicable law or agreed to in writing, software 

22# distributed under the License is distributed on an "AS IS" BASIS, 

23# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

24# See the License for the specific language governing permissions and 

25# limitations under the License. 

26 

27import shlex 

28from subprocess import PIPE, Popen 

29 

30__author__ = "Daniel Scheffler" 

31 

32 

33def subcall_with_output(cmd, v=False): 

34 """Execute external command and get its stdout, exitcode and stderr. 

35 

36 :param cmd: a normal shell command including parameters 

37 :param v: verbose mode (prints 

38 """ 

39 proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE) 

40 out, err = proc.communicate() 

41 exitcode = proc.returncode 

42 

43 if v and exitcode: 

44 print('SUBCALL CMD:', cmd) 

45 print('SUBCALL OUT:', out) 

46 print('SUBCALL ERR:', err) 

47 return out, exitcode, err