Merge lp:~achiang/hydrazine/hydrazine-show-valid-named-enums into lp:hydrazine

Proposed by Alex Chiang
Status: Merged
Merged at revision: 99
Proposed branch: lp:~achiang/hydrazine/hydrazine-show-valid-named-enums
Merge into: lp:hydrazine
Diff against target: 56 lines (+9/-9)
1 file modified
bugclient (+9/-9)
To merge this branch: bzr merge lp:~achiang/hydrazine/hydrazine-show-valid-named-enums
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+79189@code.launchpad.net

Description of the change

  bugclient: add input validation for 'filter' command, other NamedEnums

  Give the NamedEnum() class a new method, 'show_valid()'.

  This gives us a standard way to handle error checking if the user
  enters an invalid enum.

  Harden the 'filter' command so it doesn't puke when you just type it
  without any arguments, such as the stack trace below:

        hydrazine(None)> filter
        Traceback (most recent call last):
          File "./bugclient", line 541, in <module>
            main(sys.argv)
          File "./bugclient", line 537, in main
            cmd.cmdloop()
          File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
            stop = self.onecmd(line)
          File "./bugclient", line 399, in onecmd
            return cmd.Cmd.onecmd(self, cmdline)
          File "/usr/lib/python2.7/cmd.py", line 219, in onecmd
            return func(arg)
          File "./bugclient", line 175, in do_filter
            if not (args[0]):
        IndexError: list index out of range

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

  vote approve
  review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bugclient'
2--- bugclient 2011-10-12 14:06:44 +0000
3+++ bugclient 2011-10-12 22:07:25 +0000
4@@ -33,6 +33,10 @@
5 def get_all(self):
6 return self.enums
7
8+ def show_valid(self):
9+ print "Sorry, valid entries are:"
10+ _show_columnated(self.enums)
11+
12 status_enum = NamedEnum(['Confirmed', 'Triaged', 'Fix Committed',
13 'Fix Released', 'In Progress', "Won't Fix",
14 'Incomplete', 'Invalid', 'New'])
15@@ -168,9 +172,8 @@
16 filter clear # remove all filters
17 """
18 args = line.split()
19- if not filter_enum.get(args[0]):
20- print 'Invalid filter. Valid filters are:'
21- _show_columnated(filter_enum.get_all())
22+ if not args or filter_enum.get(args[0]) == None:
23+ filter_enum.show_valid()
24 return
25
26 if args[0] == "clear":
27@@ -178,8 +181,7 @@
28 return
29 elif args[0] == "status":
30 if status_enum.get(' '.join(args[1:])) == None:
31- print 'invalid status, valid values are:'
32- _show_columnated(status_enum.get_all())
33+ status_enum.show_valid()
34 return
35 else:
36 # Normalize status, and toss old junk
37@@ -195,8 +197,7 @@
38 return
39 new_importance = importance_enum.get(line)
40 if new_importance is None:
41- print 'invalid importance, valid values are:'
42- _show_columnated(importance_enum.get_all())
43+ importance_enum.show_valid()
44 return
45 print '#%d changing importance %s => %s' % (self.bug.id, task.importance, new_importance)
46 task.importance = new_importance
47@@ -314,8 +315,7 @@
48 return
49 new_status = status_enum.get(line)
50 if new_status is None:
51- print 'invalid status, valid values are:'
52- _show_columnated(status_enum.get_all())
53+ status_enum.show_valid()
54 return
55 print '#%d changing status %s => %s' % (self.bug.id, task.status, new_status)
56 task.status = new_status

Subscribers

People subscribed via source and target branches

to all changes: