summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
Diffstat (limited to 'assets')
-rwxr-xr-xassets/bin/ass5
-rwxr-xr-xassets/bin/check-truth11
-rwxr-xr-xassets/bin/truth2json37
3 files changed, 51 insertions, 2 deletions
diff --git a/assets/bin/ass b/assets/bin/ass
index 87b750d3..c82a2565 100755
--- a/assets/bin/ass
+++ b/assets/bin/ass
@@ -4,6 +4,7 @@ set -euf
DB="/krebs/db"
JOURNAL="$DB/truth"
+HERE=$(dirname $(readlink -f $0))
(cd $DB && git pull >/dev/null && echo "pulled new version")
@@ -11,10 +12,10 @@ METHOD="$1"; shift
case $METHOD in
"create")
- echo "`date --utc --rfc-3339=ns` create $1" | check-truth | tee -a $JOURNAL
+ echo "`date --utc --rfc-3339=ns` create $1" | $HERE/check-truth | tee -a $JOURNAL
;;
"set")
- echo "`date --utc --rfc-3339=ns` set $1 $2 $3" | check-truth | tee -a $JOURNAL
+ echo "`date --utc --rfc-3339=ns` set $1 $2 $3" | $HERE/check-truth | tee -a $JOURNAL
;;
*)
echo "you are made of stupid!"
diff --git a/assets/bin/check-truth b/assets/bin/check-truth
new file mode 100755
index 00000000..6b55fdcd
--- /dev/null
+++ b/assets/bin/check-truth
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -euf
+DB=${1-"/krebs/db/truth"}
+HERE=$(dirname $(readlink -f $0))
+read LINE
+if (cat $DB;echo $LINE) | $HERE/truth2json - 1>/dev/null ;then
+ echo "success" 1>&2
+ echo "$LINE"
+else
+ echo "you fail" 1>&2
+fi
diff --git a/assets/bin/truth2json b/assets/bin/truth2json
new file mode 100755
index 00000000..c1aac73c
--- /dev/null
+++ b/assets/bin/truth2json
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+import sys
+
+try:
+ db=sys.argv[1]
+except:
+ db="/krebs/db/truth"
+
+ret = {}
+
+
+if db is "-":
+ sys.stderr.write("Using stdin\n")
+ f = sys.stdin
+else:
+ sys.stderr.write("Using journal '%s'\n" % db)
+ f = open(db)
+
+for line in f:
+ lsplit = line.split()
+ date = ' '.join(lsplit[0:2])
+ cmd = lsplit[2]
+ target = lsplit[3]
+ if cmd == "create":
+ assert target not in ret, "Target '%s' already created!"
+ ret[target] = {}
+ elif cmd == "set":
+ key = lsplit[4]
+ value = ' '.join(lsplit[5:])
+ assert target in ret, "target '%s' not set yet!" % target
+ ret[target][key] = value
+ else:
+ raise AssertionError,"unknown command '%s'!"
+
+import json
+print json.dumps(ret,sort_keys=True,indent=4)