]> git.lyx.org Git - lyx.git/blobdiff - development/keystest/keytest.py
Update documentation after recent changes to references.
[lyx.git] / development / keystest / keytest.py
index 4bbe3ce21891827d2deea0fb70fe3efa68d26667..5a4e57ef5e2c39027bb3bfa7d93b93ce20ac7a6c 100755 (executable)
@@ -15,6 +15,8 @@ import subprocess
 
 print 'Beginning keytest.py'
 
+FNULL = open('/dev/null', 'w')
+
 DELAY = '59'
 
 class CommandSource:
@@ -103,7 +105,7 @@ class CommandSourceFromFile(CommandSource):
 
         drop = random.randint(0, len(self.lines) - 1)
         del self.lines[drop]
-        p = p - 1 / len(self.lines)
+        #p = p - 1 / len(self.lines)
         origlines = self.lines
         self.lines = []
         for l in origlines:
@@ -137,12 +139,15 @@ class CommandSourceFromFile(CommandSource):
             os._exit(0)
         if self.i >= len(self.lines):
             self.loops = self.loops + 1
+            if self.loops > 3:
+                os._exit(0)
             self.i = 0
             return 'Loop'
         line = self.lines[self.i]
         self.count = self.count + 1
         self.i = self.i + 1
-        print 'Line read: <<' + line + '>>\n'
+        #print 'Line read: <<' + line + '>>\n'
+        sys.stdout.write('r')
         return line.rstrip('\n').rstrip()
 
 
@@ -169,7 +174,7 @@ def sendKeystring(keystr, LYX_PID):
     before_secs = time.time()
     while not lyx_sleeping():
         time.sleep(0.02)
-        print '.',
+        sys.stdout.write('.')
         if time.time() - before_secs > 180:
             print 'Killing due to freeze (KILL_FREEZE)'
 
@@ -181,18 +186,37 @@ def sendKeystring(keystr, LYX_PID):
         while not lyx_sleeping():
             time.sleep(0.02)
             print '.',
-        print 'Making Screenshot: ' + screenshot_out
+        print 'Making Screenshot: ' + screenshot_out + ' OF ' + infilename
         time.sleep(0.2)
         os.system('import -window root '+screenshot_out+str(x.count)+".png")
         time.sleep(0.1)
     sys.stdout.flush()
-    subprocess.call(["xvkbd", "-xsendevent", "-delay", DELAY, "-text", keystr])
+    if (subprocess.call(
+            ["xvkbd", "-xsendevent", "-delay", DELAY, "-text", keystr],
+            stdout=FNULL,stderr=FNULL
+            ) == 0):
+        sys.stdout.write('*')
+    else:
+        sys.stdout.write('X')
+
+def system_retry(num_retry, cmd):
+    i = 0
+    rtn = os.system(cmd)
+    while ( ( i < num_retry ) and ( rtn != 0) ):
+        i = i + 1
+       rtn=os.system(cmd)
+        time.sleep(1)
+    if ( rtn != 0 ):
+        print "Command Failed: "+cmd
+        print " EXITING!\n"
+        os._exit(1)
 
 def RaiseWindow():
     os.system("echo x-session-manager PID: $X_PID.")
     os.system("echo x-session-manager open files: `lsof -p $X_PID | grep ICE-unix | wc -l`")
-    os.system("wmctrl -l | ( grep '"+lyx_window_name+"' || ( killall lyx ; sleep 1 ; killall -9 lyx ))")
-    os.system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1")
+    ####os.system("wmctrl -l | ( grep '"+lyx_window_name+"' || ( killall lyx ; sleep 1 ; killall -9 lyx ))")
+    #os.system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1")
+    system_retry(30, "wmctrl -R '"+lyx_window_name+"'")
 
 
 lyx_pid = os.environ.get('LYX_PID')
@@ -238,7 +262,7 @@ sendKeystring("\Afn", lyx_pid)
 write_commands = True
 
 while True:
-    os.system('echo -n LOADAVG:; cat /proc/loadavg')
+    #os.system('echo -n LOADAVG:; cat /proc/loadavg')
     c = x.getCommand()
     if c == 'Loop':
         outfile.close()
@@ -253,7 +277,7 @@ while True:
         if os.path.exists('/proc/' + lyx_pid + '/status'):
             sendKeystring(c[4:], lyx_pid)
         else:
-            os.system('killall lyx; sleep 2 ; killall -9 lyx')
+            ##os.system('killall lyx; sleep 2 ; killall -9 lyx')
             print 'No path /proc/' + lyx_pid + '/status, exiting'
             os._exit(1)
     elif c[0:4] == 'KD: ':