[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r23835: {arm} Refactoring changes for setconf functionality. - added loggi (in arm/trunk: . src/interface src/util)
Author: atagar
Date: 2010-11-19 17:21:52 +0000 (Fri, 19 Nov 2010)
New Revision: 23835
Modified:
arm/trunk/armrc.sample
arm/trunk/src/interface/controller.py
arm/trunk/src/util/torTools.py
Log:
Refactoring changes for setconf functionality.
- added logging for setconf calls made by arm
- moved setconf functionality into torTools
- allowing blank config values to be set
Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample 2010-11-19 15:32:38 UTC (rev 23834)
+++ arm/trunk/armrc.sample 2010-11-19 17:21:52 UTC (rev 23835)
@@ -191,6 +191,7 @@
log.torCtlPortClosed NOTICE
log.torGetInfo DEBUG
log.torGetConf DEBUG
+log.torSetConf INFO
log.torEventTypeUnrecognized NOTICE
log.torPrefixPathInvalid NOTICE
log.sysCallMade DEBUG
Modified: arm/trunk/src/interface/controller.py
===================================================================
--- arm/trunk/src/interface/controller.py 2010-11-19 15:32:38 UTC (rev 23834)
+++ arm/trunk/src/interface/controller.py 2010-11-19 17:21:52 UTC (rev 23835)
@@ -1525,7 +1525,7 @@
# provides prompt
selection = panels["torrc"].getSelection()
configOption = selection.get(configStatePanel.FIELD_OPTION)
- titleMsg = "%s Value: " % configOption
+ titleMsg = "%s Value (esc to cancel): " % configOption
panels["control"].setMsg(titleMsg)
panels["control"].redraw(True)
@@ -1540,7 +1540,7 @@
newConfigValue = panels["control"].getstr(0, len(titleMsg), initialText)
# it would be nice to quit on esc, but looks like this might not be possible...
- if newConfigValue != "" and newConfigValue != initialValue:
+ if newConfigValue != initialValue:
conn = torTools.getConn()
# if the value's a boolean then allow for 'true' and 'false' inputs
@@ -1550,39 +1550,19 @@
try:
if selection.get(configStatePanel.FIELD_TYPE) == "LineList":
- conn.getTorCtl().set_options([(configOption, val) for val in newConfigValue.split(",")])
- else:
- conn.getTorCtl().set_option(configOption, newConfigValue)
+ newConfigValue = newConfigValue.split(",")
+ conn.setOption(configOption, newConfigValue)
+
# resets the isDefault flag
setOptions = set()
configTextQuery = conn.getInfo("config-text", "").strip().split("\n")
for entry in configTextQuery: setOptions.add(entry[:entry.find(" ")])
selection.fields[configStatePanel.FIELD_IS_DEFAULT] = not configOption in setOptions
-
- # flushing cached values (needed until we can detect SETCONF calls)
- for fetchType in ("str", "list", "map"):
- entry = (configOption, fetchType)
-
- if entry in conn._cachedConf:
- del conn._cachedConf[entry]
-
panels["torrc"].redraw(True)
except Exception, exc:
- excStr = str(exc)
-
- if excStr.startswith("513 Unacceptable option value: "):
- # crops off the common error prefix
- excStr = excStr[31:]
-
- # Truncates messages like:
- # Value 'BandwidthRate la de da' is malformed or out of bounds.
- # to: Value 'la de da' is malformed or out of bounds.
- if excStr.startswith("Value '"):
- excStr = excStr.replace("%s " % configOption, "", 1)
-
- errorMsg = "%s (press any key)" % excStr
+ errorMsg = "%s (press any key)" % exc
panels["control"].setMsg(uiTools.cropStr(errorMsg, displayWidth), curses.A_STANDOUT)
panels["control"].redraw(True)
Modified: arm/trunk/src/util/torTools.py
===================================================================
--- arm/trunk/src/util/torTools.py 2010-11-19 15:32:38 UTC (rev 23834)
+++ arm/trunk/src/util/torTools.py 2010-11-19 17:21:52 UTC (rev 23835)
@@ -51,6 +51,7 @@
"log.torCtlPortClosed": log.NOTICE,
"log.torGetInfo": log.DEBUG,
"log.torGetConf": log.DEBUG,
+ "log.torSetConf": log.INFO,
"log.torPrefixPathInvalid": log.NOTICE}
# events used for controller functionality:
@@ -432,6 +433,59 @@
elif result == []: return default
else: return result
+ def setOption(self, param, value):
+ """
+ Issues a SETCONF to set the given option/value pair. An exeptions raised
+ if it fails to be set.
+
+ Arguments:
+ param - configuration option to be set
+ value - value to set the parameter to (this can be either a string or a
+ list of strings)
+ """
+
+ isMultiple = isinstance(value, list) or isinstance(value, tuple)
+ self.connLock.acquire()
+
+ startTime, raisedExc = time.time(), None
+ if self.isAlive():
+ try:
+ if isMultiple: self.conn.set_options([(param, val) for val in value])
+ else: self.conn.set_option(param, value)
+
+ # flushing cached values (needed until we can detect SETCONF calls)
+ for fetchType in ("str", "list", "map"):
+ entry = (param, fetchType)
+
+ if entry in self._cachedConf:
+ del self._cachedConf[entry]
+ except (socket.error, TorCtl.ErrorReply, TorCtl.TorCtlClosed), exc:
+ if type(exc) == TorCtl.TorCtlClosed: self.close()
+ elif type(exc) == TorCtl.ErrorReply:
+ excStr = str(exc)
+ if excStr.startswith("513 Unacceptable option value: "):
+ # crops off the common error prefix
+ excStr = excStr[31:]
+
+ # Truncates messages like:
+ # Value 'BandwidthRate la de da' is malformed or out of bounds.
+ # to: Value 'la de da' is malformed or out of bounds.
+ if excStr.startswith("Value '"):
+ excStr = excStr.replace("%s " % param, "", 1)
+
+ exc = TorCtl.ErrorReply(excStr)
+
+ raisedExc = exc
+
+ self.connLock.release()
+
+ setCall = "%s %s" % (param, ", ".join(value) if isMultiple else value)
+ excLabel = "failed: \"%s\", " % raisedExc if raisedExc else ""
+ msg = "SETCONF %s (%sruntime: %0.4f)" % (setCall.strip(), excLabel, time.time() - startTime)
+ log.log(CONFIG["log.torSetConf"], msg)
+
+ if raisedExc: raise raisedExc
+
def getMyNetworkStatus(self, default = None):
"""
Provides the network status entry for this relay if available. This is