summaryrefslogtreecommitdiffstats
path: root/var/lib
diff options
context:
space:
mode:
authorSergey Lukin <sergej.lukin@gmail.com>2015-12-04 09:30:06 +0200
committerSergey Lukin <sergej.lukin@gmail.com>2015-12-04 09:30:06 +0200
commit6d3d30af5f6cdb789de02909fc0d5800151d8fa1 (patch)
tree8076d34295a8eb359ec5890e6e7c9fc2fcb07376 /var/lib
parent7b24b7b03b6e69f6339282fad25c24fcc4e103ad (diff)
downloadbuild-errors-6d3d30af5f6cdb789de02909fc0d5800151d8fa1.tar.bz2
build-errors-6d3d30af5f6cdb789de02909fc0d5800151d8fa1.tar.xz
php replaced with haserl (no need to run php for several lines of code)
Diffstat (limited to 'var/lib')
-rw-r--r--var/lib/build-errors/scripts/save-build-error.lua56
-rw-r--r--var/lib/build-errors/scripts/save-build-error.sh1
-rw-r--r--var/lib/build-errors/sqlite/build-errors.dbbin0 -> 81920 bytes
3 files changed, 57 insertions, 0 deletions
diff --git a/var/lib/build-errors/scripts/save-build-error.lua b/var/lib/build-errors/scripts/save-build-error.lua
new file mode 100644
index 0000000..12d489a
--- /dev/null
+++ b/var/lib/build-errors/scripts/save-build-error.lua
@@ -0,0 +1,56 @@
+#!/usr/bin/lua
+
+local dbfile = '/var/lib/build-errors/sqlite/build-errors.db'
+
+cjson = require "cjson"
+sqlite3 = require "lsqlite3"
+
+local input = io.stdin:read()
+-- temporary
+-- input = '{"hostname":"build-edge-armhf","pkgname":"msmtp","logurl":"http://build.alpinelinux.org/buildlogs/build-edge-armhf/main/msmtp/msmtp-1.6.3-r0.log"}'
+
+local function try_decoding_json(json)
+ return pcall(function () return cjson.decode(json) end)
+end
+
+local function splitOnFirstSpace(str)
+ local space = str:find(' ') or (#str + 1)
+ return str:sub(1, space-1), str:sub(space+1)
+end
+
+topic,msg = splitOnFirstSpace(input)
+if msg ~= "" then
+ ok,d = try_decoding_json(msg)
+end
+if not ok then d = {comment=input} end
+if not d.pkgname then d.pkgname = "?" end
+if not d.hostname then d.hostname = "?" end
+if not d.reponame then d.reponame = "?" end
+if not d.logurl then d.logurl = "?" end
+if not d.comment then d.comment = "" end
+
+for k, v in pairs(d) do
+ d[k] = string.gsub(d[k], "'", "''")
+end
+
+-- for k, v in pairs(d) do print(string.format("%s=%s", tostring(k), tostring(v))) end
+
+local db = sqlite3.open(dbfile)
+local query = "\
+ insert into build_errors (\
+ hostname,\
+ pkgname,\
+ reponame,\
+ logurl,\
+ comment\
+ )\
+ values (\
+ '"..d.hostname.."',\
+ '"..d.pkgname.."',\
+ '"..d.reponame.."',\
+ '"..d.logurl.."',\
+ '"..d.comment.."'\
+ );\
+"
+db:exec(query)
+db:close()
diff --git a/var/lib/build-errors/scripts/save-build-error.sh b/var/lib/build-errors/scripts/save-build-error.sh
new file mode 100644
index 0000000..ebd10f2
--- /dev/null
+++ b/var/lib/build-errors/scripts/save-build-error.sh
@@ -0,0 +1 @@
+echo "$@" | lua /var/lib/build-errors/scripts/save-build-error.lua
diff --git a/var/lib/build-errors/sqlite/build-errors.db b/var/lib/build-errors/sqlite/build-errors.db
new file mode 100644
index 0000000..b97ec02
--- /dev/null
+++ b/var/lib/build-errors/sqlite/build-errors.db
Binary files differ