summaryrefslogtreecommitdiffstats
path: root/lldb/third_party/Python/module/pexpect-2.4/examples/topip.py
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/third_party/Python/module/pexpect-2.4/examples/topip.py
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/third_party/Python/module/pexpect-2.4/examples/topip.py')
-rw-r--r--lldb/third_party/Python/module/pexpect-2.4/examples/topip.py102
1 files changed, 66 insertions, 36 deletions
diff --git a/lldb/third_party/Python/module/pexpect-2.4/examples/topip.py b/lldb/third_party/Python/module/pexpect-2.4/examples/topip.py
index 5bd63e2ef22..498f9a3b516 100644
--- a/lldb/third_party/Python/module/pexpect-2.4/examples/topip.py
+++ b/lldb/third_party/Python/module/pexpect-2.4/examples/topip.py
@@ -46,21 +46,30 @@ Noah Spurrier
$Id: topip.py 489 2007-11-28 23:40:34Z noah $
"""
-import pexpect, pxssh # See http://pexpect.sourceforge.net/
-import os, sys, time, re, getopt, pickle, getpass, smtplib
+import pexpect
+import pxssh # See http://pexpect.sourceforge.net/
+import os
+import sys
+import time
+import re
+import getopt
+import pickle
+import getpass
+import smtplib
import traceback
from pprint import pprint
TOPIP_LOG_FILE = '/var/log/topip.log'
TOPIP_LAST_RUN_STATS = '/var/run/topip.last'
+
def exit_with_usage():
print globals()['__doc__']
os._exit(1)
-def stats(r):
+def stats(r):
"""This returns a dict of the median, average, standard deviation, min and max of the given sequence.
>>> from topip import stats
@@ -75,30 +84,35 @@ def stats(r):
"""
total = sum(r)
- avg = float(total)/float(len(r))
- sdsq = sum([(i-avg)**2 for i in r])
- s = list(r)
- s.sort()
- return dict(zip(['med', 'avg', 'stddev', 'min', 'max'] , (s[len(s)//2], avg, (sdsq/len(r))**.5, min(r), max(r))))
+ avg = float(total) / float(len(r))
+ sdsq = sum([(i - avg)**2 for i in r])
+ s = sorted(r)
+ return dict(zip(['med', 'avg', 'stddev', 'min', 'max'],
+ (s[len(s) // 2], avg, (sdsq / len(r))**.5, min(r), max(r))))
-def send_alert (message, subject, addr_from, addr_to, smtp_server='localhost'):
+def send_alert(message, subject, addr_from, addr_to, smtp_server='localhost'):
"""This sends an email alert.
"""
- message = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n' % (addr_from, addr_to, subject) + message
+ message = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n' % (
+ addr_from, addr_to, subject) + message
server = smtplib.SMTP(smtp_server)
server.sendmail(addr_from, addr_to, message)
server.quit()
+
def main():
######################################################################
- ## Parse the options, arguments, etc.
+ # Parse the options, arguments, etc.
######################################################################
try:
- optlist, args = getopt.getopt(sys.argv[1:], 'h?valqs:u:p:n:', ['help','h','?','ipv6','stddev='])
- except Exception, e:
+ optlist, args = getopt.getopt(
+ sys.argv[
+ 1:], 'h?valqs:u:p:n:', [
+ 'help', 'h', '?', 'ipv6', 'stddev='])
+ except Exception as e:
print str(e)
exit_with_usage()
options = dict(optlist)
@@ -119,7 +133,8 @@ def main():
print args, len(args)
return 0
exit_with_usage()
- if [elem for elem in options if elem in ['-h','--h','-?','--?','--help']]:
+ if [elem for elem in options if elem in [
+ '-h', '--h', '-?', '--?', '--help']]:
print 'Help:'
exit_with_usage()
if '-s' in options:
@@ -183,10 +198,11 @@ def main():
p.sendline('netstat -n -t')
PROMPT = p.PROMPT
- # loop through each matching netstat_pattern and put the ip address in the list.
+ # loop through each matching netstat_pattern and put the ip address in the
+ # list.
ip_list = {}
try:
- while 1:
+ while True:
i = p.expect([PROMPT, netstat_pattern])
if i == 0:
break
@@ -199,21 +215,25 @@ def main():
pass
# remove a few common, uninteresting addresses from the dictionary.
- ip_list = dict([ (key,value) for key,value in ip_list.items() if '192.168.' not in key])
- ip_list = dict([ (key,value) for key,value in ip_list.items() if '127.0.0.1' not in key])
+ ip_list = dict([(key, value)
+ for key, value in ip_list.items() if '192.168.' not in key])
+ ip_list = dict([(key, value)
+ for key, value in ip_list.items() if '127.0.0.1' not in key])
# sort dict by value (count)
#ip_list = sorted(ip_list.iteritems(),lambda x,y:cmp(x[1], y[1]),reverse=True)
ip_list = ip_list.items()
if len(ip_list) < 1:
- if verbose: print 'Warning: no networks connections worth looking at.'
+ if verbose:
+ print 'Warning: no networks connections worth looking at.'
return 0
- ip_list.sort(lambda x,y:cmp(y[1],x[1]))
+ ip_list.sort(lambda x, y: cmp(y[1], x[1]))
# generate some stats for the ip addresses found.
if average_n <= 1:
average_n = None
- s = stats(zip(*ip_list[0:average_n])[1]) # The * unary operator treats the list elements as arguments
+ # The * unary operator treats the list elements as arguments
+ s = stats(zip(*ip_list[0:average_n])[1])
s['maxip'] = ip_list[0]
# print munin-style or verbose results for the stats.
@@ -223,33 +243,44 @@ def main():
print 'connections_stddev.value', s['stddev']
return 0
if verbose:
- pprint (s)
+ pprint(s)
print
- pprint (ip_list[0:average_n])
+ pprint(ip_list[0:average_n])
# load the stats from the last run.
try:
last_stats = pickle.load(file(TOPIP_LAST_RUN_STATS))
except:
- last_stats = {'maxip':None}
+ last_stats = {'maxip': None}
- if s['maxip'][1] > (s['stddev'] * stddev_trigger) and s['maxip']==last_stats['maxip']:
- if verbose: print 'The maxip has been above trigger for two consecutive samples.'
+ if s['maxip'][1] > (
+ s['stddev'] *
+ stddev_trigger) and s['maxip'] == last_stats['maxip']:
+ if verbose:
+ print 'The maxip has been above trigger for two consecutive samples.'
if alert_flag:
- if verbose: print 'SENDING ALERT EMAIL'
- send_alert(str(s), 'ALERT on %s' % hostname, alert_addr_from, alert_addr_to)
+ if verbose:
+ print 'SENDING ALERT EMAIL'
+ send_alert(
+ str(s),
+ 'ALERT on %s' %
+ hostname,
+ alert_addr_from,
+ alert_addr_to)
if log_flag:
- if verbose: print 'LOGGING THIS EVENT'
- fout = file(TOPIP_LOG_FILE,'a')
+ if verbose:
+ print 'LOGGING THIS EVENT'
+ fout = file(TOPIP_LOG_FILE, 'a')
#dts = time.strftime('%Y:%m:%d:%H:%M:%S', time.localtime())
dts = time.asctime()
- fout.write ('%s - %d connections from %s\n' % (dts,s['maxip'][1],str(s['maxip'][0])))
+ fout.write('%s - %d connections from %s\n' %
+ (dts, s['maxip'][1], str(s['maxip'][0])))
fout.close()
# save state to TOPIP_LAST_RUN_STATS
try:
- pickle.dump(s, file(TOPIP_LAST_RUN_STATS,'w'))
- os.chmod (TOPIP_LAST_RUN_STATS, 0664)
+ pickle.dump(s, file(TOPIP_LAST_RUN_STATS, 'w'))
+ os.chmod(TOPIP_LAST_RUN_STATS, 0o664)
except:
pass
# p.logout()
@@ -258,10 +289,9 @@ if __name__ == '__main__':
try:
main()
sys.exit(0)
- except SystemExit, e:
+ except SystemExit as e:
raise e
- except Exception, e:
+ except Exception as e:
print str(e)
traceback.print_exc()
os._exit(1)
-
OpenPOWER on IntegriCloud