Skip to content
Permalink
Browse files

Werk-Tool: Introduce new field "Knowledge"

Change-Id: Ic09ed5a9db7aef201ac96d730f8b4c9a4a448f01
  • Loading branch information
LarsMichelsen committed Sep 26, 2019
1 parent 687ee40 commit d49cc3acdf3b91ff68a3260203c1ad23fb8bc581
Showing with 58 additions and 14 deletions.
  1. +6 −0 .werks/config
  2. +52 −14 werk
@@ -55,4 +55,10 @@ compatible = [
("incomp", "Incompatible"),
]

knowledge = [
( "undoc", "User manual state unknown" ),
( "todoc", "Needs to be added to user manual" ),
( "doc", "Is reflected in user manual or does not need to" ),
]

online_url = "http://mathias-kettner.de/check_mk_werks.php?werk_id=%d"
66 werk
@@ -12,6 +12,7 @@ if sys.stdout.isatty():
tty_cyan = '\033[36m'
tty_white = '\033[37m'
tty_bgred = '\033[41m'
tty_bggreen = '\033[42m'
tty_bgyellow = '\033[43m'
tty_bgblue = '\033[44m'
tty_bgmagenta = '\033[45m'
@@ -31,6 +32,8 @@ else:
tty_magenta = ''
tty_cyan = ''
tty_white = ''
tty_bgred = ''
tty_bggreen = ''
tty_bgblue = ''
tty_bgmagenta = ''
tty_bgcyan = ''
@@ -150,6 +153,7 @@ def load_werk(werkid):
"component": "general",
"compatible": "compat",
"edition": "cre",
"knowledge": "undoc",
}

f = open(str(werkid))
@@ -271,6 +275,7 @@ where COMMAND is one of:
delete #.. - delete werk(s)
grep [-v] KW1 KW2... - show werks containing all of the given keywords (-v: verbose)
edit [#] - open werk # in editor (or newest werk)
knowledge|knw ID STATE - change the knowlege state of a werk
blame [#] - show who worked on a werk
url # - show the online URL of werk #
@@ -296,16 +301,26 @@ def list_werk(werk):
lines, cols = get_tty_size()
title = werk["title"][:cols - 45]
sys.stdout.write(
"%s %-9s %s %3s %-13s %-6s %s%s%s %-8s %s%s%s\n" %
(format_werk_id(werk["id"]), time.strftime("%F", time.localtime(int(werk["date"]))),
colored_class(werk["class"], 8), werk["edition"], werk["component"], werk["compatible"],
tty_bold, werk["level"], tty_normal, werk["version"], bold, title, tty_normal))
"%s %-9s %s %s %3s %-13s %-6s %s%s%s %-8s %s%s%s\n" %
(format_werk_id(werk["id"]), time.strftime(
"%F", time.localtime(int(werk["date"]))), colored_class(werk["class"], 8),
format_knw_state(werk["knowledge"]) if werk["class"] == "feature" else " ",
werk["edition"], werk["component"], werk["compatible"], tty_bold, werk["level"],
tty_normal, werk["version"], bold, title, tty_normal))


def format_werk_id(werk_id):
return tty_bgwhite + tty_blue + ("#%05d" % int(werk_id)) + tty_normal


def format_knw_state(knw_state):
return {
"undoc": tty_bgblue + tty_white + tty_bold + "?D?" + tty_normal,
"todoc": tty_bgred + tty_white + tty_bold + "!D!" + tty_normal,
"doc": tty_bggreen + tty_white + tty_bold + " D " + tty_normal,
}.get(knw_state, knw_state)


def colored_class(classname, digits):
if classname == "fix":
return tty_bold + tty_red + ("%-" + str(digits) + "s") % classname + tty_normal
@@ -337,14 +352,9 @@ def main_list(args, format):
continue

hit = False
for tp, values in [
("edition", editions),
("component", all_components()),
("level", levels),
("class", classes),
("version", versions),
("compatible", compatible),
]:
for tp, values in [("edition", editions), ("component", all_components()),
("level", levels), ("class", classes), ("version", versions),
("compatible", compatible), ("knowledge", knowledge)]:
for v in values:
if isinstance(v, tuple):
v = v[0]
@@ -357,7 +367,9 @@ def main_list(args, format):
if hit:
break
if not hit:
bail_out("No such edition, component, state, class or target version: %s" % a)
bail_out(
"No such edition, component, state, class, knowledge state or target version: %s" %
a)

# Filter
newwerks = []
@@ -542,6 +554,10 @@ def main_new(args):
werk["component"] = input_choice("Component", get_edition_components(werk["edition"]))
werk["level"] = input_choice("Level", levels)
werk["compatible"] = input_choice("Compatible", compatible)
if werk["class"] == "feature":
werk["knowledge"] = "undoc" # Don't ask. Developers must not deal with this
else:
werk["knowledge"] = "doc" # Bug and security fixes never get documented in user manual
werk["description"] = u"\n"

g_werks[werk["id"]] = werk
@@ -679,6 +695,25 @@ def main_grep(args):
sys.stdout.write(" %s\n" % lines[x])


def main_knowledge(args):
if len(args) != 2:
bail_out("Usage: werk knowledge ID undoc|todoc|doc")
werkid = args[0]
if not werk_exists(werkid):
bail_out("No such werk.")
werkid = int(werkid)
save_last_werkid(werkid)

knw_state = args[1]
if knw_state not in [c[0] for c in knowledge]:
bail_out("Invalid knowledge state. Allowed are %s." %
", ".join(["%s (%s)" % c for c in knowledge]))

werk = load_werk(werkid)
werk["knowledge"] = knw_state
save_werk(werk)


def main_edit(args):
if len(args) == 0:
werkid = int(g_last_werk)
@@ -709,7 +744,7 @@ def edit_werk(werkid, custom_files=[], commit=True):
if not editor:
bail_out("No editor available (please set EDITOR).\n")

if 0 == os.system("bash -c '%s +10 %s'" % (editor, werkid)): # nosec
if 0 == os.system("bash -c '%s +11 %s'" % (editor, werkid)): # nosec
load_werks()
werk = g_werks[werkid]
git_add(g_werks[werkid])
@@ -860,6 +895,7 @@ edition_components = {}
classes = []
levels = []
compatible = []
knowledge = []
online_url = None

versions = set([])
@@ -881,6 +917,8 @@ commands = {
"delete": main_delete,
"grep": main_grep,
"edit": main_edit,
"knowledge": main_knowledge,
"knw": main_knowledge,
"ids": main_fetch_ids,
"pick": main_pick,
"cherry-pick": main_pick,

0 comments on commit d49cc3a

Please sign in to comment.
You can’t perform that action at this time.