diff options
author | Jochen Schmitt <Jochen@herr-schmitt.de> | 2010-09-15 21:27:00 +0200 |
---|---|---|
committer | Jochen Schmitt <Jochen@herr-schmitt.de> | 2010-09-15 23:10:01 +0200 |
commit | aa8685df8faba2a097f1ab154866599e48b6da4a (patch) | |
tree | a1544013b7f45be32cb316646d772f21c833ec52 | |
parent | 55049f2b70915df8969328316800243bd6ba27f4 (diff) | |
download | fedora-packager-rework.tar.gz fedora-packager-rework.tar.xz fedora-packager-rework.zip |
Try to avoid list-form output in error messagesrework
-rw-r--r-- | src/pyfedpkg/__init__.py | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index 97b6302..917bf58 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -29,6 +29,8 @@ import StringIO import OpenSSL import fnmatch +spaces = re.compile(r'\s') +cmdlist_pattern = re.compile(r'\[.*\]') # Define some global variables, put them here to make it easy to change LOOKASIDE = 'http://pkgs.fedoraproject.org/repo/pkgs' @@ -41,6 +43,8 @@ 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') + # Define our own error class class FedpkgError(Exception): pass @@ -104,6 +108,29 @@ def _delete(path): os.rmdir(os.path.join(root, name)) return +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(cmd): + if not type(cmd) is str: + return cmd + cmdliste = cmd[1:-1].split(',') + result = [_format_item(item) for item in cmdliste] + return ' '.join(result) + +def _format_cmdx(match): + return _format_cmd(match.group(0)) + +def _format_err(e): + return re.sub(cmdlist_pattern, _format_cmdx, str(e)) + def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None): """Run the given command. @@ -142,11 +169,10 @@ def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None): if sys.stdout.isatty(): if pipe: log.debug('Running %s | %s directly on the tty' % - (subprocess.list2cmdline(cmd), - subprocess.list2cmdline(pipe))) + (_format_cmd(cmd), _format_cmd(pipe))) else: log.debug('Running %s directly on the tty' % - subprocess.list2cmdline(cmd)) + _format_cmd(cmd)) try: if pipe: # We're piping the stderr over too, which is probably a @@ -168,18 +194,17 @@ 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))) + (_format_cmd(cmd), _format_cmd(pipe))) else: log.debug('Running %s and logging output' % - subprocess.list2cmdline(cmd)) + _format_cmd(cmd)) try: if pipe: proc1 = subprocess.Popen(command, env=environ, @@ -200,11 +225,11 @@ 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 proc.returncode: raise FedpkgError('Command %s returned code %s with error: %s' % - (subprocess.list2cmdline(cmd), + (_format_cmd(cmd), proc.returncode, error)) return @@ -289,13 +314,13 @@ def _srpmdetails(srpm): # get the name cmd = ['rpm', '-qp', '--qf', '%{NAME}', srpm] # Run the command - log.debug('Running: %s' % subprocess.list2cmdline(cmd)) + log.debug('Running: %s' % _format_cmd(cmd)) try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = proc.communicate() except OSError, e: - raise FedpkgError(e) + raise FedpkgError(_format_err(e)) name = output if error: raise FedpkgError('Error querying srpm: %s' % error) @@ -310,7 +335,7 @@ def _srpmdetails(srpm): stderr=subprocess.PIPE) output, error = proc.communicate() except OSError, e: - raise FedpkgError(e) + raise FedpkgError(_format_err(e)) if error: raise FedpkgError('Error querying srpm:' % error) contents = output.split() @@ -561,7 +586,7 @@ def get_latest_commit(module): stdout=subprocess.PIPE) output, error = proc.communicate() except OSError, e: - raise FedpkgError(e) + raise FedpkgError(_format_err(e)) if error: raise FedpkgError('Got an error finding head for %s: %s' % (module, error)) |