X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=development%2Fautotests%2Fkeytest.py;h=b2a89c2d0d63944c101146419e0997950b9b1e58;hb=1e807d5183896250bb28ac2cdec61e2a7423e8b6;hp=67cc0be8130a7eb9cbd494ba26cbd7c6b74eaaec;hpb=1f51de3cd15becfda6bddb425032035c40999770;p=lyx.git diff --git a/development/autotests/keytest.py b/development/autotests/keytest.py index 67cc0be813..b2a89c2d0d 100755 --- a/development/autotests/keytest.py +++ b/development/autotests/keytest.py @@ -20,7 +20,7 @@ print 'Beginning keytest.py' FNULL = open('/dev/null', 'w') -DELAY = '59' +key_delay = '' class CommandSource: @@ -149,8 +149,6 @@ class CommandSourceFromFile(CommandSource): line = self.lines[self.i].rstrip('\n') self.count = self.count + 1 self.i = self.i + 1 - #print '\nLine read: <<' + line + '>>\n' - sys.stdout.write('r') return line def lyx_exists(): @@ -170,6 +168,17 @@ def lyx_sleeping(): return sleeping +# Interruptible os.system() +def intr_system(cmd, ignore_err = False): + print "Executing " + cmd + "\n" + ret = os.system(cmd) + if os.WIFSIGNALED(ret): + raise KeyboardInterrupt + if ret != 0 and not ignore_err: + raise BaseException("command failed.") + return ret + + def sendKeystring(keystr, LYX_PID): # print "sending keystring "+keystr+"\n" @@ -180,39 +189,40 @@ def sendKeystring(keystr, LYX_PID): before_secs = time.time() while lyx_exists() and not lyx_sleeping(): time.sleep(0.02) - sys.stdout.write('.') sys.stdout.flush() if time.time() - before_secs > 180: print 'Killing due to freeze (KILL_FREEZE)' # Do profiling, but sysprof has no command line interface? - # os.system("killall -KILL lyx") + # intr_system("killall -KILL lyx") os._exit(1) if not screenshot_out is None: while lyx_exists() and not lyx_sleeping(): time.sleep(0.02) - sys.stdout.write('.') sys.stdout.flush() print 'Making Screenshot: ' + screenshot_out + ' OF ' + infilename time.sleep(0.2) - os.system('import -window root '+screenshot_out+str(x.count)+".png") + intr_system('import -window root '+screenshot_out+str(x.count)+".png") time.sleep(0.1) sys.stdout.flush() - if (subprocess.call( - [xvkbd_exe, "-no_root", "-xsendevent", "-window", lyx_window_name, "-delay", DELAY, "-text", keystr], - stdout=FNULL,stderr=FNULL - ) == 0): - sys.stdout.write('*') + actual_delay = key_delay + if actual_delay == '': + actual_delay = def_delay + if not xvkbd_hacked: + subprocess.call([xvkbd_exe, "-xsendevent", "-window", lyx_window_name, + "-delay", actual_delay, "-text", keystr], stdout = FNULL, stderr = FNULL) else: - sys.stdout.write('X') + subprocess.call([xvkbd_exe, "-no_root", "-wait_idle", lyx_pid, + "-xsendevent", "-window", lyx_window_name, + "-delay", actual_delay, "-text", keystr], stdout = FNULL, stderr = FNULL) def system_retry(num_retry, cmd): i = 0 - rtn = os.system(cmd) + rtn = intr_system(cmd) while ( ( i < num_retry ) and ( rtn != 0) ): i = i + 1 - rtn=os.system(cmd) + rtn = intr_system(cmd) time.sleep(1) if ( rtn != 0 ): print "Command Failed: "+cmd @@ -220,11 +230,11 @@ def system_retry(num_retry, cmd): 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") - system_retry(30, "wmctrl -a '"+lyx_window_name+"'") + #intr_system("echo x-session-manager PID: $X_PID.") + #intr_system("echo x-session-manager open files: `lsof -p $X_PID | grep ICE-unix | wc -l`") + ####intr_system("wmctrl -l | ( grep '"+lyx_window_name+"' || ( killall lyx ; sleep 1 ; killall -9 lyx ))") + #intr_system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1") + system_retry(30, "wmctrl -i -a '"+lyx_window_name+"'") lyx_pid = os.environ.get('LYX_PID') @@ -240,14 +250,36 @@ max_loops = os.environ.get('MAX_LOOPS') if max_loops is None: max_loops = 3 +PACKAGE = os.environ.get('PACKAGE') +if not PACKAGE is None: + print "PACKAGE = " + PACKAGE + "\n" + +PO_BUILD_DIR = os.environ.get('PO_BUILD_DIR') +if not PO_BUILD_DIR is None: + print "PO_BUILD_DIR = " + PO_BUILD_DIR + "\n" + +lyx = os.environ.get('LYX') +if lyx is None: + lyx = "lyx" + lyx_exe = os.environ.get('LYX_EXE') if lyx_exe is None: - lyx_exe = "lyx" + lyx_exe = lyx xvkbd_exe = os.environ.get('XVKBD_EXE') if xvkbd_exe is None: xvkbd_exe = "xvkbd" +xvkbd_hacked = os.environ.get('XVKBD_HACKED') != None + +locale_dir = os.environ.get('LOCALE_DIR') +if locale_dir is None: + locale_dir = '.' + +def_delay = os.environ.get('XVKBD_DELAY') +if def_delay is None: + def_delay = '100' + file_new_command = os.environ.get('FILE_NEW_COMMAND') if file_new_command is None: file_new_command = "\Afn" @@ -286,7 +318,7 @@ write_commands = True failed = False while not failed: - #os.system('echo -n LOADAVG:; cat /proc/loadavg') + #intr_system('echo -n LOADAVG:; cat /proc/loadavg') c = x.getCommand() if c is None: break @@ -295,23 +327,23 @@ while not failed: outfile.writelines(c + '\n') outfile.flush() if c[0] == '#': - print "\nIgnoring comment line: " + c + print "Ignoring comment line: " + c elif c[0:9] == 'TestBegin': print "\n" - lyx_pid=os.popen("pidof lyx").read() + lyx_pid=os.popen("pidof " + lyx).read() if lyx_pid != "": print "Found running instance(s) of LyX: " + lyx_pid + ": killing them all\n" - os.system("killall lyx") + intr_system("killall " + lyx, True) time.sleep(0.5) - os.system("killall -KILL lyx") + intr_system("killall -KILL " + lyx, True) time.sleep(0.2) print "Starting LyX . . ." if lyx_userdir is None: - os.system(lyx_exe + c[9:] + "&") + intr_system(lyx_exe + c[9:] + "&") else: - os.system(lyx_exe + " -userdir " + lyx_userdir + " " + c[9:] + "&") + intr_system(lyx_exe + " -userdir " + lyx_userdir + " " + c[9:] + "&") while True: - lyx_pid=os.popen("pidof lyx").read().rstrip() + lyx_pid=os.popen("pidof " + lyx).read().rstrip() if lyx_pid != "": lyx_window_name=os.popen("wmctrl -l -p | grep ' " + str(lyx_pid) + " ' | cut -d ' ' -f 1").read().rstrip() if lyx_window_name != "": @@ -322,12 +354,11 @@ while not failed: print 'lyx_pid: ' + lyx_pid + '\n' print 'lyx_win: ' + lyx_window_name + '\n' elif c[0:5] == 'Sleep': - print "\nSleeping for " + c[6:] + "\n" + print "Sleeping for " + c[6:] + " seconds\n" time.sleep(float(c[6:])) elif c[0:4] == 'Exec': cmd = c[5:].rstrip() - print "\nExecuting " + cmd + "\n" - os.system(cmd) + intr_system(cmd) elif c == 'Loop': outfile.close() outfile = open(outfilename + '+', 'w') @@ -339,37 +370,83 @@ while not failed: if lyx_exists(): sendKeystring(c[4:], lyx_pid) else: - ##os.system('killall lyx; sleep 2 ; killall -9 lyx') - print 'No path /proc/' + lyx_pid + '/status, exiting' + ##intr_system('killall lyx; sleep 2 ; killall -9 lyx') + if lyx_pid is None: + print 'No path /proc/xxxx/status, exiting' + else: + print 'No path /proc/' + lyx_pid + '/status, exiting' os._exit(1) elif c[0:4] == 'KD: ': - DELAY = c[4:].rstrip('\n') - print 'Setting DELAY to ' + DELAY + '.' + key_delay = c[4:].rstrip('\n') + print 'Setting DELAY to ' + key_delay + '.\n' elif c == 'Loop': RaiseWindow() sendKeystring(ResetCommand, lyx_pid) elif c[0:6] == 'Assert': cmd = c[7:].rstrip() - print "\nExecuting " + cmd - result = os.system(cmd) + result = intr_system(cmd) failed = failed or (result != 0) print "result=" + str(result) + ", failed=" + str(failed) elif c[0:7] == 'TestEnd': time.sleep(0.5) - print "\nTerminating lyx instance: " + str(lyx_pid) + "\n" - os.system("kill -9 " + str(lyx_pid) + "\n"); - while lyx_exists(): - print "Waiting for lyx to die...\n" - time.sleep(0.5) + if not lyx_exists(): + print "LyX instance not found because of crash or assert !\n" + failed = True + else: + print "Terminating lyx instance: " + str(lyx_pid) + "\n" + intr_system("kill -9 " + str(lyx_pid), True); + while lyx_exists(): + print "Waiting for lyx to die...\n" + time.sleep(0.5) cmd = c[8:].rstrip() - print "\nExecuting " + cmd - result = os.system(cmd) + print "Executing " + cmd + result = intr_system(cmd) failed = failed or (result != 0) print "result=" + str(result) + ", failed=" + str(failed) elif c[0:4] == 'Lang': lang = c[5:].rstrip() - print "\nSetting LANG=" + lang + print "Setting LANG=" + lang + "\n" os.environ['LANG'] = lang + os.environ['LC_ALL'] = lang +# If it doesn't exist, create a link //LC_MESSAGES/lyx.mo +# pointing to the corresponding .gmo file. Needed to let lyx find the right translation files. +# See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg165613.html + idx = lang.rfind(".") + if idx != -1: + ccode = lang[0:idx] + else: + ccode = lang + + print "Setting LANGUAGE=" + ccode + "\n" + os.environ['LANGUAGE'] = ccode + + idx = lang.find("_") + if idx != -1: + short_code = lang[0:idx] + else: + short_code = ccode + lyx_dir = os.popen("dirname \"" + lyx_exe + "\"").read().rstrip() + if PACKAGE is None: + # on cmake-build there is no Makefile in this directory + # so PACKAGE has to be provided + if os.path.exists(lyx_dir + "/Makefile"): + print "Executing: grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'" + lyx_name = os.popen("grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'").read().rstrip() + else: + print 'Could not determine PACKAGE name needed for translations\n' + failed = True + else: + lyx_name = PACKAGE + intr_system("mkdir -p " + locale_dir + "/" + ccode + "/LC_MESSAGES") + intr_system("rm -f " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo") + if PO_BUILD_DIR is None: + if lyx_dir[0:3] == "../": + rel_dir = "../../" + lyx_dir + else: + rel_dir = lyx_dir + intr_system("ln -s " + rel_dir + "/../po/" + short_code + ".gmo " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo") + else: + intr_system("ln -s " + PO_BUILD_DIR + "/" + short_code + ".gmo " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo") else: print "Unrecognised Command '" + c + "'\n" failed = True