[tor-commits] [stem/master] Remove awk and grep from ps call

atagar at torproject.org atagar at torproject.org
Tue Jan 3 04:41:40 UTC 2012


commit c421b54e52d181e14a6677752fe2c07d2b56a796
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date:   Tue Dec 20 17:13:53 2011 +0530

    Remove awk and grep from ps call
    
    Instead of piping the output from the ps call
    to grep and awk, use python itself to parse
    the result.
---
 test/integ/util/system.py |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 7f4c68c..b255c4a 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -26,11 +26,13 @@ class TestSystem(unittest.TestCase):
     
     if self.is_extra_tor_running == None:
       if not stem.util.system.is_bsd():
-        pgrep_results = stem.util.system.call("pgrep -x tor")
+        pgrep_results = stem.util.system.call(stem.util.system.GET_PID_BY_NAME_PGREP % "tor")
         self.is_extra_tor_running = len(pgrep_results) > 1
       else:
-        pgrep_results = stem.util.system.call("ps -axo pid,command,args  | grep -i tor | awk '{ print $1}'")
-        self.is_extra_tor_running = len(pgrep_results) > 1
+        ps_results = stem.util.system.call(stem.util.system.GET_PID_BY_NAME_PS_BSD)
+        results = [r for r in ps_results if r.endswith("tor")]
+        self.is_extra_tor_running = len(results) > 1
+        
   def tearDown(self):
     # resets call mocking back to being disabled
     stem.util.system.CALL_MOCKING = None





More information about the tor-commits mailing list