From 72997ffde3823d6f74cb7a8ab2171529bc46ed0c Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 09:53:32 -0500 Subject: [PATCH 1/6] ignore *.swp, *.pyc --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9b568f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.swp From 10554dd4a5bdceec42c4f275dca6e3b3a5664404 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 09:54:11 -0500 Subject: [PATCH 2/6] basic config file --- dr.botzo.cfg | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 dr.botzo.cfg diff --git a/dr.botzo.cfg b/dr.botzo.cfg new file mode 100644 index 0000000..87e2c3f --- /dev/null +++ b/dr.botzo.cfg @@ -0,0 +1,6 @@ +[IRC] +server = irc.foonetic.net +port = 6667 +channel = #lh +nick = dr_devzo +name = dr. devzo From f45712a94e41a9362bcb44ea4b84f52c95a55907 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 09:54:38 -0500 Subject: [PATCH 3/6] test loading from a config file --- dr.botzo.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 dr.botzo.py diff --git a/dr.botzo.py b/dr.botzo.py new file mode 100755 index 0000000..6676611 --- /dev/null +++ b/dr.botzo.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3.1 + +import configparser +import os + +config = configparser.ConfigParser() +config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg']) + +# load connection info +server = config.get('IRC', 'server') +port = config.getint('IRC', 'port') +channel = config.get('IRC', 'channel') +nick = config.get('IRC', 'nick') +name = config.get('IRC', 'name') + +print(server + " " + str(port) + " " + channel + " " + nick + " " + name) + +# vi:tabstop=4:expandtab:autoindent From e792c22a8e7aa626448a0172aec67ce15a0d5fc6 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 10:03:27 -0500 Subject: [PATCH 4/6] name -> ircname variable rename to fit with irclib --- dr.botzo.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dr.botzo.py b/dr.botzo.py index 6676611..37466ed 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -11,8 +11,6 @@ server = config.get('IRC', 'server') port = config.getint('IRC', 'port') channel = config.get('IRC', 'channel') nick = config.get('IRC', 'nick') -name = config.get('IRC', 'name') - -print(server + " " + str(port) + " " + channel + " " + nick + " " + name) +ircname = config.get('IRC', 'name') # vi:tabstop=4:expandtab:autoindent From 398514a42220b3bab595f6fc9360437defa328c2 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 10:12:00 -0500 Subject: [PATCH 5/6] from configparser import *, light exception handling in initial value load --- dr.botzo.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dr.botzo.py b/dr.botzo.py index 37466ed..1c2b819 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -1,16 +1,20 @@ #!/usr/bin/env python3.1 -import configparser +from configparser import * import os +import sys -config = configparser.ConfigParser() +config = ConfigParser() config.read([os.path.expanduser('~/.dr.botzo.cfg'), 'dr.botzo.cfg']) -# load connection info -server = config.get('IRC', 'server') -port = config.getint('IRC', 'port') -channel = config.get('IRC', 'channel') -nick = config.get('IRC', 'nick') -ircname = config.get('IRC', 'name') +try: + # load connection info + server = config.get('IRC', 'server') + port = config.getint('IRC', 'port') + channel = config.get('IRC', 'channel') + nick = config.get('IRC', 'nick') + ircname = config.get('IRC', 'name') +except NoSectionError as e: + sys.exit(str(e)) # vi:tabstop=4:expandtab:autoindent From ea0610409a0161d630a060b15d97c6eabdfaa992 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 24 Jul 2010 10:14:47 -0500 Subject: [PATCH 6/6] one more exception caught, more verbose sys.exit --- dr.botzo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dr.botzo.py b/dr.botzo.py index 1c2b819..b21d9ff 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -15,6 +15,8 @@ try: nick = config.get('IRC', 'nick') ircname = config.get('IRC', 'name') except NoSectionError as e: - sys.exit(str(e)) + sys.exit("Aborted due to error with necessary configuration: " + str(e)) +except NoOptionError as e: + sys.exit("Aborted due to error with necessary configuration: " + str(e)) # vi:tabstop=4:expandtab:autoindent