[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Removing sysTools' getFileErrorMsg() function



commit 4f78691b376b8ec228ae5d3ece46f3e330d0e0b7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Sep 15 11:48:12 2013 -0700

    Removing sysTools' getFileErrorMsg() function
    
    The sole purpose of getFileErrorMsg() was to strip off the errno component of
    IOErrors from the output we print or log. On reflection however, that's exactly
    what the IOError's strerror attribute is so might as well use this instead.
    Only funcitonal difference of this change is that we no longer call lower() on
    the messages.
---
 arm/configPanel.py    |    4 ++--
 arm/controller.py     |    2 +-
 arm/logPanel.py       |   13 ++++++++-----
 arm/starter.py        |   11 ++++++-----
 arm/util/sysTools.py  |   20 --------------------
 arm/util/torConfig.py |   16 +++++++++-------
 6 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/arm/configPanel.py b/arm/configPanel.py
index 8a11be4..9ae4fa8 100644
--- a/arm/configPanel.py
+++ b/arm/configPanel.py
@@ -9,7 +9,7 @@ import threading
 import arm.controller
 import popups
 
-from arm.util import panel, sysTools, torConfig, torTools, uiTools
+from arm.util import panel, torConfig, torTools, uiTools
 
 import stem.control
 
@@ -474,7 +474,7 @@ class ConfigPanel(panel.Panel):
             torConfig.saveConf(configLocation, configLines)
             msg = "Saved configuration to %s" % configLocation
           except IOError, exc:
-            msg = "Unable to save configuration (%s)" % sysTools.getFileErrorMsg(exc)
+            msg = "Unable to save configuration (%s)" % exc.strerror
           
           popups.showMsg(msg, 2)
     finally: popups.finalize()
diff --git a/arm/controller.py b/arm/controller.py
index f6a1f6e..a72c634 100644
--- a/arm/controller.py
+++ b/arm/controller.py
@@ -665,7 +665,7 @@ def drawTorMonitor(stdscr, startTime):
       if confirmationKey in (ord('x'), ord('X')):
         try: torTools.getConn().reload()
         except IOError, exc:
-          log.error("Error detected when reloading tor: %s" % sysTools.getFileErrorMsg(exc))
+          log.error("Error detected when reloading tor: %s" % exc.strerror)
     elif key == ord('h') or key == ord('H'):
       overrideKey = arm.popups.showHelpPopup()
     elif key == ord('l') - 96:
diff --git a/arm/logPanel.py b/arm/logPanel.py
index 1f3067c..e9b3d06 100644
--- a/arm/logPanel.py
+++ b/arm/logPanel.py
@@ -18,7 +18,7 @@ from stem.util import conf, log, system
 
 import arm.popups
 from arm import __version__
-from arm.util import panel, sysTools, torTools, uiTools
+from arm.util import panel, torTools, uiTools
 
 TOR_EVENT_TYPES = {
   "d": "DEBUG",   "a": "ADDRMAP",          "k": "DESCCHANGED",  "s": "STREAM",
@@ -555,8 +555,11 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
         
         self.logFile = open(logPath, "a")
         log.notice("arm %s opening log file (%s)" % (__version__, logPath))
-      except (IOError, OSError), exc:
-        log.error("Unable to write to log file: %s" % sysTools.getFileErrorMsg(exc))
+      except IOError, exc:
+        log.error("Unable to write to log file: %s" % exc.strerror)
+        self.logFile = None
+      except OSError, exc:
+        log.error("Unable to write to log file: %s" % exc)
         self.logFile = None
     
     stem_logger = log.get_logger()
@@ -652,7 +655,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
         self.logFile.write(event.getDisplayMessage(True) + "\n")
         self.logFile.flush()
       except IOError, exc:
-        log.error("Unable to write to log file: %s" % sysTools.getFileErrorMsg(exc))
+        log.error("Unable to write to log file: %s" % exc.strerror)
         self.logFile = None
     
     self.valsLock.acquire()
@@ -786,7 +789,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
         self.saveSnapshot(pathInput)
         popups.showMsg("Saved: %s" % pathInput, 2)
       except IOError, exc:
-        popups.showMsg("Unable to save snapshot: %s" % sysTools.getFileErrorMsg(exc), 2)
+        popups.showMsg("Unable to save snapshot: %s" % exc.strerror, 2)
   
   def clear(self):
     """
diff --git a/arm/starter.py b/arm/starter.py
index 53c24ff..c804745 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -16,7 +16,6 @@ import time
 
 import arm.controller
 import arm.logPanel
-import arm.util.sysTools
 import arm.util.torConfig
 import arm.util.torTools
 import arm.util.uiTools
@@ -85,7 +84,7 @@ try:
   config = stem.util.conf.get_config("arm")
   config.load("%sarm/settings.cfg" % pathPrefix)
 except IOError, exc:
-  stem.util.log.warn(NO_INTERNAL_CFG_MSG % arm.util.sysTools.getFileErrorMsg(exc))
+  stem.util.log.warn(NO_INTERNAL_CFG_MSG % exc.strerror)
 
 
 def _get_args(argv):
@@ -314,15 +313,17 @@ def main():
       osLabel = "Platform: %s (%s)" % (platform.system(), " ".join(platform.dist()))
       
       stem.util.log.trace("%s\n%s\n%s\n%s\n" % (initMsg, pythonVersionLabel, osLabel, "-" * 80))
-    except (OSError, IOError), exc:
-      print "Unable to write to debug log file: %s" % arm.util.sysTools.getFileErrorMsg(exc)
+    except OSError, exc:
+      print "Unable to write to debug log file: %s" % exc
+    except IOError, exc:
+      print "Unable to write to debug log file: %s" % exc.strerror
   
   # loads user's personal armrc if available
   if os.path.exists(args.config):
     try:
       config.load(args.config)
     except IOError, exc:
-      stem.util.log.warn(CONFIG['msg.unable_to_read_config'].format(error = arm.util.sysTools.getFileErrorMsg(exc)))
+      stem.util.log.warn(CONFIG['msg.unable_to_read_config'].format(error = exc.strerror))
   else:
     # no armrc found, falling back to the defaults in the source
     stem.util.log.notice(CONFIG['msg.config_not_found'].format(path = args.config))
diff --git a/arm/util/sysTools.py b/arm/util/sysTools.py
index 3763826..80e5c12 100644
--- a/arm/util/sysTools.py
+++ b/arm/util/sysTools.py
@@ -40,26 +40,6 @@ def getSysCpuUsage():
   runtimeSum = sum([entry[1] for entry in RUNTIMES])
   return runtimeSum / SAMPLING_PERIOD
 
-def getFileErrorMsg(exc):
-  """
-  Strips off the error number prefix for file related IOError messages. For
-  instance, instead of saying:
-  [Errno 2] No such file or directory
-  
-  this would return:
-  no such file or directory
-  
-  Arguments:
-    exc - file related IOError exception
-  """
-  
-  excStr = str(exc)
-  if excStr.startswith("[Errno ") and "] " in excStr:
-    excStr = excStr[excStr.find("] ") + 2:].strip()
-    excStr = excStr[0].lower() + excStr[1:]
-  
-  return excStr
-
 def getResourceTracker(pid, noSpawn = False):
   """
   Provides a running singleton ResourceTracker instance for the given pid.
diff --git a/arm/util/torConfig.py b/arm/util/torConfig.py
index 34fc989..978f44c 100644
--- a/arm/util/torConfig.py
+++ b/arm/util/torConfig.py
@@ -9,7 +9,7 @@ import threading
 
 import stem.version
 
-from arm.util import sysTools, torTools, uiTools
+from arm.util import torTools, uiTools
 
 from stem.util import conf, enum, log, str_tools, system
 
@@ -727,7 +727,7 @@ class Torrc():
       configFile.close()
     except IOError, exc:
       if logFailure and not self.isLoadFailWarned:
-        log.warn("Unable to load torrc (%s)" % sysTools.getFileErrorMsg(exc))
+        log.warn("Unable to load torrc (%s)" % exc.strerror)
         self.isLoadFailWarned = True
       
       self.valsLock.release()
@@ -1086,7 +1086,7 @@ def loadConfigurationDescriptions(pathPrefix):
         
         log.info(DESC_LOAD_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
       except IOError, exc:
-        log.info(DESC_LOAD_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+        log.info(DESC_LOAD_FAILED_MSG % exc.strerror)
     
     # fetches configuration options from the man page
     if not isConfigDescriptionsLoaded:
@@ -1097,7 +1097,7 @@ def loadConfigurationDescriptions(pathPrefix):
         
         log.info(DESC_READ_MAN_SUCCESS_MSG % (time.time() - loadStartTime))
       except IOError, exc:
-        log.notice(DESC_READ_MAN_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+        log.notice(DESC_READ_MAN_FAILED_MSG % exc.strerror)
       
       # persists configuration descriptions 
       if isConfigDescriptionsLoaded and descriptorPath:
@@ -1105,8 +1105,10 @@ def loadConfigurationDescriptions(pathPrefix):
           loadStartTime = time.time()
           saveOptionDescriptions(descriptorPath)
           log.info(DESC_SAVE_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
-        except (IOError, OSError), exc:
-          log.notice(DESC_SAVE_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+        except IOError, exc:
+          log.notice(DESC_SAVE_FAILED_MSG % exc.strerror)
+        except OSError, exc:
+          log.notice(DESC_SAVE_FAILED_MSG % exc)
     
     # finally fall back to the cached descriptors provided with arm (this is
     # often the case for tbb and manual builds)
@@ -1117,5 +1119,5 @@ def loadConfigurationDescriptions(pathPrefix):
         isConfigDescriptionsLoaded = True
         log.notice(DESC_INTERNAL_LOAD_SUCCESS_MSG % loadedVersion)
       except IOError, exc:
-        log.error(DESC_INTERNAL_LOAD_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+        log.error(DESC_INTERNAL_LOAD_FAILED_MSG % exc.strerror)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits