diff options
Diffstat (limited to 'libbe/util')
-rw-r--r-- | libbe/util/__init__.py | 3 | ||||
-rw-r--r-- | libbe/util/encoding.py | 8 | ||||
-rw-r--r-- | libbe/util/id.py | 11 | ||||
-rw-r--r-- | libbe/util/plugin.py | 1 | ||||
-rw-r--r-- | libbe/util/subproc.py | 44 | ||||
-rw-r--r-- | libbe/util/tree.py | 3 | ||||
-rw-r--r-- | libbe/util/utility.py | 5 |
7 files changed, 51 insertions, 24 deletions
diff --git a/libbe/util/__init__.py b/libbe/util/__init__.py index b9166f0..78f615f 100644 --- a/libbe/util/__init__.py +++ b/libbe/util/__init__.py @@ -1,4 +1,5 @@ -# Copyright (C) 2009-2011 W. Trevor King <wking@drexel.edu> +# Copyright (C) 2009-2011 Chris Ball <cjb@laptop.org> +# W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. # diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py index 5950bb9..22a2e30 100644 --- a/libbe/util/encoding.py +++ b/libbe/util/encoding.py @@ -1,4 +1,5 @@ -# Copyright (C) 2008-2011 Gianluca Montecchi <gian@grys.it> +# Copyright (C) 2008-2011 Chris Ball <cjb@laptop.org> +# Gianluca Montecchi <gian@grys.it> # W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. @@ -49,11 +50,14 @@ def get_input_encoding(): return get_encoding() def get_output_encoding(): - return get_encoding() + return sys.__stdout__.encoding or get_encoding() def get_filesystem_encoding(): return get_encoding() +def get_argv_encoding(): + return get_encoding() + def known_encoding(encoding): """ >>> known_encoding("highly-unlikely-encoding") diff --git a/libbe/util/id.py b/libbe/util/id.py index 8d8c75c..c14dd90 100644 --- a/libbe/util/id.py +++ b/libbe/util/id.py @@ -1,4 +1,5 @@ -# Copyright (C) 2008-2011 Gianluca Montecchi <gian@grys.it> +# Copyright (C) 2008-2011 Chris Ball <cjb@laptop.org> +# Gianluca Montecchi <gian@grys.it> # W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. @@ -224,8 +225,8 @@ def _truncate(uuid, other_uuids, min_length=3): uuid : str The UUID to truncate. other_uuids : list of str - The other UUIDs which the truncation *might* (but doesn't) refer - to. + The other UUIDs which the truncation *might* refer to. May + contain `uuid`. min_length : int Avoid rapidly outdated truncations, even if they are unique now. @@ -255,8 +256,8 @@ def _expand(truncated_id, common, other_ids): `other_ids`. Not used by ``_expand``, but passed on to the matching exceptions if they occur. other_uuids : list of str - The other UUIDs which the truncation *might* (but doesn't) refer - to. + The other UUIDs which the truncation *might* refer to. May + contain `uuid`. Raises ------ diff --git a/libbe/util/plugin.py b/libbe/util/plugin.py index b6200fc..034b750 100644 --- a/libbe/util/plugin.py +++ b/libbe/util/plugin.py @@ -1,4 +1,5 @@ # Copyright (C) 2005-2011 Aaron Bentley <abentley@panoramicfeedback.com> +# Chris Ball <cjb@laptop.org> # Gianluca Montecchi <gian@grys.it> # Marien Zwart <marien.zwart@gmail.com> # W. Trevor King <wking@drexel.edu> diff --git a/libbe/util/subproc.py b/libbe/util/subproc.py index b10f84a..fde5af5 100644 --- a/libbe/util/subproc.py +++ b/libbe/util/subproc.py @@ -1,4 +1,5 @@ -# Copyright (C) 2009-2011 W. Trevor King <wking@drexel.edu> +# Copyright (C) 2009-2011 Chris Ball <cjb@laptop.org> +# W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. # @@ -21,6 +22,7 @@ Functions for running external commands in subprocesses. from subprocess import Popen, PIPE import sys +import types import libbe from encoding import get_encoding @@ -45,7 +47,8 @@ class CommandError(Exception): self.stderr = stderr def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,), - cwd=None, unicode_output=True, verbose=False, encoding=None): + cwd=None, shell=None, unicode_output=True, verbose=False, + encoding=None): """ expect should be a tuple of allowed exit codes. cwd should be the directory from which the command will be executed. When @@ -54,18 +57,29 @@ def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,), """ if cwd == None: cwd = '.' + if isinstance(shell, types.StringTypes): + list_args = ' '.split(args) # sloppy, but just for logging + str_args = args + else: + list_args = args + str_args = ' '.join(args) # sloppy, but just for logging if verbose == True: - print >> sys.stderr, '%s$ %s' % (cwd, ' '.join(args)) + print >> sys.stderr, '%s$ %s' % (cwd, str_args) try : if _POSIX: - q = Popen(args, stdin=PIPE, stdout=stdout, stderr=stderr, cwd=cwd) + if shell is None: + shell = False + q = Popen(args, stdin=PIPE, stdout=stdout, stderr=stderr, + shell=shell, cwd=cwd) else: assert _MSWINDOWS==True, 'invalid platform' + if shell is None: + shell = True # win32 don't have os.execvp() so have to run command in a shell q = Popen(args, stdin=PIPE, stdout=stdout, stderr=stderr, - shell=True, cwd=cwd) + shell=shell, cwd=cwd) except OSError, e: - raise CommandError(args, status=e.args[0], stderr=e) + raise CommandError(list_args, status=e.args[0], stderr=e) stdout,stderr = q.communicate(input=stdin) status = q.wait() if unicode_output == True: @@ -78,18 +92,18 @@ def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,), if verbose == True: print >> sys.stderr, '%d\n%s%s' % (status, stdout, stderr) if status not in expect: - raise CommandError(args, status, stdout, stderr) + raise CommandError(list_args, status, stdout, stderr) return status, stdout, stderr class Pipe (object): - """ - Simple interface for executing POSIX-style pipes based on the - subprocess module. The only complication is the adaptation of - subprocess.Popen._comminucate to listen to the stderrs of all - processes involved in the pipe, as well as the terminal process' - stdout. There are two implementations of Pipe._communicate, one - for MS Windows, and one for POSIX systems. The MS Windows - implementation is currently untested. + """Simple interface for executing POSIX-style pipes. + + Based on the `subprocess` module. The only complication is the + adaptation of `subprocess.Popen._communicate` to listen to the + stderrs of all processes involved in the pipe, as well as the + terminal process' stdout. There are two implementations of + `Pipe._communicate`, one for MS Windows, and one for POSIX + systems. The MS Windows implementation is currently untested. >>> p = Pipe([['find', '/etc/'], ['grep', '^/etc/ssh$']]) >>> p.stdout diff --git a/libbe/util/tree.py b/libbe/util/tree.py index f676b0b..6e2ffec 100644 --- a/libbe/util/tree.py +++ b/libbe/util/tree.py @@ -1,5 +1,6 @@ # Bugs Everywhere, a distributed bugtracker -# Copyright (C) 2008-2011 Gianluca Montecchi <gian@grys.it> +# Copyright (C) 2008-2011 Chris Ball <cjb@laptop.org> +# Gianluca Montecchi <gian@grys.it> # W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. diff --git a/libbe/util/utility.py b/libbe/util/utility.py index 3f9a1b0..0bdacb6 100644 --- a/libbe/util/utility.py +++ b/libbe/util/utility.py @@ -1,4 +1,5 @@ # Copyright (C) 2005-2011 Aaron Bentley <abentley@panoramicfeedback.com> +# Chris Ball <cjb@laptop.org> # Gianluca Montecchi <gian@grys.it> # W. Trevor King <wking@drexel.edu> # @@ -28,6 +29,10 @@ import shutil import tempfile import time import types +try: # import core module, Python >= 2.5 + from xml.etree import ElementTree +except ImportError: # look for non-core module + from elementtree import ElementTree import libbe if libbe.TESTING == True: |