Module: check_mk
Branch: master
Commit: e9725ef62d4ac2146ca12d53ac7b34dd2995ed49
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e9725ef62d4ac2…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Nov 5 12:37:48 2013 +0100
werk new/edit now able to process custom files
---
werk | 42 +++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/werk b/werk
index 3b9c9d2..8d3e4e2 100755
--- a/werk
+++ b/werk
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, os, time, termios, tty
+import sys, os, time, termios, tty, subprocess
# colored output, if stdout is a tty
if sys.stdout.isatty():
@@ -63,7 +63,8 @@ def bail_out(text):
sys.exit(1)
def goto_werksdir():
- base_dir = os.path.abspath('.')
+ global g_base_dir
+ g_base_dir = os.path.abspath('.')
while not os.path.exists(".werks") and os.path.abspath('.') !=
'/':
os.chdir("..")
@@ -233,14 +234,28 @@ def save_werk(werk):
def git_add(werk):
os.system("git add %d" % werk["id"])
-def git_commit(werk):
+def git_commit(werk, custom_files):
title = werk["title"]
for classid, classname, prefix in classes:
if werk["class"] == classid:
if prefix:
title = "%s %s" % (prefix, title)
- os.system("git commit -a -m %s" % quote_shell_string(title +
"\n\n" + werk["description"]))
+ if custom_files:
+ files_to_commit = custom_files
+ default_files = [ ".werks", "ChangeLog" ]
+ # Get top level
+ info = subprocess.Popen(["git", "rev-parse",
"--show-toplevel"], stdout=subprocess.PIPE)
+ git_top_level = info.communicate()[0].split()[0]
+ for entry in default_files:
+ files_to_commit.append("%s/%s" % (git_top_level, entry))
+
+ os.chdir(g_base_dir)
+ os.system("git commit %s -m %s" % ("
".join(files_to_commit),
+ quote_shell_string(title + "\n\n" +
werk["description"])))
+
+ else:
+ os.system("git commit -a -m %s" % quote_shell_string(title +
"\n\n" + werk["description"]))
def quote_shell_string(s):
return "'" + s.replace("'",
"'\"'\"'") + "'"
@@ -480,7 +495,7 @@ def main_new(args):
werk = {}
werk["id"] = next_werk_id()
werk["date"] = int(time.time())
- werk["version"] = g_current_version
+ werk["version"] = g_current_version
werk["title"] = get_input("Title")
if werk["title"] == "":
sys.stderr.write("Cancelled.\n")
@@ -493,7 +508,7 @@ def main_new(args):
g_werks[werk["id"]] = werk
save_werk(werk)
invalidate_my_werkid(werk["id"])
- edit_werk(werk["id"])
+ edit_werk(werk["id"], args)
sys.stdout.write("Werk saved with id %d.\n" % werk["id"])
@@ -605,15 +620,20 @@ def main_edit(args):
werkid = int(g_last_werk)
if werkid == None:
bail_out("No last werk. Please specify id.")
-
else:
- werkid = int(args[0])
+ try:
+ werkid = int(args[0])
+ args = args[1:]
+ except:
+ werkid = int(g_last_werk)
+ if werkid == None:
+ bail_out("No last werk. Please specify id.")
- edit_werk(werkid)
+ edit_werk(werkid, args)
save_last_werkid(werkid)
-def edit_werk(werkid):
+def edit_werk(werkid, custom_files = []):
if not os.path.exists(str(werkid)):
bail_out("No werk with this id.")
editor = os.getenv("EDITOR")
@@ -630,7 +650,7 @@ def edit_werk(werkid):
werk = g_werks[werkid]
git_add(g_werks[werkid])
rewrite_changelog()
- git_commit(werk)
+ git_commit(werk, custom_files)
def main_commit(args):