Do not re-read the config. file if it hasn't changed
--- a/mcevent.py Sat Jun 21 19:35:23 2008 +0200
+++ b/mcevent.py Sat Jun 21 19:52:15 2008 +0200
@@ -9,6 +9,7 @@
#
import sys, getopt
+import os
import pynotify
CONFFILE = "mcevent.cfg"
@@ -50,8 +51,6 @@
def read_conf_from_file():
import ConfigParser
- # TODO: Do not re-read file if it hasn't been touched
-
config = ConfigParser.ConfigParser()
config.read(CONFFILE)
@@ -216,6 +215,14 @@
if o == "-c":
CONFFILE = a
+try:
+ last_conf_read = os.stat(CONFFILE).st_ctime
+except OSError:
+ sys.stderr.write("Cannot read config file!\n")
+ sys.exit(3)
+
+read_conf_from_file()
+
NOTIFY_LOADED = False
# read stdin line by line
@@ -228,7 +235,10 @@
if not line:
break
- read_conf_from_file()
+ last_conf_change = os.stat(CONFFILE).st_ctime
+ if last_conf_change > last_conf_read:
+ read_conf_from_file()
+ last_conf_read = last_conf_change
lineargs = line.split()
process_line(lineargs)