Skip to content

Commit

Permalink
ENH #234 use logging & log stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Sep 3, 2019
1 parent 3740438 commit 63456ec
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions apstools/utils.py
Expand Up @@ -65,6 +65,7 @@
import zipfile

from .filewriters import _rebuild_scan_command
from jupyter_core.tests.mocking import linux


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -583,17 +584,21 @@ def unix(command, raises=True):
default: `True`
"""
# TODO: confirm it is running on a unix system
# TODO: use logging package
# TODO: log any error output
process = subprocess.Popen(
command,
shell=True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
)
output, error = process.communicate()
return output, error

stdout, stderr = process.communicate()
if len(stderr) > 0:
emsg = f"unix({command}) returned error:\n{stderr}"
logger.error(emsg)
if raises:
raise RuntimeError(emsg)
return stdout, stderr


def unix_cmd(command_list, raises=True):
Expand All @@ -613,9 +618,9 @@ def unix_cmd(command_list, raises=True):
"""
msg = "'unix_cmd()' is deprecated"
msg += ", use 'unix()' instead, slightly different API"
logger.warning(msg)
if raises:
raise RuntimeWarning(msg)
logger.warning(msg)

process = subprocess.Popen(command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
Expand Down

0 comments on commit 63456ec

Please sign in to comment.