From 4e5dc3888699076e46bdc1d94f901ca889b88b05 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 22 Jun 2009 16:27:46 -0400 Subject: Added `be list --sort *` for user-selectable sorting. Also added libbe.bug.cmp_last_modified, which handles part of 9ce2f015-8ea0-43a5-a03d-fc36f6d202fe. To do better we could extend the RCS framework. I also transcribed a few emails from the be-devel list onto their relavent bugs and closed a few bugs. Finally, I removed some left over InvalidValue cruft. --- becommands/comment.py | 4 ++++ becommands/list.py | 22 ++++++++++++++++++++-- becommands/set.py | 7 +------ 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'becommands') diff --git a/becommands/comment.py b/becommands/comment.py index 29e9f88..f7459dd 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -102,10 +102,14 @@ def execute(args, test=False): body+='\n' comment = parent.new_reply(body=body) + if options.content_type != None: + comment.content_type = options.content_type bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be comment ID [COMMENT]") + parser.add_option("-c", "--content-type", metavar="MIME", dest="content_type", + help="Set comment content-type (e.g. text/plain)", default=None) return parser longhelp=""" diff --git a/becommands/list.py b/becommands/list.py index 9f4e037..1f06569 100644 --- a/becommands/list.py +++ b/becommands/list.py @@ -19,6 +19,10 @@ from libbe import cmdutil, bugdir, bug import os __desc__ = __doc__ +# get a list of * for cmp_*() comparing two bugs. +AVAILABLE_CMPS = [fn[4:] for fn in dir(bug) if fn[:4] == 'cmp_'] +AVAILABLE_CMPS.remove("attr") # a cmp_* template. + def execute(args, test=False): """ >>> import os @@ -35,6 +39,13 @@ def execute(args, test=False): complete(options, args, parser) if len(args) > 0: raise cmdutil.UsageError("Too many arguments.") + cmp_list = [] + if options.sort_by != None: + for cmp in options.sort_by.split(','): + if cmp not in AVAILABLE_CMPS: + raise cmdutil.UserError("Invalid sort on '%s'.\nValid sorts:\n %s" + % (cmp, '\n '.join(AVAILABLE_CMPS))) + cmp_list.append(eval('bug.cmp_%s' % cmp)) bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test) bd.load_all_bugs() @@ -115,7 +126,6 @@ def execute(args, test=False): print "No matching bugs found" def list_bugs(cur_bugs, title=None, just_uuids=False, xml=False): - cur_bugs.sort(bug.cmp_full) if xml == True: print "" if len(cur_bugs) > 0: @@ -130,7 +140,13 @@ def execute(args, test=False): print bg.string(shortlist=True) if xml == True: print "" - + + # sort bugs + cmp_list.extend(bug.DEFAULT_CMP_FULL_CMP_LIST) + cmp_fn = bug.BugCompoundComparator(cmp_list=cmp_list) + bugs.sort(cmp_fn) + + # print list of bugs list_bugs(bugs, just_uuids=options.uuids, xml=options.xml) def get_parser(): @@ -143,6 +159,8 @@ def get_parser(): help="List options matching ASSIGNED", default=None) parser.add_option("-t", "--target", metavar="TARGET", dest="target", help="List options matching TARGET", default=None) + parser.add_option("-S", "--sort", metavar="SORT-BY", dest="sort_by", + help="Adjust bug-sort criteria with comma-separated list SORT-BY. e.g. \"--sort creator,time\". Available criteria: %s" % ','.join(AVAILABLE_CMPS), default=None) # boolean options. All but uuids and xml are special cases of long forms bools = (("u", "uuids", "Only print the bug UUIDS"), ("w", "wishlist", "List bugs with 'wishlist' severity"), diff --git a/becommands/set.py b/becommands/set.py index b8a125e..c8bbe4f 100644 --- a/becommands/set.py +++ b/becommands/set.py @@ -63,12 +63,7 @@ def execute(args, test=False): msg += '\n '.join(bd.settings_properties) raise cmdutil.UserError(msg) old_setting = bd.settings.get(args[0]) - try: - setattr(bd, args[0], args[1]) - except bugdir.InvalidValue, e: - bd.settings[args[0]] = old_setting - bd.save() - raise cmdutil.UserError(e) + setattr(bd, args[0], args[1]) else: del bd.settings[args[0]] bd.save() -- cgit