Skip to content

Commit

Permalink
Feature/replace check output (#4854)
Browse files Browse the repository at this point in the history
* Do not print stderr in stdout

* try with scm

* Better output check

* moved

* Organized imports

* Remove file always

* Reverted formatting

* Reverted format and fixed imports

* Close file

* Close descriptor

* Added which

* Ignore stderr

* replace check output

* dont care if you dont delete the tmp
  • Loading branch information
lasote authored Mar 28, 2019
1 parent 1b0fdab commit 1548364
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion conans/client/tools/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import platform
import subprocess
import sys
import tempfile
from subprocess import CalledProcessError, PIPE

from conans.client.tools import which
from conans.client.tools.env import environment_append
from conans.client.tools.files import load, which
from conans.errors import ConanException
from conans.model.version import Version
from conans.util.fallbacks import default_output
Expand Down Expand Up @@ -432,3 +434,24 @@ def get_gnu_triplet(os_, arch, compiler=None):
op_system += "_ilp32" # https://wiki.linaro.org/Platform/arm64-ilp32

return "%s-%s" % (machine, op_system)


def check_output(cmd, folder=None, return_code=False):
tmp_file = tempfile.mktemp()
try:
process = subprocess.Popen("{} > {}".format(cmd, tmp_file), shell=True, stderr=PIPE, cwd=folder)
process.communicate()

if return_code:
return process.returncode

if process.returncode:
raise CalledProcessError(process.returncode, cmd)

output = load(tmp_file)
return output
finally:
try:
os.unlink(tmp_file)
except:
pass
4 changes: 2 additions & 2 deletions conans/client/tools/scm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import platform
import re
Expand All @@ -8,6 +7,7 @@

from six.moves.urllib.parse import quote_plus, unquote, urlparse

from conans.client.tools import check_output
from conans.client.tools.env import environment_append, no_op
from conans.client.tools.files import chdir
from conans.errors import ConanException
Expand Down Expand Up @@ -53,7 +53,7 @@ def run(self, command):
with chdir(self.folder) if self.folder else no_op():
with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op():
if not self._runner:
return decode_text(subprocess.check_output(command, shell=True, stderr=STDOUT).strip())
return check_output(command).strip()
else:
return self._runner(command)

Expand Down

0 comments on commit 1548364

Please sign in to comment.