summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-03-29 15:36:00 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-03-29 15:36:00 (GMT)
commit27a967a7fbbd9345bf205e44bbfd047f5752a42e (patch)
tree9becd79e8ac21da53a2f5fcbc5ae9b9cb1e037cf
parent473634799142c6cc9f7c78778add94958f5293d2 (diff)
added minimal config parser
-rw-r--r--nopsyncd/conf.lua33
-rw-r--r--nopsyncd/nopsyncd.conf13
-rw-r--r--nopsyncd/playlog.lua7
-rwxr-xr-xnopsyncd/qlistener.lua6
-rw-r--r--nopsyncd/rddb.lua5
5 files changed, 56 insertions, 8 deletions
diff --git a/nopsyncd/conf.lua b/nopsyncd/conf.lua
new file mode 100644
index 0000000..83257b5
--- /dev/null
+++ b/nopsyncd/conf.lua
@@ -0,0 +1,33 @@
+--
+-- rhnop
+--
+-- Copyright (C) 2011 Christian Pointner <equinox@helsinki.at>
+--
+-- This file is part of rhnop.
+--
+-- rhnop is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- any later version.
+--
+-- rhnop is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with rhnop. If not, see <http://www.gnu.org/licenses/>.
+--
+
+local conf = {}
+
+local file = assert(io.open("nopsyncd.conf", "r"))
+for line in file:lines() do
+ local k,v = string.match(line, "^([^=#]+)=(.*)$")
+ if k and v and v ~= "" then
+ conf[k] = v
+ end
+end
+file:close()
+
+return conf
diff --git a/nopsyncd/nopsyncd.conf b/nopsyncd/nopsyncd.conf
new file mode 100644
index 0000000..636e4f0
--- /dev/null
+++ b/nopsyncd/nopsyncd.conf
@@ -0,0 +1,13 @@
+queue_name=/rhnop
+
+rddb_db=rivendell
+rddb_host=127.0.0.1
+#rddb_port=3306
+rddb_user=rivendellro
+rddb_pwd=lldrivenro
+
+playlog_db=rhnop
+playlog_host=127.0.0.1
+#playlog_port=3307
+playlog_user=nopsyncd
+playlog_pwd=123456
diff --git a/nopsyncd/playlog.lua b/nopsyncd/playlog.lua
index 3aa0361..37b9ea6 100644
--- a/nopsyncd/playlog.lua
+++ b/nopsyncd/playlog.lua
@@ -25,6 +25,8 @@ require "luasql.mysql"
-- GRANT select,insert,update ON rhnop.* TO 'nopsyncd' IDENTIFIED BY '123456';
-- CREATE TABLE IF NOT EXISTS now (timestamp VARCHAR(16) PRIMARY KEY NOT NULL, cart INT NOT NULL, len INT, showtitle VARCHAR(255), title VARCHAR(255), artist VARCHAR(255), album VARCHAR(255), ismusic BOOLEAN)
+conf = require "conf"
+
local playlog = {}
function playlog:init()
@@ -35,7 +37,7 @@ function playlog:init()
return nil, err
end
- self.con, err = self.env:connect("rhnop", "nopsyncd", "123456", "127.0.0.1")
+ self.con, err = self.env:connect(conf.playlog_db, conf.playlog_user, conf.playlog_pwd, conf.playlog_host, conf.playlog_port)
if self.con == nil then
return nil, err
end
@@ -59,7 +61,7 @@ function playlog:getLastCart()
return cart
end
-function playlog:insertMusic(timestamp, cart, len, title, artist, album)
+function playlog:insertNowMusic(timestamp, cart, len, title, artist, album)
cart = tonumber(cart)
len = tonumber(len)
if cart < 400000 or cart > 450000 then
@@ -67,7 +69,6 @@ function playlog:insertMusic(timestamp, cart, len, title, artist, album)
else
poolnum = math.floor(cart/1000) - 399
end
- -- usage of undocumented escape function...
local cur, err = self.con:execute("INSERT into now VALUES(" .. self.con:escape(timestamp) .. ", " .. cart .. ", " .. len .. ", 'Musikpool " .. poolnum .. "', '" .. self.con:escape(title) .. "', '" .. self.con:escape(artist) .."', '" .. self.con:escape(album) .. "', 1)")
if cur == nil then
return nil, err
diff --git a/nopsyncd/qlistener.lua b/nopsyncd/qlistener.lua
index c507358..ebc8446 100755
--- a/nopsyncd/qlistener.lua
+++ b/nopsyncd/qlistener.lua
@@ -19,12 +19,12 @@
-- along with rhnop. If not, see <http://www.gnu.org/licenses/>.
--
-local queue_name = "/rhnop"
local last_cart = nil
mq = require "luamq"
playlog = require "playlog"
rddb = require "rddb"
+conf = require "conf"
function handle_now(timestamp, nowcart, nowlen)
local results, err = rddb:getCartInfo(nowcart);
@@ -32,7 +32,7 @@ function handle_now(timestamp, nowcart, nowlen)
io.stderr:write("can't fetch cart info: " .. err .. "\n")
else
-- print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'")
- local ret, err = playlog:insertMusic(timestamp, nowcart, nowlen, results.TITLE, results.ARTIST, results.ALBUM)
+ local ret, err = playlog:insertNowMusic(timestamp, nowcart, nowlen, results.TITLE, results.ARTIST, results.ALBUM)
if ret == nil then
io.stderr:write("can't insert music info: " .. err .. "\n")
else
@@ -56,7 +56,7 @@ function handle_message(msg)
end
function main_loop()
- local q, err = mq.create(queue_name, "ro")
+ local q, err = mq.create(conf.queue_name, "ro")
if q == nil then
io.stderr:write("creation of message queue failed: " .. err .. "\n")
os.exit(1)
diff --git a/nopsyncd/rddb.lua b/nopsyncd/rddb.lua
index e7ed14e..c8037a9 100644
--- a/nopsyncd/rddb.lua
+++ b/nopsyncd/rddb.lua
@@ -21,6 +21,8 @@
require "luasql.mysql"
+conf = require "conf"
+
local rddb = {}
function rddb:init()
@@ -31,8 +33,7 @@ function rddb:init()
return nil, err
end
- -- TODO: read /etc/rd.conf for connection info
- self.con, err = self.env:connect("rivendell", "rivendellro", "lldrivenro", "127.0.0.1")
+ self.con, err = self.env:connect(conf.rddb_db, conf.rddb_user, conf.rddb_pwd, conf.rddb_host, conf.rddb_port)
if self.con == nil then
return nil, err
end