aboutsummaryrefslogtreecommitdiffstats
path: root/be
blob: 5c0490614c31c64d25a8fa4b8ed6cd2c35e201fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
from libbe.cmdutil import *
from libbe.bugdir import tree_root, create_bug_dir
from libbe import names
import sys
import os
import commands
import commands.severity
__doc__ = """Bugs Everywhere - Distributed bug tracking

Supported commands
 set-root: assign the root directory for bug tracking
      new: Create a new bug
     list: list bugs
     show: show a particular bug
    close: close a bug
     open: re-open a bug
 severity: %s

Unimplemented commands
  comment: append a comment to a bug
""" % commands.severity.__desc__

def list_bugs(args):
    active = True
    severity = ("minor", "serious", "critical", "fatal")
    def filter(bug):
        if active is not None:
            if bug.active != active:
                return False
        if bug.severity not in severity:
            return False
        return True
    all_bugs = list(tree_root(os.getcwd()).list())
    bugs = [b for b in all_bugs if filter(b) ]
    if len(bugs) == 0:
        print "No matching bugs found"
    for bug in bugs:
        print bug_summary(bug, all_bugs)

def show_bug(args):
    bug_dir = tree_root(os.getcwd())
    if len(args) !=1:
        raise UserError("Please specify a bug id.")
    print bug_summary(get_bug(args[0], bug_dir), list(bug_dir.list()))

def set_root(args):
    if len(args) != 1:
        raise UserError("Please supply a directory path")
    create_bug_dir(args[0])

def new_bug(args):
    if len(args) != 1:
        raise UserError("Please supply a summary message")
    dir = tree_root(".")
    bugs = (dir.list())
    bug = dir.new_bug()
    bug.creator = names.creator()
    bug.severity = "minor"
    bug.status = "open"
    bug.summary = args[0]

def close_bug(args):
    assert(len(args) == 1)
    get_bug(args[0], tree_root('.')).status = "closed"

def open_bug(args):
    assert(len(args) == 1)
    get_bug(args[0], tree_root('.')).status = "open"

if len(sys.argv) == 1:
    print __doc__
else:
    try:
        try:
            cmd = {
                "list": list_bugs,
                "show": show_bug,
                "set-root": set_root,
                "new": new_bug,
                "close": close_bug,
                "open": open_bug,
                "severity": commands.severity.execute,
            }[sys.argv[1]]
        except KeyError, e:
            raise UserError("Unknown command \"%s\"" % e.args[0])
        cmd(sys.argv[2:])
    except UserError, e:
        print e
        sys.exit(1)