Added severity command
[be.git] / be
1 #!/usr/bin/env python
2 from libbe.cmdutil import *
3 from libbe.bugdir import tree_root, create_bug_dir
4 from libbe import names
5 import sys
6 import os
7 import commands
8 import commands.severity
9 __doc__ = """Bugs Everywhere - Distributed bug tracking
10
11 Supported commands
12  set-root: assign the root directory for bug tracking
13       new: Create a new bug
14      list: list bugs
15      show: show a particular bug
16     close: close a bug
17      open: re-open a bug
18  severity: %s
19
20 Unimplemented commands
21   comment: append a comment to a bug
22 """ % commands.severity.__desc__
23
24 def list_bugs(args):
25     active = True
26     severity = ("minor", "serious", "critical", "fatal")
27     def filter(bug):
28         if active is not None:
29             if bug.active != active:
30                 return False
31         if bug.severity not in severity:
32             return False
33         return True
34     all_bugs = list(tree_root(os.getcwd()).list())
35     bugs = [b for b in all_bugs if filter(b) ]
36     if len(bugs) == 0:
37         print "No matching bugs found"
38     for bug in bugs:
39         print bug_summary(bug, all_bugs)
40
41 def show_bug(args):
42     bug_dir = tree_root(os.getcwd())
43     if len(args) !=1:
44         raise UserError("Please specify a bug id.")
45     print bug_summary(get_bug(args[0], bug_dir), list(bug_dir.list()))
46
47 def set_root(args):
48     if len(args) != 1:
49         raise UserError("Please supply a directory path")
50     create_bug_dir(args[0])
51
52 def new_bug(args):
53     if len(args) != 1:
54         raise UserError("Please supply a summary message")
55     dir = tree_root(".")
56     bugs = (dir.list())
57     bug = dir.new_bug()
58     bug.creator = names.creator()
59     bug.severity = "minor"
60     bug.status = "open"
61     bug.summary = args[0]
62
63 def close_bug(args):
64     assert(len(args) == 1)
65     get_bug(args[0], tree_root('.')).status = "closed"
66
67 def open_bug(args):
68     assert(len(args) == 1)
69     get_bug(args[0], tree_root('.')).status = "open"
70
71 if len(sys.argv) == 1:
72     print __doc__
73 else:
74     try:
75         try:
76             cmd = {
77                 "list": list_bugs,
78                 "show": show_bug,
79                 "set-root": set_root,
80                 "new": new_bug,
81                 "close": close_bug,
82                 "open": open_bug,
83                 "severity": commands.severity.execute,
84             }[sys.argv[1]]
85         except KeyError, e:
86             raise UserError("Unknown command \"%s\"" % e.args[0])
87         cmd(sys.argv[2:])
88     except UserError, e:
89         print e
90         sys.exit(1)