commit 072fcb45439099e61716bb3edfee8cbc81f6887a Author: Damian Johnson atagar@torproject.org Date: Fri May 13 19:04:51 2011 -0700
Moving torrc log load warnings to the torrc class
Minor refactoring change so warnings are an option of the load method. --- src/cli/controller.py | 16 +++++----------- src/util/torConfig.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/src/cli/controller.py b/src/cli/controller.py index eb1df4f..d44b811 100644 --- a/src/cli/controller.py +++ b/src/cli/controller.py @@ -96,8 +96,7 @@ PAGES = [ ["config"], ["torrc"]]
-CONFIG = {"log.torrc.readFailed": log.WARN, - "features.graph.type": 1, +CONFIG = {"features.graph.type": 1, "queries.refreshRate.rate": 5, "log.torEventTypeUnrecognized": log.NOTICE, "features.graph.bw.prepopulate": True, @@ -286,11 +285,8 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode): loadedTorrc = torConfig.getTorrc() loadedTorrc.getLock().acquire()
- try: - loadedTorrc.load() - except IOError, exc: - msg = "Unable to load torrc (%s)" % sysTools.getFileErrorMsg(exc) - log.log(CONFIG["log.torrc.readFailed"], msg) + try: loadedTorrc.load(True) + except: pass
if loadedTorrc.isLoaded(): corrections = loadedTorrc.getCorrections() @@ -504,11 +500,9 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode): # reload the torrc if it's previously been loaded if loadedTorrc.isLoaded(): try: - loadedTorrc.load() + loadedTorrc.load(True) if page == 3: panels["torrc"].redraw(True) - except IOError, exc: - msg = "Unable to load torrc (%s)" % sysTools.getFileErrorMsg(exc) - log.log(CONFIG["log.torrc.readFailed"], msg) + except: pass
sighupTracker.isReset = False
diff --git a/src/util/torConfig.py b/src/util/torConfig.py index 4a25f0f..a083099 100644 --- a/src/util/torConfig.py +++ b/src/util/torConfig.py @@ -22,6 +22,7 @@ CONFIG = {"features.torrc.validate": True, "torrc.label.time.hour": [], "torrc.label.time.day": [], "torrc.label.time.week": [], + "log.torrc.readFailed": log.WARN, "log.configDescriptions.unrecognizedCategory": log.NOTICE}
# enums and values for numeric torrc entries @@ -616,11 +617,18 @@ class Torrc(): self.displayableContents = None self.strippedContents = None self.corrections = None + + # flag to indicate if we've given a load failure warning before + self.isLoadFailWarned = False
- def load(self): + def load(self, logFailure = False): """ Loads or reloads the torrc contents, raising an IOError if there's a problem. + + Arguments: + logFailure - if the torrc fails to load and we've never provided a + warning for this before then logs a warning """
self.valsLock.acquire() @@ -637,6 +645,11 @@ class Torrc(): self.contents = configFile.readlines() configFile.close() except IOError, exc: + if logFailure and not self.isLoadFailWarned: + msg = "Unable to load torrc (%s)" % sysTools.getFileErrorMsg(exc) + log.log(CONFIG["log.torrc.readFailed"], msg) + self.isLoadFailWarned = True + self.valsLock.release() raise exc
tor-commits@lists.torproject.org