summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Myint <git@stevenmyint.com>2013-10-04 07:02:31 -0700
committerSteven Myint <git@stevenmyint.com>2013-10-04 07:02:31 -0700
commitdd0479cb32e55e882a8d1391af2d5b37f25e2db7 (patch)
treeae595ce22b4b9d6700c71e2af4ef7d8055808b15
parentf64079f942fce756b52c81210401afd175b05902 (diff)
downloadpexpect-dd0479cb32e55e882a8d1391af2d5b37f25e2db7.tar.gz
Fix mixture of tabs and spaces
-rwxr-xr-xexamples/chess.py124
-rwxr-xr-xexamples/chess3.py124
-rwxr-xr-xexamples/fix_cvs_files.py85
-rwxr-xr-xexamples/passmass.py3
4 files changed, 165 insertions, 171 deletions
diff --git a/examples/chess.py b/examples/chess.py
index 193dbd8..47daec2 100755
--- a/examples/chess.py
+++ b/examples/chess.py
@@ -31,68 +31,68 @@ REGEX_MOVE_PART = '(?:[0-9]|\x1b\[C)(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)'
class Chess:
- def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"):
- self.child = pexpect.spawn (engine)
- self.term = ANSI.ANSI ()
-
- self.child.expect ('Chess')
- if self.child.after != 'Chess':
- raise IOError, 'incompatible chess program'
- self.term.process_list (self.before)
- self.term.process_list (self.after)
- self.last_computer_move = ''
- def read_until_cursor (self, r,c)
- while 1:
- self.child.read(1, 60)
- self.term.process (c)
- if self.term.cur_r == r and self.term.cur_c == c:
- return 1
-
- def do_first_move (self, move):
- self.child.expect ('Your move is')
- self.child.sendline (move)
- self.term.process_list (self.before)
- self.term.process_list (self.after)
- return move
-
- def do_move (self, move):
- read_until_cursor (19,60)
- #self.child.expect ('\[19;60H')
- self.child.sendline (move)
- print 'do_move' move
- return move
-
- def get_first_computer_move (self):
- self.child.expect ('My move is')
- self.child.expect (REGEX_MOVE)
+ def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"):
+ self.child = pexpect.spawn (engine)
+ self.term = ANSI.ANSI ()
+
+ self.child.expect ('Chess')
+ if self.child.after != 'Chess':
+ raise IOError, 'incompatible chess program'
+ self.term.process_list (self.before)
+ self.term.process_list (self.after)
+ self.last_computer_move = ''
+ def read_until_cursor (self, r,c)
+ while 1:
+ self.child.read(1, 60)
+ self.term.process (c)
+ if self.term.cur_r == r and self.term.cur_c == c:
+ return 1
+
+ def do_first_move (self, move):
+ self.child.expect ('Your move is')
+ self.child.sendline (move)
+ self.term.process_list (self.before)
+ self.term.process_list (self.after)
+ return move
+
+ def do_move (self, move):
+ read_until_cursor (19,60)
+ #self.child.expect ('\[19;60H')
+ self.child.sendline (move)
+ print 'do_move' move
+ return move
+
+ def get_first_computer_move (self):
+ self.child.expect ('My move is')
+ self.child.expect (REGEX_MOVE)
# print '', self.child.after
- return self.child.after
-
- def get_computer_move (self):
- print 'Here'
- i = self.child.expect (['\[17;59H', '\[17;58H'])
- print i
- if i == 0:
- self.child.expect (REGEX_MOVE)
- if len(self.child.after) < 4:
- self.child.after = self.child.after + self.last_computer_move[3]
- if i == 1:
- self.child.expect (REGEX_MOVE_PART)
- self.child.after = self.last_computer_move[0] + self.child.after
- print '', self.child.after
- self.last_computer_move = self.child.after
- return self.child.after
-
- def switch (self):
- self.child.sendline ('switch')
-
- def set_depth (self, depth):
- self.child.sendline ('depth')
- self.child.expect ('depth=')
- self.child.sendline ('%d' % depth)
-
- def quit(self):
- self.child.sendline ('quit')
+ return self.child.after
+
+ def get_computer_move (self):
+ print 'Here'
+ i = self.child.expect (['\[17;59H', '\[17;58H'])
+ print i
+ if i == 0:
+ self.child.expect (REGEX_MOVE)
+ if len(self.child.after) < 4:
+ self.child.after = self.child.after + self.last_computer_move[3]
+ if i == 1:
+ self.child.expect (REGEX_MOVE_PART)
+ self.child.after = self.last_computer_move[0] + self.child.after
+ print '', self.child.after
+ self.last_computer_move = self.child.after
+ return self.child.after
+
+ def switch (self):
+ self.child.sendline ('switch')
+
+ def set_depth (self, depth):
+ self.child.sendline ('depth')
+ self.child.expect ('depth=')
+ self.child.sendline ('%d' % depth)
+
+ def quit(self):
+ self.child.sendline ('quit')
import sys, os
print 'Starting...'
white = Chess()
@@ -145,5 +145,3 @@ while not done:
print 'tail of loop'
g.quit()
-
-
diff --git a/examples/chess3.py b/examples/chess3.py
index f60ab0a..7c080dd 100755
--- a/examples/chess3.py
+++ b/examples/chess3.py
@@ -31,69 +31,69 @@ REGEX_MOVE_PART = '(?:[0-9]|\x1b\[C)(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)'
class Chess:
- def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"):
- self.child = pexpect.spawn (engine)
- self.term = ANSI.ANSI ()
+ def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"):
+ self.child = pexpect.spawn (engine)
+ self.term = ANSI.ANSI ()
# self.child.expect ('Chess')
- # if self.child.after != 'Chess':
- # raise IOError, 'incompatible chess program'
- # self.term.process_list (self.before)
- # self.term.process_list (self.after)
- self.last_computer_move = ''
- def read_until_cursor (self, r,c):
- fout = open ('log','a')
- while 1:
- k = self.child.read(1, 10)
- self.term.process (k)
- fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
- fout.flush()
- if self.term.cur_r == r and self.term.cur_c == c:
- fout.close()
- return 1
- sys.stdout.write (k)
- sys.stdout.flush()
-
- def do_scan (self):
- fout = open ('log','a')
- while 1:
- c = self.child.read(1,10)
- self.term.process (c)
- fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
- fout.flush()
- sys.stdout.write (c)
- sys.stdout.flush()
-
- def do_move (self, move):
- self.read_until_cursor (19,60)
- self.child.sendline (move)
- return move
-
- def get_computer_move (self):
- print 'Here'
- i = self.child.expect (['\[17;59H', '\[17;58H'])
- print i
- if i == 0:
- self.child.expect (REGEX_MOVE)
- if len(self.child.after) < 4:
- self.child.after = self.child.after + self.last_computer_move[3]
- if i == 1:
- self.child.expect (REGEX_MOVE_PART)
- self.child.after = self.last_computer_move[0] + self.child.after
- print '', self.child.after
- self.last_computer_move = self.child.after
- return self.child.after
-
- def switch (self):
- self.child.sendline ('switch')
-
- def set_depth (self, depth):
- self.child.sendline ('depth')
- self.child.expect ('depth=')
- self.child.sendline ('%d' % depth)
-
- def quit(self):
- self.child.sendline ('quit')
+ # if self.child.after != 'Chess':
+ # raise IOError, 'incompatible chess program'
+ # self.term.process_list (self.before)
+ # self.term.process_list (self.after)
+ self.last_computer_move = ''
+ def read_until_cursor (self, r,c):
+ fout = open ('log','a')
+ while 1:
+ k = self.child.read(1, 10)
+ self.term.process (k)
+ fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
+ fout.flush()
+ if self.term.cur_r == r and self.term.cur_c == c:
+ fout.close()
+ return 1
+ sys.stdout.write (k)
+ sys.stdout.flush()
+
+ def do_scan (self):
+ fout = open ('log','a')
+ while 1:
+ c = self.child.read(1,10)
+ self.term.process (c)
+ fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
+ fout.flush()
+ sys.stdout.write (c)
+ sys.stdout.flush()
+
+ def do_move (self, move):
+ self.read_until_cursor (19,60)
+ self.child.sendline (move)
+ return move
+
+ def get_computer_move (self):
+ print 'Here'
+ i = self.child.expect (['\[17;59H', '\[17;58H'])
+ print i
+ if i == 0:
+ self.child.expect (REGEX_MOVE)
+ if len(self.child.after) < 4:
+ self.child.after = self.child.after + self.last_computer_move[3]
+ if i == 1:
+ self.child.expect (REGEX_MOVE_PART)
+ self.child.after = self.last_computer_move[0] + self.child.after
+ print '', self.child.after
+ self.last_computer_move = self.child.after
+ return self.child.after
+
+ def switch (self):
+ self.child.sendline ('switch')
+
+ def set_depth (self, depth):
+ self.child.sendline ('depth')
+ self.child.expect ('depth=')
+ self.child.sendline ('%d' % depth)
+
+ def quit(self):
+ self.child.sendline ('quit')
import sys, os
print 'Starting...'
white = Chess()
@@ -152,5 +152,3 @@ while not done:
print 'tail of loop'
g.quit()
-
-
diff --git a/examples/fix_cvs_files.py b/examples/fix_cvs_files.py
index 733c39a..6812335 100755
--- a/examples/fix_cvs_files.py
+++ b/examples/fix_cvs_files.py
@@ -45,13 +45,13 @@ def is_binary (filename):
'''Assume that any file with a character where the 8th bit is set is
binary. '''
- fin = open(filename, 'rb')
- wholething = fin.read()
- fin.close()
- for c in wholething:
- if ord(c) & 0x80:
- return 1
- return 0
+ fin = open(filename, 'rb')
+ wholething = fin.read()
+ fin.close()
+ for c in wholething:
+ if ord(c) & 0x80:
+ return 1
+ return 0
def is_kb_sticky (filename):
@@ -59,55 +59,54 @@ def is_kb_sticky (filename):
Sticky Option status is '-ks' then this returns 1. If the status is
'Unknown' then it returns 1. Otherwise 0 is returned. '''
- try:
- s = pexpect.spawn ('cvs status %s' % filename)
- i = s.expect (['Sticky Options:\s*(.*)\r\n', 'Status: Unknown'])
- if i==1 and VERBOSE:
- print 'File not part of CVS repository:', filename
- return 1 # Pretend it's OK.
- if s.match.group(1) == '-kb':
- return 1
- s = None
- except:
- print 'Something went wrong trying to run external cvs command.'
- print ' cvs status %s' % filename
- print 'The cvs command returned:'
- print s.before
- return 0
+ try:
+ s = pexpect.spawn ('cvs status %s' % filename)
+ i = s.expect (['Sticky Options:\s*(.*)\r\n', 'Status: Unknown'])
+ if i==1 and VERBOSE:
+ print 'File not part of CVS repository:', filename
+ return 1 # Pretend it's OK.
+ if s.match.group(1) == '-kb':
+ return 1
+ s = None
+ except:
+ print 'Something went wrong trying to run external cvs command.'
+ print ' cvs status %s' % filename
+ print 'The cvs command returned:'
+ print s.before
+ return 0
def cvs_admin_kb (filename):
'''This uses 'cvs admin' to set the '-kb' sticky option. '''
- s = pexpect.run ('cvs admin -kb %s' % filename)
- # There is a timing issue. If I run 'cvs admin' too quickly
- # cvs sometimes has trouble obtaining the directory lock.
- time.sleep(1)
+ s = pexpect.run ('cvs admin -kb %s' % filename)
+ # There is a timing issue. If I run 'cvs admin' too quickly
+ # cvs sometimes has trouble obtaining the directory lock.
+ time.sleep(1)
def walk_and_clean_cvs_binaries (arg, dirname, names):
'''This contains the logic for processing files. This is the os.path.walk
callback. This skips dirnames that end in CVS. '''
- if len(dirname)>3 and dirname[-3:]=='CVS':
- return
- for n in names:
- fullpath = os.path.join (dirname, n)
- if os.path.isdir(fullpath) or os.path.islink(fullpath):
- continue
- if is_binary(fullpath):
- if not is_kb_sticky (fullpath):
- if VERBOSE: print fullpath
- cvs_admin_kb (fullpath)
+ if len(dirname)>3 and dirname[-3:]=='CVS':
+ return
+ for n in names:
+ fullpath = os.path.join (dirname, n)
+ if os.path.isdir(fullpath) or os.path.islink(fullpath):
+ continue
+ if is_binary(fullpath):
+ if not is_kb_sticky (fullpath):
+ if VERBOSE: print fullpath
+ cvs_admin_kb (fullpath)
def main ():
- if len(sys.argv) == 1:
- root = '.'
- else:
- root = sys.argv[1]
- os.path.walk (root, walk_and_clean_cvs_binaries, None)
+ if len(sys.argv) == 1:
+ root = '.'
+ else:
+ root = sys.argv[1]
+ os.path.walk (root, walk_and_clean_cvs_binaries, None)
if __name__ == '__main__':
- main ()
-
+ main ()
diff --git a/examples/passmass.py b/examples/passmass.py
index 1e371a4..4c4c850 100755
--- a/examples/passmass.py
+++ b/examples/passmass.py
@@ -72,7 +72,7 @@ def change_password(child, user, oldpassword, newpassword):
if i == 0:
print 'Host did not like new password. Here is what it said...'
print child.before
- child.send (chr(3)) # Ctrl-C
+ child.send (chr(3)) # Ctrl-C
child.sendline('') # This should tell remote passwd command to quit.
return
child.sendline(newpassword)
@@ -106,4 +106,3 @@ if __name__ == '__main__':
main()
except pexpect.ExceptionPexpect, e:
print str(e)
-