From 49a7771336ce09f6d42c7699ef32aecea0e83182 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 20:07:55 -0500 Subject: Initial directory restructuring to clarify dependencies --- libbe/command/due.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 libbe/command/due.py (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py new file mode 100644 index 0000000..0b8d1e9 --- /dev/null +++ b/libbe/command/due.py @@ -0,0 +1,108 @@ +# Copyright (C) 2009 W. Trevor King +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +"""Set bug due dates""" +from libbe import cmdutil, bugdir, utility +__desc__ = __doc__ + +DUE_TAG="DUE:" + +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): + """ + >>> import os + >>> bd = bugdir.SimpleBugDir() + >>> bd.save() + >>> os.chdir(bd.root) + >>> execute(["a"], manipulate_encodings=False) + No due date assigned. + >>> execute(["a", "Thu, 01 Jan 1970 00:00:00 +0000"], manipulate_encodings=False) + >>> execute(["a"], manipulate_encodings=False) + Thu, 01 Jan 1970 00:00:00 +0000 + >>> execute(["a", "none"], manipulate_encodings=False) # doctest: +NORMALIZE_WHITESPACE + >>> execute(["a"], manipulate_encodings=False) + No due date assigned. + >>> bd.cleanup() + """ + parser = get_parser() + options, args = parser.parse_args(args) + cmdutil.default_complete(options, args, parser, + bugid_args={0: lambda bug : bug.active==True}) + + if len(args) not in (1, 2): + raise cmdutil.UsageError('Incorrect number of arguments.') + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=manipulate_encodings, + root=dir) + bug = cmdutil.bug_from_id(bd, args[0]) + if len(args) == 1: + due_time = get_due(bug) + if due_time is None: + print "No due date assigned." + else: + print utility.time_to_str(due_time) + else: + if args[1] == "none": + remove_due(bug) + else: + due_time = utility.str_to_time(args[1]) + set_due(bug, due_time) + +def get_parser(): + parser = cmdutil.CmdOptionParser("be due BUG-ID [DATE]") + return parser + +longhelp=""" +If no DATE is specified, the bug's current due date is printed. If +DATE is specified, it will be assigned to the bug. +""" + +def help(): + return get_parser().help_str() + longhelp + +# internal helper functions + +def _generate_due_string(time): + return "%s%s" % (DUE_TAG, utility.time_to_str(time)) + +def _parse_due_string(string): + assert string.startswith(DUE_TAG) + return utility.str_to_time(string[len(DUE_TAG):]) + +# functions exposed to other modules + +def get_due(bug): + matched = [] + for line in bug.extra_strings: + if line.startswith(DUE_TAG): + matched.append(_parse_due_string(line)) + if len(matched) == 0: + return None + if len(matched) > 1: + raise Exception('Several due dates for %s?:\n %s' + % (bug.uuid, '\n '.join(matched))) + return matched[0] + +def remove_due(bug): + estrs = bug.extra_strings + for due_str in [s for s in estrs if s.startswith(DUE_TAG)]: + estrs.remove(due_str) + bug.extra_strings = estrs # reassign to notice change + +def set_due(bug, time): + remove_due(bug) + estrs = bug.extra_strings + estrs.append(_generate_due_string(time)) + bug.extra_strings = estrs # reassign to notice change -- cgit From c855cd95fb777e2eef36b9f4bc05a01d8dc571f8 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 08:45:20 -0500 Subject: Transitioned due to Command format --- libbe/command/due.py | 100 ++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py index 0b8d1e9..372f10a 100644 --- a/libbe/command/due.py +++ b/libbe/command/due.py @@ -13,73 +13,77 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""Set bug due dates""" -from libbe import cmdutil, bugdir, utility -__desc__ = __doc__ -DUE_TAG="DUE:" +import libbe +import libbe.command +import libbe.command.util +import libbe.util.utility -def execute(args, manipulate_encodings=True, restrict_file_access=False, - dir="."): - """ - >>> import os - >>> bd = bugdir.SimpleBugDir() - >>> bd.save() - >>> os.chdir(bd.root) - >>> execute(["a"], manipulate_encodings=False) +DUE_TAG = 'DUE:' + +class Due (libbe.command.Command): + """Set bug due dates + + >>> import sys + >>> import libbe.bugdir + >>> bd = libbe.bugdir.SimpleBugDir(memory=False) + >>> cmd = Due() + >>> cmd._setup_io = lambda i_enc,o_enc : None + >>> cmd.stdout = sys.stdout + + >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) No due date assigned. - >>> execute(["a", "Thu, 01 Jan 1970 00:00:00 +0000"], manipulate_encodings=False) - >>> execute(["a"], manipulate_encodings=False) + >>> ret = cmd.run(bd.storage, bd, {}, ['/a', 'Thu, 01 Jan 1970 00:00:00 +0000']) + >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) Thu, 01 Jan 1970 00:00:00 +0000 - >>> execute(["a", "none"], manipulate_encodings=False) # doctest: +NORMALIZE_WHITESPACE - >>> execute(["a"], manipulate_encodings=False) + >>> ret = cmd.run(bd.storage, bd, {}, ['/a', 'none']) + >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) No due date assigned. >>> bd.cleanup() """ - parser = get_parser() - options, args = parser.parse_args(args) - cmdutil.default_complete(options, args, parser, - bugid_args={0: lambda bug : bug.active==True}) - - if len(args) not in (1, 2): - raise cmdutil.UsageError('Incorrect number of arguments.') - bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings, - root=dir) - bug = cmdutil.bug_from_id(bd, args[0]) - if len(args) == 1: - due_time = get_due(bug) - if due_time is None: - print "No due date assigned." - else: - print utility.time_to_str(due_time) - else: - if args[1] == "none": - remove_due(bug) - else: - due_time = utility.str_to_time(args[1]) - set_due(bug, due_time) + name = 'due' + + def __init__(self, *args, **kwargs): + libbe.command.Command.__init__(self, *args, **kwargs) + self.requires_bugdir = True + self.args.extend([ + libbe.command.Argument( + name='bug-id', metavar='BUG-ID', + completion_callback=libbe.command.util.complete_bug_id), + libbe.command.Argument( + name='due', metavar='DUE', optional=True), + ]) -def get_parser(): - parser = cmdutil.CmdOptionParser("be due BUG-ID [DATE]") - return parser + def _run(self, storage, bugdir, **params): + bug,dummy_comment = libbe.command.util.bug_comment_from_user_id( + bugdir, params['bug-id']) + if params['due'] == None: + due_time = get_due(bug) + if due_time is None: + print >> self.stdout, 'No due date assigned.' + else: + print >> self.stdout, libbe.util.utility.time_to_str(due_time) + else: + if params['due'] == 'none': + remove_due(bug) + else: + due_time = libbe.util.utility.str_to_time(params['due']) + set_due(bug, due_time) -longhelp=""" + def _long_help(self): + return """ If no DATE is specified, the bug's current due date is printed. If DATE is specified, it will be assigned to the bug. """ -def help(): - return get_parser().help_str() + longhelp - # internal helper functions def _generate_due_string(time): - return "%s%s" % (DUE_TAG, utility.time_to_str(time)) + return "%s%s" % (DUE_TAG, libbe.util.utility.time_to_str(time)) def _parse_due_string(string): assert string.startswith(DUE_TAG) - return utility.str_to_time(string[len(DUE_TAG):]) + return libbe.util.utility.str_to_time(string[len(DUE_TAG):]) # functions exposed to other modules -- cgit From 1b9c628529848af370adbc67b5ba298236a1b86d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 23:15:58 -0500 Subject: Transitioned severity to Command-format, also added Command._get_*() The old .requires_* thing was rediculous. The new ._get_*() callbacks allow the caller to provide a means for getting the expensive structures, which the command can use, or not, as required. This will also make it easier to implement the completion callbacks. The callbacks should probably have matching .set_*() methods, to avoid the current cache tweaking cmd._storage = ... etc. But that can wait for now... --- libbe/command/due.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py index 372f10a..119115c 100644 --- a/libbe/command/due.py +++ b/libbe/command/due.py @@ -28,16 +28,17 @@ class Due (libbe.command.Command): >>> import libbe.bugdir >>> bd = libbe.bugdir.SimpleBugDir(memory=False) >>> cmd = Due() + >>> cmd._storage = bd.storage >>> cmd._setup_io = lambda i_enc,o_enc : None >>> cmd.stdout = sys.stdout - >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) + >>> ret = cmd.run(args=['/a']) No due date assigned. - >>> ret = cmd.run(bd.storage, bd, {}, ['/a', 'Thu, 01 Jan 1970 00:00:00 +0000']) - >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) + >>> ret = cmd.run(args=['/a', 'Thu, 01 Jan 1970 00:00:00 +0000']) + >>> ret = cmd.run(args=['/a']) Thu, 01 Jan 1970 00:00:00 +0000 - >>> ret = cmd.run(bd.storage, bd, {}, ['/a', 'none']) - >>> ret = cmd.run(bd.storage, bd, {}, ['/a']) + >>> ret = cmd.run(args=['/a', 'none']) + >>> ret = cmd.run(args=['/a']) No due date assigned. >>> bd.cleanup() """ @@ -45,7 +46,6 @@ class Due (libbe.command.Command): def __init__(self, *args, **kwargs): libbe.command.Command.__init__(self, *args, **kwargs) - self.requires_bugdir = True self.args.extend([ libbe.command.Argument( name='bug-id', metavar='BUG-ID', @@ -54,7 +54,8 @@ class Due (libbe.command.Command): name='due', metavar='DUE', optional=True), ]) - def _run(self, storage, bugdir, **params): + def _run(self, **params): + bugdir = self._get_bugdir() bug,dummy_comment = libbe.command.util.bug_comment_from_user_id( bugdir, params['bug-id']) if params['due'] == None: -- cgit From a1bd5432ffbf28bf2fadfed8a5b2db917f243344 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 15 Dec 2009 01:52:17 -0500 Subject: Transitioned tag to Command-format --- libbe/command/due.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py index 119115c..f3ad2f1 100644 --- a/libbe/command/due.py +++ b/libbe/command/due.py @@ -19,8 +19,10 @@ import libbe.command import libbe.command.util import libbe.util.utility + DUE_TAG = 'DUE:' + class Due (libbe.command.Command): """Set bug due dates -- cgit From cfae8a8302f06a84196700138d7ddbb25e91ea31 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 31 Dec 2009 14:32:39 -0500 Subject: Added UserInterface and other improved abstractions for command handling --- libbe/command/due.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py index f3ad2f1..2eb3194 100644 --- a/libbe/command/due.py +++ b/libbe/command/due.py @@ -29,19 +29,21 @@ class Due (libbe.command.Command): >>> import sys >>> import libbe.bugdir >>> bd = libbe.bugdir.SimpleBugDir(memory=False) - >>> cmd = Due() - >>> cmd._storage = bd.storage - >>> cmd._setup_io = lambda i_enc,o_enc : None - >>> cmd.stdout = sys.stdout + >>> io = libbe.command.StringInputOutput() + >>> io.stdout = sys.stdout + >>> ui = libbe.command.UserInterface(io=io) + >>> ui.storage_callbacks.set_storage(bd.storage) + >>> cmd = Due(ui=ui) - >>> ret = cmd.run(args=['/a']) + >>> ret = ui.run(cmd, args=['/a']) No due date assigned. - >>> ret = cmd.run(args=['/a', 'Thu, 01 Jan 1970 00:00:00 +0000']) - >>> ret = cmd.run(args=['/a']) + >>> ret = ui.run(cmd, args=['/a', 'Thu, 01 Jan 1970 00:00:00 +0000']) + >>> ret = ui.run(cmd, args=['/a']) Thu, 01 Jan 1970 00:00:00 +0000 - >>> ret = cmd.run(args=['/a', 'none']) - >>> ret = cmd.run(args=['/a']) + >>> ret = ui.run(cmd, args=['/a', 'none']) + >>> ret = ui.run(cmd, args=['/a']) No due date assigned. + >>> ui.cleanup() >>> bd.cleanup() """ name = 'due' -- cgit From 4d4283ecd654f1efb058cd7f7dba6be88b70ee92 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 1 Jan 2010 08:11:08 -0500 Subject: Updated copyright information --- libbe/command/due.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/command/due.py') diff --git a/libbe/command/due.py b/libbe/command/due.py index 2eb3194..4463455 100644 --- a/libbe/command/due.py +++ b/libbe/command/due.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009 W. Trevor King +# Copyright (C) 2009-2010 W. Trevor King # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -- cgit