summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJochen Schmitt <Jochen@herr-schmitt.de>2010-09-01 00:30:49 +0200
committerJochen Schmitt <Jochen@herr-schmitt.de>2010-09-05 21:27:47 +0200
commit9d3a26ee290fe2d447ba034bf9e8387466cd1e79 (patch)
treed21d81a0e0071f74fcc4a5688c689e1c04bc7ba3
parent04780d691a87b32a77eb498ea4504162fcd67697 (diff)
downloadfedora-packager-9d3a26ee290fe2d447ba034bf9e8387466cd1e79.tar.gz
fedora-packager-9d3a26ee290fe2d447ba034bf9e8387466cd1e79.tar.xz
fedora-packager-9d3a26ee290fe2d447ba034bf9e8387466cd1e79.zip
Avoid ugly list output on _run_command error outputs
-rw-r--r--src/pyfedpkg/__init__.py59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 4c0b03d..f531c07 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -40,6 +40,9 @@ UPLOADEXTS = ['tar', 'gz', 'bz2', 'lzma', 'xz', 'Z', 'zip', 'tff', 'bin',
'cpio', 'jisp', 'egg', 'gem']
BRANCHFILTER = 'f\d\d\/master|master|el\d\/master|olpc\d\/master'
+spaces = re.compile(r'\s')
+cmdlist_pattern = re.compile(r'\[.*\]')
+
# Define our own error class
class FedpkgError(Exception):
pass
@@ -91,6 +94,35 @@ def _hash_file(file, hashtype):
input.close()
return sum.hexdigest()
+def _list_to_string(cmd):
+ """Convert a list to a string where eatch item is separate
+ by a blang
+ """
+
+ if type(cmd) == list:
+ return ' '.join(cmd)
+ else:
+ return cmd
+
+def _format_item(s):
+ temp = s.strip()
+ if temp.startswith('\'') & temp.endswith('\''):
+ temp = temp[1:-1]
+ if spaces.match(temp):
+ result = '\'%s\'' % temp
+ else:
+ result = temp
+ return result
+
+def _format_cmd(m):
+ s = m.group(0)
+ cmdliste = s[1:-1].split(',')
+ result = [_format_item(item) for item in cmdliste]
+ return ' '.join(result)
+
+def _format_err(e):
+ return re.sub(cmdlist_pattern, _format_cmd, str(e))
+
def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None):
"""Run the given command.
@@ -128,12 +160,11 @@ def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None):
# Check to see if we're on a real tty, if so, stream it baby!
if sys.stdout.isatty():
if pipe:
- log.debug('Running %s | %s directly on the tty' %
- (subprocess.list2cmdline(cmd),
- subprocess.list2cmdline(pipe)))
+ log.debug('Running ''%s | %s'' directly on the tty' %
+ (_list_to_string(cmd), _list_to_string(pipe)))
else:
- log.debug('Running %s directly on the tty' %
- subprocess.list2cmdline(cmd))
+ log.debug('Running ''%s'' directly on the tty' %
+ _list_to_string(cmd))
try:
if pipe:
# We're piping the stderr over too, which is probably a
@@ -155,18 +186,18 @@ def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None):
cwd=cwd)
except (subprocess.CalledProcessError,
OSError), e:
- raise FedpkgError(e)
+ raise FedpkgError(_format_err(e))
except KeyboardInterrupt:
raise FedpkgError()
else:
# Ok, we're not on a live tty, so pipe and log.
if pipe:
- log.debug('Running %s | %s and logging output' %
- (subprocess.list2cmdline(cmd),
- subprocess.list2cmdline(pipe)))
+ log.debug('Running ''%s | %s'' and logging output' %
+ (_list_to_string(cmd),
+ _list_to_string(pipe)))
else:
- log.debug('Running %s and logging output' %
- subprocess.list2cmdline(cmd))
+ log.debug('Running ''%s'' and logging output' %
+ _list_to_string(cmd))
try:
if pipe:
proc1 = subprocess.Popen(command, env=environ,
@@ -186,13 +217,13 @@ def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None):
cwd=cwd)
output, error = proc.communicate()
except OSError, e:
- raise FedpkgError(e)
+ raise FedpkgError(_format_err(e))
log.info(output)
if error:
log.error(error)
if proc.returncode:
- raise FedpkgError('Command %s returned code %s with error: %s' %
- (subprocess.list2cmdline(cmd),
+ raise FedpkgError('Command ''%s'' returned code %s with error: %s' %
+ (_list_to_string(cmd),
proc.returncode,
error))
return