# HG changeset patch # User Mikael Berthe # Date 1214070735 -7200 # Node ID 727c0c584faaaf744704583ff2a3ca671e7189ce # Parent 72c249247e183209371a01aa8b7860dfd0f3d7b3 Do not re-read the config. file if it hasn't changed diff -r 72c249247e18 -r 727c0c584faa mcevent.py --- 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)