diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | bcm5719-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/monitor.py')
-rw-r--r-- | lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py | 104 |
1 files changed, 59 insertions, 45 deletions
diff --git a/lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py b/lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py index e31b51b6d21..6ed6589d670 100644 --- a/lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py +++ b/lldb/third_party/Python/module/pexpect-2.4/examples/monitor.py @@ -23,40 +23,53 @@ It works like this: Exit the remote host. """ -import os, sys, time, re, getopt, getpass +import os +import sys +import time +import re +import getopt +import getpass import traceback import pexpect # # Some constants. # -COMMAND_PROMPT = '[#$] ' ### This is way too simple for industrial use -- we will change is ASAP. +# This is way too simple for industrial use -- we will change is ASAP. +COMMAND_PROMPT = '[#$] ' TERMINAL_PROMPT = '(?i)terminal type\?' TERMINAL_TYPE = 'vt100' -# This is the prompt we get if SSH does not have the remote host's public key stored in the cache. +# This is the prompt we get if SSH does not have the remote host's public +# key stored in the cache. SSH_NEWKEY = '(?i)are you sure you want to continue connecting' + def exit_with_usage(): print globals()['__doc__'] os._exit(1) + def main(): global COMMAND_PROMPT, TERMINAL_PROMPT, TERMINAL_TYPE, SSH_NEWKEY ###################################################################### - ## Parse the options, arguments, get ready, etc. + # Parse the options, arguments, get ready, etc. ###################################################################### try: - optlist, args = getopt.getopt(sys.argv[1:], 'h?s:u:p:', ['help','h','?']) - except Exception, e: + optlist, args = getopt.getopt( + sys.argv[ + 1:], 'h?s:u:p:', [ + 'help', 'h', '?']) + except Exception as e: print str(e) exit_with_usage() options = dict(optlist) if len(args) > 1: 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() @@ -76,16 +89,17 @@ def main(): # # Login via SSH # - child = pexpect.spawn('ssh -l %s %s'%(user, host)) - i = child.expect([pexpect.TIMEOUT, SSH_NEWKEY, COMMAND_PROMPT, '(?i)password']) - if i == 0: # Timeout + child = pexpect.spawn('ssh -l %s %s' % (user, host)) + i = child.expect([pexpect.TIMEOUT, SSH_NEWKEY, + COMMAND_PROMPT, '(?i)password']) + if i == 0: # Timeout print 'ERROR! could not login with SSH. Here is what SSH said:' print child.before, child.after print str(child) - sys.exit (1) - if i == 1: # In this case SSH does not have the public key cached. - child.sendline ('yes') - child.expect ('(?i)password') + sys.exit(1) + if i == 1: # In this case SSH does not have the public key cached. + child.sendline('yes') + child.expect('(?i)password') if i == 2: # This may happen if a public key was setup to automatically login. # But beware, the COMMAND_PROMPT at this point is very trivial and @@ -95,25 +109,25 @@ def main(): child.sendline(password) # Now we are either at the command prompt or # the login process is asking for our terminal type. - i = child.expect ([COMMAND_PROMPT, TERMINAL_PROMPT]) + i = child.expect([COMMAND_PROMPT, TERMINAL_PROMPT]) if i == 1: - child.sendline (TERMINAL_TYPE) - child.expect (COMMAND_PROMPT) + child.sendline(TERMINAL_TYPE) + child.expect(COMMAND_PROMPT) # # Set command prompt to something more unique. # COMMAND_PROMPT = "\[PEXPECT\]\$ " - child.sendline ("PS1='[PEXPECT]\$ '") # In case of sh-style - i = child.expect ([pexpect.TIMEOUT, COMMAND_PROMPT], timeout=10) + child.sendline("PS1='[PEXPECT]\$ '") # In case of sh-style + i = child.expect([pexpect.TIMEOUT, COMMAND_PROMPT], timeout=10) if i == 0: print "# Couldn't set sh-style prompt -- trying csh-style." - child.sendline ("set prompt='[PEXPECT]\$ '") - i = child.expect ([pexpect.TIMEOUT, COMMAND_PROMPT], timeout=10) + child.sendline("set prompt='[PEXPECT]\$ '") + i = child.expect([pexpect.TIMEOUT, COMMAND_PROMPT], timeout=10) if i == 0: print "Failed to set command prompt using sh or csh style." print "Response was:" print child.before - sys.exit (1) + sys.exit(1) # Now we should be at the command prompt and ready to run some commands. print '---------------------------------------' @@ -121,8 +135,8 @@ def main(): print '---------------------------------------' # Run uname. - child.sendline ('uname -a') - child.expect (COMMAND_PROMPT) + child.sendline('uname -a') + child.expect(COMMAND_PROMPT) print child.before if 'linux' in child.before.lower(): LINUX_MODE = 1 @@ -130,51 +144,52 @@ def main(): LINUX_MODE = 0 # Run and parse 'uptime'. - child.sendline ('uptime') - child.expect('up\s+(.*?),\s+([0-9]+) users?,\s+load averages?: ([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9])') + child.sendline('uptime') + child.expect( + 'up\s+(.*?),\s+([0-9]+) users?,\s+load averages?: ([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9]),?\s+([0-9]+\.[0-9][0-9])') duration, users, av1, av5, av15 = child.match.groups() days = '0' hours = '0' mins = '0' if 'day' in duration: - child.match = re.search('([0-9]+)\s+day',duration) + child.match = re.search('([0-9]+)\s+day', duration) days = str(int(child.match.group(1))) if ':' in duration: - child.match = re.search('([0-9]+):([0-9]+)',duration) + child.match = re.search('([0-9]+):([0-9]+)', duration) hours = str(int(child.match.group(1))) mins = str(int(child.match.group(2))) if 'min' in duration: - child.match = re.search('([0-9]+)\s+min',duration) + child.match = re.search('([0-9]+)\s+min', duration) mins = str(int(child.match.group(1))) print print 'Uptime: %s days, %s users, %s (1 min), %s (5 min), %s (15 min)' % ( duration, users, av1, av5, av15) - child.expect (COMMAND_PROMPT) + child.expect(COMMAND_PROMPT) # Run iostat. - child.sendline ('iostat') - child.expect (COMMAND_PROMPT) + child.sendline('iostat') + child.expect(COMMAND_PROMPT) print child.before # Run vmstat. - child.sendline ('vmstat') - child.expect (COMMAND_PROMPT) + child.sendline('vmstat') + child.expect(COMMAND_PROMPT) print child.before # Run free. if LINUX_MODE: - child.sendline ('free') # Linux systems only. - child.expect (COMMAND_PROMPT) + child.sendline('free') # Linux systems only. + child.expect(COMMAND_PROMPT) print child.before # Run df. - child.sendline ('df') - child.expect (COMMAND_PROMPT) + child.sendline('df') + child.expect(COMMAND_PROMPT) print child.before - + # Run lsof. - child.sendline ('lsof') - child.expect (COMMAND_PROMPT) + child.sendline('lsof') + child.expect(COMMAND_PROMPT) print child.before # # Run netstat @@ -191,9 +206,9 @@ def main(): # print child.before # Now exit the remote host. - child.sendline ('exit') + child.sendline('exit') index = child.expect([pexpect.EOF, "(?i)there are stopped jobs"]) - if index==1: + if index == 1: child.sendline("exit") child.expect(EOF) @@ -201,8 +216,7 @@ if __name__ == "__main__": try: main() - except Exception, e: + except Exception as e: print str(e) traceback.print_exc() os._exit(1) - |