From 882ec95e0a9bd543fe9f8834ab840e3f035a35bc Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Sat, 6 Oct 2012 13:51:47 +0200 Subject: [PATCH] moved config to a file, the config module now looks in ~/.brathuhn.cfg, $CWD/brathuhn.cfg and /etc/brathuhn/config.cfg An example config-file: [Account] NAME = brathuhn SRV = n0g.at PWD = secret [Conference] ROOM = gladio@conference.n0g.at PWD_ROOM = terces ;ROOM = debug@conference.n0g.at ;PWD_ROOM = this is a comment --- brathuhn.py | 4 ++-- config.py | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/brathuhn.py b/brathuhn.py index 3a4b650..7ba28fe 100644 --- a/brathuhn.py +++ b/brathuhn.py @@ -205,7 +205,7 @@ def connect_and_join(): con=cl.connect() if not con: print 'could not connect!' - raise 'could not connect!' + raise Exception('could not connect!') print 'connected' cl.RegisterHandler('message',__messageCB) @@ -215,7 +215,7 @@ def connect_and_join(): auth=cl.auth(NAME,PWD,resource=jid.getResource()) if not auth: print 'could not authenticate!' - raise 'could not authenticate!' + raise Exception('could not authenticate!') print 'auth' diff --git a/config.py b/config.py index 6477aa5..c09ce55 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,15 @@ -NAME = "brathuhn" -SRV = "n0g.at" -PWD = "123huhn" +from ConfigParser import ConfigParser +import os -ROOM = "gladio@conference.n0g.at" -PWD_ROOM = "secret" +cp = ConfigParser() +cp.read(["/etc/brathuhn/config.cfg","brathuhn.cfg",os.path.expanduser('~/.brathuhn.cfg')]) + +NAME = cp.get("Account","NAME") +SRV = cp.get("Account","SRV") +PWD = cp.get("Account","PWD") + +ROOM = cp.get("Conference","ROOM") +PWD_ROOM = cp.get("Conference","PWD_ROOM") + +print NAME,SRV -#ROOM = "debug@conference.n0g.at" -#PWD_ROOM = ""