diff options
-rw-r--r-- | .be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/77399855-6300-41a8-91a3-decbb915a3ff/values | 2 | ||||
-rw-r--r-- | libbe/bug.py | 6 | ||||
-rw-r--r-- | libbe/command/import_xml.py | 2 | ||||
-rw-r--r-- | libbe/storage/vcs/base.py | 2 | ||||
-rw-r--r-- | libbe/storage/vcs/git.py | 2 | ||||
-rw-r--r-- | libbe/ui/command_line.py | 46 | ||||
-rw-r--r-- | libbe/ui/util/user.py | 36 | ||||
-rw-r--r-- | libbe/util/encoding.py | 5 | ||||
-rw-r--r-- | libbe/util/subproc.py | 16 |
9 files changed, 82 insertions, 35 deletions
diff --git a/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/77399855-6300-41a8-91a3-decbb915a3ff/values b/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/77399855-6300-41a8-91a3-decbb915a3ff/values index 30d4df6..0f32345 100644 --- a/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/77399855-6300-41a8-91a3-decbb915a3ff/values +++ b/.be/bea86499-824e-4e77-b085-2d581fa9ccab/bugs/77399855-6300-41a8-91a3-decbb915a3ff/values @@ -5,7 +5,7 @@ extra_strings: severity: target -status: open +status: fixed summary: '1.0' diff --git a/libbe/bug.py b/libbe/bug.py index 6d3d836..adccf21 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -359,7 +359,7 @@ class Bug (settings_object.SavedSettingsObject): >>> bugB.xml(show_comments=True) == xml True >>> bugB.explicit_attrs # doctest: +NORMALIZE_WHITESPACE - ['severity', 'status', 'creator', 'created', 'summary'] + ['severity', 'status', 'creator', 'time', 'summary'] >>> len(list(bugB.comments())) 3 """ @@ -395,6 +395,10 @@ class Bug (settings_object.SavedSettingsObject): if child.tag == 'uuid': uuid = text continue # don't set the bug's uuid tag. + elif child.tag == 'created': + self.time = utility.str_to_time(text) + self.explicit_attrs.append('time') + continue elif child.tag == 'extra-string': estrs.append(text) continue # don't set the bug's extra_string yet. diff --git a/libbe/command/import_xml.py b/libbe/command/import_xml.py index bd25372..b4da2fd 100644 --- a/libbe/command/import_xml.py +++ b/libbe/command/import_xml.py @@ -184,7 +184,7 @@ class Import_XML (libbe.command.Command): except KeyError: old = None if old == None: - bd.append(new) + bugdir.append(new) else: old.load_comments(load_full=True) old.merge(new, accept_changes=accept_changes, diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index aba6159..3ff6e7e 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -537,7 +537,7 @@ class VCS (libbe.storage.base.VersionedStorage): self.user_id = self._vcs_get_user_id() if self.user_id == None: # guess missing info - name = libbe.ui.util.user.get_fallback_username() + name = libbe.ui.util.user.get_fallback_fullname() email = libbe.ui.util.user.get_fallback_email() self.user_id = libbe.ui.util.user.create_user_id(name, email) return self.user_id diff --git a/libbe/storage/vcs/git.py b/libbe/storage/vcs/git.py index 5c17303..6de1d56 100644 --- a/libbe/storage/vcs/git.py +++ b/libbe/storage/vcs/git.py @@ -74,7 +74,7 @@ class Git(base.VCS): if name != '' or email != '': # got something! # guess missing info, if necessary if name == '': - name = _user.get_fallback_username() + name = _user.get_fallback_fullname() if email == '': email = _user.get_fallback_email() return _user.create_user_id(name, email) diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py index 5f42147..52daa4b 100644 --- a/libbe/ui/command_line.py +++ b/libbe/ui/command_line.py @@ -29,6 +29,8 @@ import libbe.command import libbe.command.util import libbe.version import libbe.ui.util.pager +import libbe.util.encoding + if libbe.TESTING == True: import doctest @@ -86,11 +88,11 @@ class CmdOptionParser(optparse.OptionParser): if '_' in name: # reconstruct original option name options[name.replace('_', '-')] = options.pop(name) for name,value in options.items(): + argument = None + option = self._option_by_name[name] + if option.arg != None: + argument = option.arg if value == '--complete': - argument = None - option = self._option_by_name[name] - if option.arg != None: - argument = option.arg fragment = None indices = [i for i,arg in enumerate(args) if arg == '--complete'] @@ -108,22 +110,28 @@ class CmdOptionParser(optparse.OptionParser): if i+1 < len(args): fragment = args[i+1] self.complete(argument, fragment) + elif argument is not None: + value = self.process_raw_argument(argument=argument, value=value) + options[name] = value for i,arg in enumerate(parsed_args): + if i > 0 and self.command.name == 'be': + break # let this pass through for the command parser to handle + elif i < len(self.command.args): + argument = self.command.args[i] + elif len(self.command.args) == 0: + break # command doesn't take arguments + else: + argument = self.command.args[-1] + if argument.repeatable == False: + raise libbe.command.UserError('Too many arguments') if arg == '--complete': - if i > 0 and self.command.name == 'be': - break # let this pass through for the command parser to handle - elif i < len(self.command.args): - argument = self.command.args[i] - elif len(self.command.args) == 0: - break # command doesn't take arguments - else: - argument = self.command.args[-1] - if argument.repeatable == False: - raise libbe.command.UserError('Too many arguments') fragment = None if i < len(parsed_args) - 1: fragment = parsed_args[i+1] self.complete(argument, fragment) + else: + value = self.process_raw_argument(argument=argument, value=arg) + parsed_args[i] = value if len(parsed_args) > len(self.command.args) \ and self.command.args[-1].repeatable == False: raise libbe.command.UserError('Too many arguments') @@ -154,6 +162,16 @@ class CmdOptionParser(optparse.OptionParser): print >> self.command.stdout, '\n'.join(comps) raise CallbackExit + def process_raw_argument(self, argument, value): + if value == argument.default: + return value + if argument.type == 'string': + if not hasattr(self, 'argv_encoding'): + self.argv_encoding = libbe.util.encoding.get_argv_encoding() + return unicode(value, self.argv_encoding) + return value + + class BE (libbe.command.Command): """Class for parsing the command line arguments for `be`. This class does not contain a useful _run() method. Call this diff --git a/libbe/ui/util/user.py b/libbe/ui/util/user.py index 35665e4..5649fd9 100644 --- a/libbe/ui/util/user.py +++ b/libbe/ui/util/user.py @@ -28,32 +28,54 @@ are human-readable tags refering to objects. try: from email.utils import formataddr, parseaddr -except ImportErrror: # adjust to old python < 2.5 +except ImportErrror: # adjust to old python < 2.5 from email.Utils import formataddr, parseaddr import os +try: + import pwd +except ImportError: # handle non-Unix systems + pwd = None import re from socket import gethostname import libbe import libbe.storage.util.config + def get_fallback_username(): """Return a username extracted from environmental variables. """ name = None - for env in ["LOGNAME", "USERNAME"]: + for env in ['LOGNAME', 'USERNAME']: + if os.environ.has_key(env): + name = os.environ[env] + break + if name is None and pwd: + pw_ent = pwd.getpwuid(os.getuid()) + name = pw_ent.pw_name + assert name is not None + return name + +def get_fallback_fullname(): + """Return a full name extracted from environmental variables. + """ + name = None + for env in ['FULLNAME']: if os.environ.has_key(env): name = os.environ[env] break - assert name != None + if pwd and not name: + pw_ent = pwd.getpwuid(os.getuid()) + name = pw_ent.pw_gecos.split(',', 1)[0] + if not name: + name = get_fallback_username() return name def get_fallback_email(): """Return an email address extracted from environmental variables. """ - hostname = gethostname() - name = get_fallback_username() - return "%s@%s" % (name, hostname) + return os.getenv('EMAIL') or '%s@%s' % ( + get_fallback_username(), gethostname()) def create_user_id(name, email=None): """Create a user ID string from given `name` and `email` strings. @@ -122,7 +144,7 @@ def get_user_id(storage=None): user = storage.get_user_id() if user != None: return user - name = get_fallback_username() + name = get_fallback_fullname() email = get_fallback_email() user = create_user_id(name, email) return user diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py index 5950bb9..3cc425d 100644 --- a/libbe/util/encoding.py +++ b/libbe/util/encoding.py @@ -49,11 +49,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/subproc.py b/libbe/util/subproc.py index b10f84a..412ed36 100644 --- a/libbe/util/subproc.py +++ b/libbe/util/subproc.py @@ -82,14 +82,14 @@ def invoke(args, stdin=None, stdout=PIPE, stderr=PIPE, expect=(0,), 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 |