[or-cvs] r22497: {arm} change: fetching header config parameters in a more uniform (arm/trunk/interface)

Damian Johnson atagar1 at gmail.com
Wed Jun 9 16:07:56 UTC 2010


Author: atagar
Date: 2010-06-09 16:07:56 +0000 (Wed, 09 Jun 2010)
New Revision: 22497

Modified:
   arm/trunk/interface/controller.py
   arm/trunk/interface/headerPanel.py
Log:
change: fetching header config parameters in a more uniform way



Modified: arm/trunk/interface/controller.py
===================================================================
--- arm/trunk/interface/controller.py	2010-06-09 15:46:48 UTC (rev 22496)
+++ arm/trunk/interface/controller.py	2010-06-09 16:07:56 UTC (rev 22497)
@@ -311,6 +311,10 @@
     otherwise unrecognized events)
   """
   
+  # loads config for various interface components
+  config = conf.getConfig("arm")
+  config.update(CONFIG)
+  
   # pauses/unpauses connection resolution according to if tor's connected or not
   torTools.getConn().addStatusListener(connResetListener)
   
@@ -348,7 +352,7 @@
   connections.RESOLVER_FINAL_FAILURE_MSG += " (connection related portions of the monitor won't function)"
   
   panels = {
-    "header": headerPanel.HeaderPanel(stdscr),
+    "header": headerPanel.HeaderPanel(stdscr, config),
     "popup": Popup(stdscr, 9),
     "graph": graphPanel.GraphPanel(stdscr),
     "log": logPanel.LogMonitor(stdscr, conn, loggedEvents)}
@@ -411,9 +415,6 @@
   panels["popup"].redraw()      # hack to make sure popup has a window instance (not entirely sure why...)
   
   # provides notice about any unused config keys
-  config = conf.getConfig("arm")
-  config.update(CONFIG)
-  
   for key in config.getUnusedKeys():
     log.log(CONFIG["log.configEntryUndefined"], "config entry '%s' is unrecognized" % key)
   

Modified: arm/trunk/interface/headerPanel.py
===================================================================
--- arm/trunk/interface/headerPanel.py	2010-06-09 15:46:48 UTC (rev 22496)
+++ arm/trunk/interface/headerPanel.py	2010-06-09 16:07:56 UTC (rev 22497)
@@ -18,11 +18,8 @@
 import time
 import threading
 
-from util import conf, panel, sysTools, torTools, uiTools
+from util import panel, sysTools, torTools, uiTools
 
-# seconds between querying information
-UPDATE_RATE_CFG = ("queries.ps.rate", 5)
-
 # minimum width for which panel attempts to double up contents (two columns to
 # better use screen real estate)
 MIN_DUAL_COL_WIDTH = 141
@@ -35,6 +32,9 @@
 VERSION_STATUS_COLORS = {"new": "blue", "new in series": "blue", "obsolete": "red", "recommended": "green",  
                          "old": "red",  "unrecommended": "red",  "unknown": "cyan"}
 
+# user customizable parameters
+DEFAULT_CONFIG = {"queries.ps.rate": 5}
+
 class HeaderPanel(panel.Panel, threading.Thread):
   """
   Top area contenting tor settings and system information. Stats are stored in
@@ -48,12 +48,11 @@
   * volatile parameter that'll be reset on each update
   """
   
-  def __init__(self, stdscr):
+  def __init__(self, stdscr, config=None):
     panel.Panel.__init__(self, stdscr, 0)
     threading.Thread.__init__(self)
     self.setDaemon(True)
     
-    self._updateRate = conf.getConfig("arm").get(UPDATE_RATE_CFG[0], UPDATE_RATE_CFG[1], 1)
     self._isTorConnected = True
     self._lastUpdate = -1       # time the content was last revised
     self._isLastDrawWide = False
@@ -61,7 +60,12 @@
     self._isPaused = False      # prevents updates if true
     self._halt = False          # terminates thread if true
     self._cond = threading.Condition()  # used for pausing the thread
+    self._config = dict(DEFAULT_CONFIG)
     
+    if config:
+      config.update(self._config)
+      self._config["queries.ps.rate"] = max(self._config["queries.ps.rate"], 1)
+    
     self.vals = {}
     self.valsLock = threading.RLock()
     self._update(True)
@@ -205,9 +209,10 @@
     
     while not self._halt:
       timeSinceReset = time.time() - self._lastUpdate
+      psRate = self._config["queries.ps.rate"]
       
-      if self._isPaused or timeSinceReset < self._updateRate or not self._isTorConnected:
-        sleepTime = max(0.5, self._updateRate - timeSinceReset)
+      if self._isPaused or timeSinceReset < psRate or not self._isTorConnected:
+        sleepTime = max(0.5, psRate - timeSinceReset)
         self._cond.acquire()
         if not self._halt: self._cond.wait(sleepTime)
         self._cond.release()
@@ -326,7 +331,8 @@
       # the ps call formats results as:
       # %CPU   RSS %MEM     ELAPSED
       # 0.3 14096  1.3       29:51
-      psCall = sysTools.call("ps -p %s -o %s" % (self.vals["ps/pid"], ",".join(psParams)), self._updateRate, True)
+      psRate = self._config["queries.ps.rate"]
+      psCall = sysTools.call("ps -p %s -o %s" % (self.vals["ps/pid"], ",".join(psParams)), psRate, True)
       
       if psCall and len(psCall) >= 2:
         stats = psCall[1].strip().split()



More information about the tor-commits mailing list