Module: check_mk
Branch: master
Commit: 43c5a2d85eed9934bad2586b3847059b660c3a2c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=43c5a2d85eed99…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Feb 17 14:20:31 2012 +0100
gb: new csv export function
---
.bugs/655 | 1 +
.bugs/config | 2 +-
gb | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/.bugs/655 b/.bugs/655
index de0fa8b..d4d5361 100644
--- a/.bugs/655
+++ b/.bugs/655
@@ -3,6 +3,7 @@ Component: multisite
State: open
Date: 2012-02-15 08:51:28
Targetversion: future
+Effort: 10
Class: bug
The background colors are broken in the view editor.
diff --git a/.bugs/config b/.bugs/config
index 9bbb6eb..9433a76 100644
--- a/.bugs/config
+++ b/.bugs/config
@@ -8,7 +8,7 @@ states = {
}
components = [
- "core",
+ ( "core", "Core Modules, Setup, etc." ),
"checks",
"multisite",
"livestatus",
diff --git a/gb b/gb
index fa90c9d..3072aae 100755
--- a/gb
+++ b/gb
@@ -220,7 +220,7 @@ def show_bug(bug):
list_bug(bug)
sys.stdout.write("\n%s\n" % bug["description"])
-def main_list(args):
+def main_list(args, format):
bugs = g_bugs.values()
# arguments are tags from state, component and class. Multiple values
@@ -243,6 +243,8 @@ def main_list(args):
( "targetversion", targetversions),
]:
for v in values:
+ if type(v) == tuple:
+ v = v[0]
if v.startswith(a):
entries = filters.get(tp, [])
entries.append(v)
@@ -273,10 +275,53 @@ def main_list(args):
newbugs.reverse()
# Output
- for bug in bugs:
- list_bug(bug)
+ if format == "console":
+ for bug in bugs:
+ list_bug(bug)
+ else:
+ output_csv(bugs)
+# CSV Table has the following columns:
+# Component;ID;Title;Class;Effort
+def output_csv(bugs):
+ def line(*l):
+ sys.stdout.write('"' + '";"'.join(map(str, l)) +
'"\n')
+
+ nr = 1
+ for entry in components:
+ if len(entry) == 2:
+ name, alias = entry
+ else:
+ name = entry
+ alias = entry
+
+ line("", "", "", "", "")
+
+ total_effort = 0
+ for bug in bugs:
+ if bug["component"] == name:
+ total_effort += bug_effort(bug)
+ line("", "%d. %s" % (nr, alias), "", total_effort)
+ nr += 1
+
+ for bug in bugs:
+ if bug["component"] == name:
+ line(bug["id"], bug["title"], bug_class(bug),
bug_effort(bug))
+ line("", bug["description"].replace("\n",
" ").replace('"', "'"), "", "")
+
+def bug_class(bug):
+ cl = bug["class"]
+ for entry in classes:
+ if entry == cl:
+ return cl
+ elif type(entry) == tuple and entry[0] == cl:
+ return entry[1]
+ return cl
+
+def bug_effort(bug):
+ return int(bug.get("effort", "0"))
+
def main_show(args):
ids = args
if len(ids) == 0:
@@ -556,7 +601,8 @@ if len(sys.argv) < 2:
cmd = sys.argv[1]
commands = {
- "list" : main_list,
+ "list" : lambda args: main_list(args, "console"),
+ "export" : lambda args: main_list(args, "csv"),
"show" : main_show,
"new" : main_new,
"resolve" : main_resolve,
@@ -581,7 +627,7 @@ if len(hits) < 1:
elif len(hits) > 1:
sys.stderr.write("Command '%s' is ambigous. Possible are: %s\n" %
\
- ", ".join([ n for (n,f) in hits]))
+ (cmd, ", ".join([ n for (n,f) in hits])))
else:
hits[0][1](sys.argv[2:])