2011-01-29 14:42:53 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# This script generates hundreds of random keypresses per second,
|
|
|
|
# and sends them to the lyx window
|
|
|
|
# It requires xvkbd and wmctrl
|
|
|
|
# It generates a log of the KEYCODES it sends as development/keystest/out/KEYCODES
|
|
|
|
#
|
|
|
|
# Adapted by Tommaso Cucinotta from the original MonKey Test by
|
|
|
|
# John McCabe-Dansted.
|
|
|
|
|
2017-04-24 15:42:24 +00:00
|
|
|
from __future__ import print_function
|
2011-01-29 14:42:53 +00:00
|
|
|
import random
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
#from subprocess import call
|
|
|
|
import subprocess
|
|
|
|
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Beginning keytest.py')
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
FNULL = open('/dev/null', 'w')
|
|
|
|
|
2011-02-06 22:50:07 +00:00
|
|
|
key_delay = ''
|
2011-01-29 14:42:53 +00:00
|
|
|
|
2017-05-12 19:28:57 +00:00
|
|
|
# Ignore status == "dead" if this is set. Used at the last commands after "\Cq"
|
|
|
|
dead_expected = False
|
|
|
|
|
2017-05-16 11:01:43 +00:00
|
|
|
def die(excode, text):
|
|
|
|
if text != "":
|
|
|
|
print(text)
|
|
|
|
sys.stdout.flush()
|
|
|
|
os._exit(excode)
|
|
|
|
|
2011-01-29 14:42:53 +00:00
|
|
|
class CommandSource:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
keycode = [
|
|
|
|
"\[Left]",
|
|
|
|
'\[Right]',
|
|
|
|
'\[Down]',
|
|
|
|
'\[Up]',
|
|
|
|
'\[BackSpace]',
|
|
|
|
'\[Delete]',
|
|
|
|
'\[Escape]',
|
|
|
|
]
|
|
|
|
keycode[:0] = keycode
|
|
|
|
keycode[:0] = keycode
|
|
|
|
|
|
|
|
keycode[:0] = ['\\']
|
|
|
|
|
|
|
|
for k in range(97, 123):
|
|
|
|
keycode[:0] = chr(k)
|
|
|
|
|
|
|
|
for k in range(97, 123):
|
|
|
|
keycode[:0] = ["\A" + chr(k)]
|
|
|
|
|
|
|
|
for k in range(97, 123):
|
|
|
|
keycode[:0] = ["\A" + chr(k)]
|
|
|
|
|
|
|
|
for k in range(97, 123):
|
|
|
|
keycode[:0] = ["\C" + chr(k)]
|
|
|
|
|
|
|
|
self.keycode = keycode
|
|
|
|
self.count = 0
|
|
|
|
self.count_max = 1999
|
|
|
|
|
|
|
|
def getCommand(self):
|
|
|
|
self.count = self.count + 1
|
|
|
|
if self.count % 200 == 0:
|
|
|
|
return 'RaiseLyx'
|
|
|
|
elif self.count > self.count_max:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(0, "")
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
|
|
|
keystr = ''
|
|
|
|
for k in range(1, 2):
|
|
|
|
keystr = keystr + self.keycode[random.randint(1,
|
|
|
|
len(self.keycode)) - 1]
|
|
|
|
return 'KK: ' + keystr
|
|
|
|
|
|
|
|
|
|
|
|
class CommandSourceFromFile(CommandSource):
|
|
|
|
|
|
|
|
def __init__(self, filename, p):
|
|
|
|
|
|
|
|
self.infile = open(filename, 'r')
|
|
|
|
self.lines = self.infile.readlines()
|
|
|
|
self.infile.close()
|
|
|
|
linesbak = self.lines
|
|
|
|
self.p = p
|
2017-04-24 15:42:24 +00:00
|
|
|
print(p, self.p, 'self.p')
|
2011-01-29 14:42:53 +00:00
|
|
|
self.i = 0
|
|
|
|
self.count = 0
|
|
|
|
self.loops = 0
|
|
|
|
|
|
|
|
# Now we start randomly dropping lines, which we hope are redundant
|
|
|
|
# p is the probability that any given line will be removed
|
|
|
|
|
|
|
|
if p > 0.001:
|
|
|
|
if random.uniform(0, 1) < 0.5:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('randomdrop_independant\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
self.randomdrop_independant()
|
|
|
|
else:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('randomdrop_slice\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
self.randomdrop_slice()
|
|
|
|
if screenshot_out is None:
|
|
|
|
count_atleast = 100
|
|
|
|
else:
|
|
|
|
count_atleast = 1
|
|
|
|
self.max_count = max(len(self.lines) + 20, count_atleast)
|
|
|
|
if len(self.lines) < 1:
|
|
|
|
self.lines = linesbak
|
|
|
|
|
|
|
|
def randomdrop_independant(self):
|
|
|
|
p = self.p
|
|
|
|
|
|
|
|
# The next couple of lines are to ensure that at least one line is dropped
|
|
|
|
|
|
|
|
drop = random.randint(0, len(self.lines) - 1)
|
|
|
|
del self.lines[drop]
|
|
|
|
#p = p - 1 / len(self.lines)
|
|
|
|
origlines = self.lines
|
|
|
|
self.lines = []
|
|
|
|
for l in origlines:
|
|
|
|
if random.uniform(0, 1) < self.p:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Randomly dropping line ' + l + '\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
|
|
|
self.lines.append(l)
|
2017-04-24 15:42:24 +00:00
|
|
|
print('LINES\n')
|
|
|
|
print(self.lines)
|
2011-01-29 14:42:53 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
def randomdrop_slice(self):
|
|
|
|
lines = self.lines
|
|
|
|
if random.uniform(0, 1) < 0.4:
|
|
|
|
lines.append(lines[0])
|
|
|
|
del lines[0]
|
|
|
|
num_lines = len(lines)
|
|
|
|
max_drop = max(5, num_lines / 5)
|
|
|
|
num_drop = random.randint(1, 5)
|
|
|
|
drop_mid = random.randint(0, num_lines)
|
|
|
|
drop_start = max(drop_mid - num_drop / 2, 0)
|
|
|
|
drop_end = min(drop_start + num_drop, num_lines)
|
2017-04-24 15:42:24 +00:00
|
|
|
print(drop_start, drop_mid, drop_end)
|
|
|
|
print(lines)
|
2011-01-29 14:42:53 +00:00
|
|
|
del lines[drop_start:drop_end]
|
2017-04-24 15:42:24 +00:00
|
|
|
print(lines)
|
2011-01-29 14:42:53 +00:00
|
|
|
self.lines = lines
|
|
|
|
|
|
|
|
def getCommand(self):
|
|
|
|
if self.count >= self.max_count:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(0, "")
|
2011-01-29 14:42:53 +00:00
|
|
|
if self.i >= len(self.lines):
|
|
|
|
self.loops = self.loops + 1
|
2011-01-30 15:58:08 +00:00
|
|
|
if self.loops >= int(max_loops):
|
2011-01-30 19:44:31 +00:00
|
|
|
return None
|
2011-01-29 14:42:53 +00:00
|
|
|
self.i = 0
|
|
|
|
return 'Loop'
|
2011-01-30 19:44:31 +00:00
|
|
|
line = self.lines[self.i].rstrip('\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
self.count = self.count + 1
|
|
|
|
self.i = self.i + 1
|
2011-01-30 19:44:31 +00:00
|
|
|
return line
|
2011-01-29 14:42:53 +00:00
|
|
|
|
2017-05-16 07:16:18 +00:00
|
|
|
class ControlFile:
|
|
|
|
|
|
|
|
def __init__(self):
|
2017-05-16 11:01:43 +00:00
|
|
|
self.control = re.compile(r'^(C[ONPRC]):\s*(.*)$')
|
2017-05-17 22:03:50 +00:00
|
|
|
self.fileformat = re.compile(r'^((\>\>?)[,\s]\s*)?([^\s]+)\s*$')
|
2017-05-16 07:16:18 +00:00
|
|
|
self.cntrname = None
|
|
|
|
self.cntrfile = None
|
|
|
|
|
|
|
|
def open(self, filename):
|
2017-05-17 22:03:50 +00:00
|
|
|
if not self.cntrfile is None:
|
|
|
|
self.cntrfile.close()
|
|
|
|
self.cntrfile = None
|
|
|
|
self.cntrname = None
|
|
|
|
m = self.fileformat.match(filename)
|
|
|
|
if m:
|
|
|
|
type = m.group(2)
|
|
|
|
filename = m.group(3)
|
|
|
|
if type == '>>':
|
|
|
|
append = True
|
|
|
|
else:
|
|
|
|
append = False
|
|
|
|
else:
|
|
|
|
append = False
|
2017-05-16 07:16:18 +00:00
|
|
|
self.cntrname = filename
|
2017-05-17 22:03:50 +00:00
|
|
|
if append:
|
|
|
|
self.cntrfile = open(filename, 'a')
|
|
|
|
else:
|
|
|
|
self.cntrfile = open(filename, 'w')
|
2017-05-16 07:16:18 +00:00
|
|
|
|
|
|
|
def close(self):
|
|
|
|
if not self.cntrfile is None:
|
|
|
|
self.cntrfile.close()
|
|
|
|
self.cntrfile = None
|
|
|
|
self.cntrname = None
|
2017-05-17 22:03:50 +00:00
|
|
|
# make the method below 'private'
|
|
|
|
def __addline(self, pat):
|
2017-05-16 07:16:18 +00:00
|
|
|
self.cntrfile.writelines(pat + "\n")
|
|
|
|
|
|
|
|
def getfname(self):
|
|
|
|
return self.cntrname
|
|
|
|
|
|
|
|
def dispatch(self, c):
|
|
|
|
m = self.control.match(c)
|
|
|
|
if not m:
|
|
|
|
return False
|
|
|
|
command = m.group(1)
|
|
|
|
text = m.group(2)
|
|
|
|
if command == "CO":
|
|
|
|
self.open(text);
|
|
|
|
elif command == "CC":
|
|
|
|
self.close()
|
|
|
|
else:
|
|
|
|
if self.cntrfile is None:
|
|
|
|
print("Controlfile not initialized")
|
|
|
|
else:
|
|
|
|
if command == "CN":
|
2017-05-17 22:03:50 +00:00
|
|
|
self.__addline("Comment: " + text)
|
2017-05-16 07:16:18 +00:00
|
|
|
elif command == "CP":
|
2017-05-17 22:03:50 +00:00
|
|
|
self.__addline("Simple: " + text)
|
2017-05-16 07:16:18 +00:00
|
|
|
elif command == "CR":
|
2017-05-17 22:03:50 +00:00
|
|
|
self.__addline("Regex: " + text)
|
2017-05-16 07:16:18 +00:00
|
|
|
else:
|
2017-05-17 10:12:55 +00:00
|
|
|
die(1,"Error, Unrecognised Command '" + command + "'")
|
2017-05-16 07:16:18 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2017-05-12 09:22:05 +00:00
|
|
|
def get_proc_pid(proc_name):
|
|
|
|
pid=os.popen("pidof " + proc_name).read().rstrip()
|
|
|
|
return pid
|
|
|
|
|
|
|
|
wlistreg = re.compile(r'^(0x[0-9a-f]{5,9})\s+[^\s]+\s+([0-9]+)\s.*$')
|
|
|
|
def get_proc_win_id(pid, ignoreid):
|
|
|
|
nlist = os.popen("wmctrl -l -p").read()
|
|
|
|
wlist = nlist.split("\n")
|
|
|
|
for item in wlist:
|
|
|
|
m = wlistreg.match(item)
|
|
|
|
if m:
|
|
|
|
win_id = m.group(1)
|
|
|
|
win_pid = m.group(2)
|
|
|
|
if win_pid == pid:
|
|
|
|
if win_id != ignoreid:
|
|
|
|
return win_id
|
|
|
|
return None
|
2017-01-25 01:08:28 +00:00
|
|
|
|
2011-01-30 15:58:08 +00:00
|
|
|
def lyx_exists():
|
|
|
|
if lyx_pid is None:
|
|
|
|
return False
|
|
|
|
fname = '/proc/' + lyx_pid + '/status'
|
|
|
|
return os.path.exists(fname)
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
|
2011-02-06 22:16:51 +00:00
|
|
|
# Interruptible os.system()
|
2011-02-10 22:33:23 +00:00
|
|
|
def intr_system(cmd, ignore_err = False):
|
2017-05-07 12:40:08 +00:00
|
|
|
print("Executing " + cmd)
|
2017-05-17 10:12:55 +00:00
|
|
|
# Assure the output of cmd does not overhaul
|
|
|
|
sys.stdout.flush()
|
2011-02-06 22:16:51 +00:00
|
|
|
ret = os.system(cmd)
|
|
|
|
if os.WIFSIGNALED(ret):
|
|
|
|
raise KeyboardInterrupt
|
2011-02-10 22:33:23 +00:00
|
|
|
if ret != 0 and not ignore_err:
|
2017-01-25 01:08:28 +00:00
|
|
|
raise BaseException("command failed:" + cmd)
|
2011-02-06 22:16:51 +00:00
|
|
|
return ret
|
|
|
|
|
2017-04-24 15:42:24 +00:00
|
|
|
statreg = re.compile(r'^State:.*\(([a-z]+)\)')
|
|
|
|
|
2017-05-12 09:22:05 +00:00
|
|
|
resstatus = []
|
|
|
|
def printresstatus():
|
|
|
|
for line in resstatus:
|
|
|
|
line = line.rstrip()
|
|
|
|
print(" " + line.rstrip())
|
|
|
|
print('End of /proc-lines')
|
|
|
|
|
2017-05-12 11:55:51 +00:00
|
|
|
def lyx_status_retry(pid):
|
2017-05-12 09:22:05 +00:00
|
|
|
resstatus = []
|
2017-05-17 22:03:50 +00:00
|
|
|
if pid is None:
|
2017-05-12 11:55:51 +00:00
|
|
|
print('Pid is None')
|
2017-05-12 09:22:05 +00:00
|
|
|
return "dead"
|
|
|
|
fname = '/proc/' + pid + '/status'
|
|
|
|
status = "dead"
|
|
|
|
try:
|
|
|
|
f = open(fname)
|
|
|
|
found = False
|
|
|
|
for line in f:
|
|
|
|
resstatus.extend([line])
|
|
|
|
m = statreg.match(line)
|
|
|
|
if m:
|
|
|
|
status = m.group(1)
|
|
|
|
found = True
|
2017-04-24 15:42:24 +00:00
|
|
|
f.close()
|
2017-05-12 11:55:51 +00:00
|
|
|
if not found:
|
|
|
|
return "retry"
|
2017-04-24 15:42:24 +00:00
|
|
|
return status
|
2017-05-12 09:22:05 +00:00
|
|
|
except IOError as e:
|
|
|
|
print("I/O error({0}): {1}".format(e.errno, e.strerror))
|
|
|
|
return "dead"
|
|
|
|
except:
|
|
|
|
print("Unexpected error:", sys.exc_info()[0])
|
|
|
|
return "dead"
|
2017-05-12 11:55:51 +00:00
|
|
|
print('This should not happen')
|
|
|
|
return status
|
|
|
|
|
|
|
|
def lyx_status(pid):
|
|
|
|
count = 0
|
|
|
|
while 1:
|
|
|
|
status = lyx_status_retry(pid)
|
|
|
|
if status != "retry":
|
|
|
|
break
|
|
|
|
if count == 0:
|
|
|
|
print('Retrying check for status')
|
|
|
|
count += 1
|
|
|
|
time.sleep(0.01)
|
2017-05-12 19:28:57 +00:00
|
|
|
if count > 1:
|
2017-05-12 11:55:51 +00:00
|
|
|
print('Retried to read status ' + str(count) + ' times')
|
2017-05-12 19:28:57 +00:00
|
|
|
#print('lys_status() returning ' + status)
|
2017-05-12 09:22:05 +00:00
|
|
|
return status
|
2011-02-06 22:16:51 +00:00
|
|
|
|
2017-01-25 01:08:28 +00:00
|
|
|
# Return true if LyX (identified via lyx_pid) is sleeping
|
2017-05-12 19:28:57 +00:00
|
|
|
def lyx_sleeping(LYX_PID):
|
|
|
|
return lyx_status(LYX_PID) == "sleeping"
|
2017-04-24 15:42:24 +00:00
|
|
|
|
|
|
|
# Return true if LyX (identified via lyx_pid) is zombie
|
2017-05-12 19:28:57 +00:00
|
|
|
def lyx_zombie(LYX_PID):
|
|
|
|
return lyx_status(LYX_PID) == "zombie"
|
2017-01-25 01:08:28 +00:00
|
|
|
|
2017-05-12 19:28:57 +00:00
|
|
|
def lyx_dead(LYX_PID):
|
|
|
|
status = lyx_status(LYX_PID)
|
2017-04-24 15:42:24 +00:00
|
|
|
return (status == "dead") or (status == "zombie")
|
2017-01-25 01:08:28 +00:00
|
|
|
|
2017-05-12 19:28:57 +00:00
|
|
|
def wait_until_lyx_sleeping(LYX_PID):
|
2011-01-29 14:42:53 +00:00
|
|
|
before_secs = time.time()
|
2017-05-10 22:00:42 +00:00
|
|
|
while True:
|
2017-05-12 19:28:57 +00:00
|
|
|
status = lyx_status(LYX_PID)
|
2017-05-10 22:00:42 +00:00
|
|
|
if status == "sleeping":
|
2017-05-12 19:28:57 +00:00
|
|
|
return True
|
2017-05-10 22:00:42 +00:00
|
|
|
if (status == "dead") or (status == "zombie"):
|
2017-05-12 09:22:05 +00:00
|
|
|
printresstatus()
|
2017-05-12 19:28:57 +00:00
|
|
|
if dead_expected:
|
|
|
|
print('Lyx died while waiting for status == sleeping')
|
|
|
|
return False
|
|
|
|
else:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1,"Lyx is dead, exiting")
|
2011-01-29 14:42:53 +00:00
|
|
|
if time.time() - before_secs > 180:
|
|
|
|
# Do profiling, but sysprof has no command line interface?
|
2011-02-06 22:16:51 +00:00
|
|
|
# intr_system("killall -KILL lyx")
|
2017-05-12 09:22:05 +00:00
|
|
|
printresstatus()
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1,"Killing due to freeze (KILL_FREEZE)")
|
2017-05-10 22:00:42 +00:00
|
|
|
time.sleep(0.02)
|
2017-05-12 19:28:57 +00:00
|
|
|
# Should be never reached
|
|
|
|
print('Wait for sleeping ends unexpectedly')
|
|
|
|
return False
|
2017-05-10 22:00:42 +00:00
|
|
|
|
|
|
|
def sendKeystringLocal(keystr, LYX_PID):
|
2017-05-12 19:28:57 +00:00
|
|
|
is_sleeping = wait_until_lyx_sleeping(LYX_PID)
|
|
|
|
if not is_sleeping:
|
|
|
|
print("Not sending \"" + keystr + "\"")
|
|
|
|
return
|
2011-01-29 14:42:53 +00:00
|
|
|
if not screenshot_out is None:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Making Screenshot: ' + screenshot_out + ' OF ' + infilename)
|
2011-01-29 14:42:53 +00:00
|
|
|
time.sleep(0.2)
|
2011-02-06 22:16:51 +00:00
|
|
|
intr_system('import -window root '+screenshot_out+str(x.count)+".png")
|
2011-01-29 14:42:53 +00:00
|
|
|
time.sleep(0.1)
|
2011-02-06 22:50:07 +00:00
|
|
|
actual_delay = key_delay
|
|
|
|
if actual_delay == '':
|
|
|
|
actual_delay = def_delay
|
2015-03-17 16:36:47 +00:00
|
|
|
xvpar = [xvkbd_exe]
|
|
|
|
if qt_frontend == 'QT5':
|
2017-05-09 19:07:35 +00:00
|
|
|
xvpar.extend(["-jump-pointer", "-no-back-pointer"])
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
2015-03-17 16:36:47 +00:00
|
|
|
xvpar.extend(["-xsendevent"])
|
2017-05-12 09:22:05 +00:00
|
|
|
if lyx_other_window_name is None:
|
|
|
|
xvpar.extend(["-window", lyx_window_name])
|
|
|
|
else:
|
|
|
|
xvpar.extend(["-window", lyx_other_window_name])
|
2017-05-10 22:00:42 +00:00
|
|
|
xvpar.extend(["-delay", actual_delay, "-text", keystr])
|
2017-05-04 11:53:09 +00:00
|
|
|
print("Sending \"" + keystr + "\"")
|
2015-03-17 16:36:47 +00:00
|
|
|
subprocess.call(xvpar, stdout = FNULL, stderr = FNULL)
|
2017-05-10 22:00:42 +00:00
|
|
|
sys.stdout.flush()
|
2011-01-29 14:42:53 +00:00
|
|
|
|
2017-04-26 14:03:24 +00:00
|
|
|
Axreg = re.compile(r'^(.*)\\Ax([^\\]*)(.*)$')
|
2017-05-09 19:07:35 +00:00
|
|
|
returnreg = re.compile(r'(\\\[[A-Z][a-z]+\])(.*)$')
|
2017-04-25 15:34:56 +00:00
|
|
|
|
2017-04-26 14:03:24 +00:00
|
|
|
# recursive wrapper around sendKeystringLocal()
|
2017-05-04 11:53:09 +00:00
|
|
|
# handling \Ax-entries
|
|
|
|
def sendKeystringAx(line, LYX_PID):
|
2017-04-25 15:34:56 +00:00
|
|
|
global key_delay
|
|
|
|
saved_delay = key_delay
|
2017-04-26 14:03:24 +00:00
|
|
|
m = Axreg.match(line)
|
|
|
|
if m:
|
|
|
|
prefix = m.group(1)
|
|
|
|
content = m.group(2)
|
|
|
|
rest = m.group(3);
|
|
|
|
if prefix != "":
|
|
|
|
# since (.*) is greedy, check prefix for '\Ax' again
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringAx(prefix, LYX_PID)
|
2017-04-26 14:03:24 +00:00
|
|
|
sendKeystringLocal('\Ax', LYX_PID)
|
|
|
|
time.sleep(0.1)
|
|
|
|
m2 = returnreg.match(rest)
|
|
|
|
if m2:
|
2017-05-09 19:07:35 +00:00
|
|
|
line = m2.group(2)
|
|
|
|
ctrlk = m2.group(1)
|
2017-04-26 14:03:24 +00:00
|
|
|
key_delay = "1"
|
2017-05-09 19:07:35 +00:00
|
|
|
sendKeystringLocal(content + ctrlk, LYX_PID)
|
2017-04-26 14:03:24 +00:00
|
|
|
key_delay = saved_delay
|
2017-05-09 19:07:35 +00:00
|
|
|
time.sleep(controlkey_delay)
|
2017-04-25 15:34:56 +00:00
|
|
|
if line != "":
|
|
|
|
sendKeystringLocal(line, LYX_PID)
|
2017-04-26 14:03:24 +00:00
|
|
|
else:
|
|
|
|
if content != "":
|
|
|
|
sendKeystringLocal(content, LYX_PID)
|
|
|
|
if rest != "":
|
|
|
|
sendKeystringLocal(rest, LYX_PID)
|
|
|
|
else:
|
|
|
|
if line != "":
|
|
|
|
sendKeystringLocal(line, LYX_PID)
|
|
|
|
|
2017-05-10 22:00:42 +00:00
|
|
|
specialkeyreg = re.compile(r'(.+)(\\[AC]([a-zA-Z]|\\\[[A-Z][a-z]+\]).*)$')
|
|
|
|
# Split line at start of each meta or controll char
|
2017-05-07 12:40:08 +00:00
|
|
|
|
|
|
|
def sendKeystringAC(line, LYX_PID):
|
|
|
|
m = specialkeyreg.match(line)
|
|
|
|
if m:
|
|
|
|
first = m.group(1)
|
|
|
|
second = m.group(2)
|
|
|
|
sendKeystringAC(first, LYX_PID)
|
|
|
|
sendKeystringAC(second, LYX_PID)
|
|
|
|
else:
|
|
|
|
sendKeystringAx(line, LYX_PID)
|
|
|
|
|
2017-05-04 11:53:09 +00:00
|
|
|
controlkeyreg = re.compile(r'^(.*\\\[[A-Z][a-z]+\])(.*\\\[[A-Z][a-z]+\])(.*)$')
|
|
|
|
# Make sure, only one of \[Return], \[Tab], \[Down], \[Home] etc are in one sent line
|
|
|
|
# e.g. split the input line on each keysym
|
|
|
|
def sendKeystringRT(line, LYX_PID):
|
|
|
|
m = controlkeyreg.match(line)
|
|
|
|
if m:
|
|
|
|
first = m.group(1)
|
|
|
|
second = m.group(2)
|
|
|
|
third = m.group(3)
|
|
|
|
sendKeystringRT(first, LYX_PID)
|
2017-05-09 19:07:35 +00:00
|
|
|
time.sleep(controlkey_delay)
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringRT(second, LYX_PID)
|
2017-05-09 19:07:35 +00:00
|
|
|
time.sleep(controlkey_delay)
|
2017-05-04 11:53:09 +00:00
|
|
|
if third != "":
|
|
|
|
sendKeystringRT(third, LYX_PID)
|
|
|
|
else:
|
2017-05-07 12:40:08 +00:00
|
|
|
sendKeystringAC(line, LYX_PID)
|
2017-04-25 15:34:56 +00:00
|
|
|
|
2011-01-29 14:42:53 +00:00
|
|
|
def system_retry(num_retry, cmd):
|
|
|
|
i = 0
|
2011-02-06 22:16:51 +00:00
|
|
|
rtn = intr_system(cmd)
|
2011-01-29 14:42:53 +00:00
|
|
|
while ( ( i < num_retry ) and ( rtn != 0) ):
|
|
|
|
i = i + 1
|
2015-03-17 16:36:47 +00:00
|
|
|
rtn = intr_system(cmd)
|
2011-01-29 14:42:53 +00:00
|
|
|
time.sleep(1)
|
|
|
|
if ( rtn != 0 ):
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Command Failed: "+cmd)
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1," EXITING!")
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
def RaiseWindow():
|
2011-02-06 22:16:51 +00:00
|
|
|
#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 ))")
|
2017-04-26 14:03:24 +00:00
|
|
|
print("lyx_window_name = " + lyx_window_name + "\n")
|
|
|
|
intr_system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1")
|
2012-12-11 17:59:05 +00:00
|
|
|
system_retry(30, "wmctrl -i -a '"+lyx_window_name+"'")
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
lyx_pid = os.environ.get('LYX_PID')
|
2017-04-24 15:42:24 +00:00
|
|
|
print('lyx_pid: ' + str(lyx_pid) + '\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
infilename = os.environ.get('KEYTEST_INFILE')
|
|
|
|
outfilename = os.environ.get('KEYTEST_OUTFILE')
|
|
|
|
max_drop = os.environ.get('MAX_DROP')
|
|
|
|
lyx_window_name = os.environ.get('LYX_WINDOW_NAME')
|
2017-05-12 09:22:05 +00:00
|
|
|
lyx_other_window_name = None
|
2011-01-29 14:42:53 +00:00
|
|
|
screenshot_out = os.environ.get('SCREENSHOT_OUT')
|
2011-02-01 22:08:07 +00:00
|
|
|
lyx_userdir = os.environ.get('LYX_USERDIR')
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
max_loops = os.environ.get('MAX_LOOPS')
|
|
|
|
if max_loops is None:
|
|
|
|
max_loops = 3
|
|
|
|
|
2017-05-14 16:57:25 +00:00
|
|
|
extra_path = os.environ.get('EXTRA_PATH')
|
|
|
|
if not extra_path is None:
|
|
|
|
os.environ['PATH'] = extra_path + os.pathsep + os.environ['PATH']
|
|
|
|
print("Added " + extra_path + " to path")
|
|
|
|
print(os.environ['PATH'])
|
|
|
|
|
2012-12-12 13:54:38 +00:00
|
|
|
PACKAGE = os.environ.get('PACKAGE')
|
|
|
|
if not PACKAGE is None:
|
2017-04-24 15:42:24 +00:00
|
|
|
print("PACKAGE = " + PACKAGE + "\n")
|
2012-12-12 13:54:38 +00:00
|
|
|
|
|
|
|
PO_BUILD_DIR = os.environ.get('PO_BUILD_DIR')
|
|
|
|
if not PO_BUILD_DIR is None:
|
2017-04-24 15:42:24 +00:00
|
|
|
print("PO_BUILD_DIR = " + PO_BUILD_DIR + "\n")
|
2012-12-12 13:54:38 +00:00
|
|
|
|
2013-01-05 09:07:37 +00:00
|
|
|
lyx = os.environ.get('LYX')
|
|
|
|
if lyx is None:
|
|
|
|
lyx = "lyx"
|
|
|
|
|
2011-01-29 14:42:53 +00:00
|
|
|
lyx_exe = os.environ.get('LYX_EXE')
|
|
|
|
if lyx_exe is None:
|
2013-01-05 09:07:37 +00:00
|
|
|
lyx_exe = lyx
|
2011-01-29 14:42:53 +00:00
|
|
|
|
2011-02-02 23:18:16 +00:00
|
|
|
xvkbd_exe = os.environ.get('XVKBD_EXE')
|
|
|
|
if xvkbd_exe is None:
|
|
|
|
xvkbd_exe = "xvkbd"
|
|
|
|
|
2015-03-17 16:36:47 +00:00
|
|
|
qt_frontend = os.environ.get('QT_FRONTEND')
|
|
|
|
if qt_frontend is None:
|
|
|
|
qt_frontend = 'QT4'
|
2017-05-10 22:00:42 +00:00
|
|
|
if qt_frontend == 'QT5':
|
|
|
|
controlkey_delay = 0.01
|
|
|
|
else:
|
|
|
|
controlkey_delay = 0.4
|
2011-02-06 22:50:07 +00:00
|
|
|
|
2011-02-10 22:33:23 +00:00
|
|
|
locale_dir = os.environ.get('LOCALE_DIR')
|
|
|
|
if locale_dir is None:
|
|
|
|
locale_dir = '.'
|
|
|
|
|
2011-02-06 23:14:49 +00:00
|
|
|
def_delay = os.environ.get('XVKBD_DELAY')
|
|
|
|
if def_delay is None:
|
2017-05-10 22:00:42 +00:00
|
|
|
if qt_frontend == 'QT5':
|
2017-05-14 16:57:25 +00:00
|
|
|
def_delay = '1'
|
2017-05-10 22:00:42 +00:00
|
|
|
else:
|
|
|
|
def_delay = '1'
|
2011-02-06 23:14:49 +00:00
|
|
|
|
2011-01-29 14:42:53 +00:00
|
|
|
file_new_command = os.environ.get('FILE_NEW_COMMAND')
|
|
|
|
if file_new_command is None:
|
|
|
|
file_new_command = "\Afn"
|
|
|
|
|
|
|
|
ResetCommand = os.environ.get('RESET_COMMAND')
|
|
|
|
if ResetCommand is None:
|
|
|
|
ResetCommand = "\[Escape]\[Escape]\[Escape]\[Escape]" + file_new_command
|
|
|
|
#ResetCommand="\[Escape]\[Escape]\[Escape]\[Escape]\Cw\Cw\Cw\Cw\Cw\Afn"
|
|
|
|
|
|
|
|
if lyx_window_name is None:
|
|
|
|
lyx_window_name = 'LyX'
|
|
|
|
|
2017-04-24 15:42:24 +00:00
|
|
|
print('outfilename: ' + outfilename + '\n')
|
|
|
|
print('max_drop: ' + max_drop + '\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
if infilename is None:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('infilename is None\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
x = CommandSource()
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Using x=CommandSource\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('infilename: ' + infilename + '\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
probability_we_drop_a_command = random.uniform(0, float(max_drop))
|
2017-04-24 15:42:24 +00:00
|
|
|
print('probability_we_drop_a_command: ')
|
|
|
|
print('%s' % probability_we_drop_a_command)
|
|
|
|
print('\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
x = CommandSourceFromFile(infilename, probability_we_drop_a_command)
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Using x=CommandSourceFromFile\n')
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
outfile = open(outfilename, 'w')
|
|
|
|
|
2011-02-01 22:57:10 +00:00
|
|
|
if not lyx_pid is None:
|
2011-01-29 14:42:53 +00:00
|
|
|
RaiseWindow()
|
2017-04-24 15:42:24 +00:00
|
|
|
# Next command is language dependent
|
2017-05-04 11:53:09 +00:00
|
|
|
#sendKeystringRT("\Afn", lyx_pid)
|
2011-01-29 14:42:53 +00:00
|
|
|
|
|
|
|
write_commands = True
|
2011-01-30 15:58:08 +00:00
|
|
|
failed = False
|
2017-05-10 22:00:42 +00:00
|
|
|
lineempty = re.compile(r'^\s*$')
|
2017-05-16 07:16:18 +00:00
|
|
|
marked = ControlFile()
|
2011-01-30 15:58:08 +00:00
|
|
|
while not failed:
|
2011-02-06 22:16:51 +00:00
|
|
|
#intr_system('echo -n LOADAVG:; cat /proc/loadavg')
|
2011-01-29 14:42:53 +00:00
|
|
|
c = x.getCommand()
|
2011-01-30 19:44:31 +00:00
|
|
|
if c is None:
|
|
|
|
break
|
2017-05-10 22:00:42 +00:00
|
|
|
|
|
|
|
# Do not strip trailing spaces, only check for 'empty' lines
|
|
|
|
if lineempty.match(c):
|
2011-01-30 19:44:31 +00:00
|
|
|
continue
|
2011-01-29 14:42:53 +00:00
|
|
|
outfile.writelines(c + '\n')
|
|
|
|
outfile.flush()
|
2017-05-16 07:16:18 +00:00
|
|
|
if marked.dispatch(c):
|
|
|
|
continue
|
2011-01-29 14:42:53 +00:00
|
|
|
if c[0] == '#':
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Ignoring comment line: " + c)
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c[0:9] == 'TestBegin':
|
2017-04-24 15:42:24 +00:00
|
|
|
print("\n")
|
2017-05-12 09:22:05 +00:00
|
|
|
lyx_pid=get_proc_pid(lyx)
|
2011-01-29 14:42:53 +00:00
|
|
|
if lyx_pid != "":
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Found running instance(s) of LyX: " + lyx_pid + ": killing them all\n")
|
2013-01-05 09:07:37 +00:00
|
|
|
intr_system("killall " + lyx, True)
|
2011-02-01 22:57:10 +00:00
|
|
|
time.sleep(0.5)
|
2013-01-05 09:07:37 +00:00
|
|
|
intr_system("killall -KILL " + lyx, True)
|
2017-05-12 11:55:51 +00:00
|
|
|
time.sleep(0.2)
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Starting LyX . . .")
|
2011-02-01 22:08:07 +00:00
|
|
|
if lyx_userdir is None:
|
2011-02-06 22:16:51 +00:00
|
|
|
intr_system(lyx_exe + c[9:] + "&")
|
2011-02-01 22:08:07 +00:00
|
|
|
else:
|
2011-02-06 22:16:51 +00:00
|
|
|
intr_system(lyx_exe + " -userdir " + lyx_userdir + " " + c[9:] + "&")
|
2017-05-12 11:55:51 +00:00
|
|
|
count = 10
|
2017-05-04 11:53:09 +00:00
|
|
|
old_lyx_pid = "-7"
|
2017-05-12 09:22:05 +00:00
|
|
|
old_lyx_window_name = None
|
2017-05-04 11:53:09 +00:00
|
|
|
print("Waiting for LyX to show up . . .")
|
2014-08-25 11:49:12 +00:00
|
|
|
while count > 0:
|
2017-05-12 09:22:05 +00:00
|
|
|
lyx_pid=get_proc_pid(lyx)
|
2017-05-04 11:53:09 +00:00
|
|
|
if lyx_pid != old_lyx_pid:
|
|
|
|
print('lyx_pid=' + lyx_pid)
|
|
|
|
old_lyx_pid = lyx_pid
|
2011-02-01 22:57:10 +00:00
|
|
|
if lyx_pid != "":
|
2017-05-12 09:22:05 +00:00
|
|
|
lyx_window_name=get_proc_win_id(lyx_pid, "")
|
|
|
|
if not lyx_window_name is None:
|
|
|
|
if old_lyx_window_name != lyx_window_name:
|
|
|
|
print('lyx_win=' + lyx_window_name, '\n')
|
|
|
|
old_lyx_window_name = lyx_window_name
|
2011-02-01 22:57:10 +00:00
|
|
|
break
|
2014-08-25 12:28:18 +00:00
|
|
|
else:
|
|
|
|
count = count - 1
|
2017-05-12 11:55:51 +00:00
|
|
|
time.sleep(0.5)
|
2014-08-25 11:49:12 +00:00
|
|
|
if count <= 0:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Timeout: could not start ' + lyx_exe, '\n')
|
2014-08-25 11:49:12 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
failed = True
|
2017-05-12 09:22:05 +00:00
|
|
|
else:
|
|
|
|
print('lyx_pid: ' + lyx_pid)
|
|
|
|
print('lyx_win: ' + lyx_window_name)
|
2017-05-12 19:28:57 +00:00
|
|
|
dead_expected = False
|
2017-05-12 09:22:05 +00:00
|
|
|
sendKeystringLocal("\C\[Home]", lyx_pid)
|
|
|
|
time.sleep(controlkey_delay)
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c[0:5] == 'Sleep':
|
2017-05-07 12:40:08 +00:00
|
|
|
print("Sleeping for " + c[6:] + " seconds")
|
2011-01-29 14:42:53 +00:00
|
|
|
time.sleep(float(c[6:]))
|
|
|
|
elif c[0:4] == 'Exec':
|
|
|
|
cmd = c[5:].rstrip()
|
2011-02-06 22:16:51 +00:00
|
|
|
intr_system(cmd)
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c == 'Loop':
|
|
|
|
outfile.close()
|
|
|
|
outfile = open(outfilename + '+', 'w')
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Now Looping')
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c == 'RaiseLyx':
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Raising Lyx')
|
2011-01-29 14:42:53 +00:00
|
|
|
RaiseWindow()
|
|
|
|
elif c[0:4] == 'KK: ':
|
2011-01-30 15:58:08 +00:00
|
|
|
if lyx_exists():
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringRT(c[4:], lyx_pid)
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
2011-02-06 22:16:51 +00:00
|
|
|
##intr_system('killall lyx; sleep 2 ; killall -9 lyx')
|
2012-12-11 17:59:05 +00:00
|
|
|
if lyx_pid is None:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1, 'No path /proc/xxxx/status, exiting')
|
2012-12-11 17:59:05 +00:00
|
|
|
else:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1, 'No path /proc/' + lyx_pid + '/status, exiting')
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c[0:4] == 'KD: ':
|
2011-02-06 22:50:07 +00:00
|
|
|
key_delay = c[4:].rstrip('\n')
|
2017-05-07 12:40:08 +00:00
|
|
|
print('Setting DELAY to ' + key_delay)
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c == 'Loop':
|
|
|
|
RaiseWindow()
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringRT(ResetCommand, lyx_pid)
|
2011-01-30 15:58:08 +00:00
|
|
|
elif c[0:6] == 'Assert':
|
|
|
|
cmd = c[7:].rstrip()
|
2011-02-06 22:16:51 +00:00
|
|
|
result = intr_system(cmd)
|
2011-01-30 15:58:08 +00:00
|
|
|
failed = failed or (result != 0)
|
2017-04-24 15:42:24 +00:00
|
|
|
print("result=" + str(result) + ", failed=" + str(failed))
|
2017-05-10 22:00:42 +00:00
|
|
|
elif c[0:15] == 'TestEndWithKill':
|
2017-05-16 07:16:18 +00:00
|
|
|
marked.close()
|
2017-05-10 22:00:42 +00:00
|
|
|
cmd = c[16:].rstrip()
|
2017-05-12 19:28:57 +00:00
|
|
|
if lyx_dead(lyx_pid):
|
2017-05-10 22:00:42 +00:00
|
|
|
print("LyX instance not found because of crash or assert !\n")
|
|
|
|
failed = True
|
|
|
|
else:
|
|
|
|
print(" ------------ Forcing kill of lyx instance: " + str(lyx_pid) + " ------------")
|
2017-05-12 09:22:05 +00:00
|
|
|
# This line below is there only to allow lyx to update its log-file
|
|
|
|
sendKeystringLocal("\[Escape]", lyx_pid)
|
2017-05-12 19:28:57 +00:00
|
|
|
dead_expected = True
|
|
|
|
while not lyx_dead(lyx_pid):
|
2017-05-10 22:00:42 +00:00
|
|
|
intr_system("kill -9 " + str(lyx_pid), True);
|
|
|
|
time.sleep(0.5)
|
|
|
|
if cmd != "":
|
|
|
|
print("Executing " + cmd)
|
|
|
|
result = intr_system(cmd)
|
|
|
|
failed = failed or (result != 0)
|
|
|
|
print("result=" + str(result) + ", failed=" + str(failed))
|
|
|
|
else:
|
|
|
|
print("failed=" + str(failed))
|
2011-01-29 14:42:53 +00:00
|
|
|
elif c[0:7] == 'TestEnd':
|
2017-05-16 07:16:18 +00:00
|
|
|
marked.close()
|
2017-05-12 09:22:05 +00:00
|
|
|
#lyx_other_window_name = None
|
2017-05-12 19:28:57 +00:00
|
|
|
if lyx_dead(lyx_pid):
|
2017-04-24 15:42:24 +00:00
|
|
|
print("LyX instance not found because of crash or assert !\n")
|
2013-05-21 11:26:26 +00:00
|
|
|
failed = True
|
2011-04-22 22:23:16 +00:00
|
|
|
else:
|
2017-05-04 11:53:09 +00:00
|
|
|
print(" ------------ Forcing quit of lyx instance: " + str(lyx_pid) + " ------------")
|
2017-05-17 22:03:50 +00:00
|
|
|
# \[Escape]+ should work as RESET focus to main window
|
|
|
|
sendKeystringAx("\[Escape]\[Escape]\[Escape]\[Escape]", lyx_pid)
|
2017-05-09 19:07:35 +00:00
|
|
|
time.sleep(controlkey_delay)
|
|
|
|
# now we should be outside any dialog
|
|
|
|
# and so the function lyx-quit should work
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringLocal("\Cq", lyx_pid)
|
2017-04-24 15:42:24 +00:00
|
|
|
time.sleep(0.5)
|
2017-05-12 19:28:57 +00:00
|
|
|
dead_expected = True
|
|
|
|
is_sleeping = wait_until_lyx_sleeping(lyx_pid)
|
|
|
|
if is_sleeping:
|
|
|
|
print('wait_until_lyx_sleeping() indicated "sleeping"')
|
|
|
|
# For a short time lyx-status is 'sleeping', even if it is nearly dead.
|
|
|
|
# Without the wait below, the \[Tab]-char is sent to nirvana
|
|
|
|
# causing a 'beep'
|
|
|
|
time.sleep(0.5)
|
2017-04-24 15:42:24 +00:00
|
|
|
# probably waiting for Save/Discard/Abort, we select 'Discard'
|
2017-05-04 11:53:09 +00:00
|
|
|
sendKeystringRT("\[Tab]\[Return]", lyx_pid)
|
2017-04-24 15:42:24 +00:00
|
|
|
lcount = 0
|
|
|
|
else:
|
|
|
|
lcount = 1
|
2017-05-12 19:28:57 +00:00
|
|
|
while not lyx_dead(lyx_pid):
|
2017-04-24 15:42:24 +00:00
|
|
|
lcount = lcount + 1
|
|
|
|
if lcount > 20:
|
|
|
|
print("LyX still up, killing process and waiting for it to die...\n")
|
|
|
|
intr_system("kill -9 " + str(lyx_pid), True);
|
2011-04-22 22:23:16 +00:00
|
|
|
time.sleep(0.5)
|
2011-01-30 15:58:08 +00:00
|
|
|
cmd = c[8:].rstrip()
|
2017-05-09 19:07:35 +00:00
|
|
|
if cmd != "":
|
2017-05-07 12:40:08 +00:00
|
|
|
print("Executing " + cmd)
|
|
|
|
result = intr_system(cmd)
|
|
|
|
failed = failed or (result != 0)
|
|
|
|
print("result=" + str(result) + ", failed=" + str(failed))
|
|
|
|
else:
|
|
|
|
print("failed=" + str(failed))
|
2011-01-30 15:58:08 +00:00
|
|
|
elif c[0:4] == 'Lang':
|
|
|
|
lang = c[5:].rstrip()
|
2017-05-07 12:40:08 +00:00
|
|
|
print("Setting LANG=" + lang)
|
2011-01-30 15:58:08 +00:00
|
|
|
os.environ['LANG'] = lang
|
2013-07-23 01:10:48 +00:00
|
|
|
os.environ['LC_ALL'] = lang
|
2011-02-11 23:27:34 +00:00
|
|
|
# If it doesn't exist, create a link <locale_dir>/<country-code>/LC_MESSAGES/lyx<version-suffix>.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
|
2011-02-10 22:33:23 +00:00
|
|
|
idx = lang.rfind(".")
|
|
|
|
if idx != -1:
|
|
|
|
ccode = lang[0:idx]
|
|
|
|
else:
|
|
|
|
ccode = lang
|
2012-12-09 20:20:05 +00:00
|
|
|
|
2017-05-07 12:40:08 +00:00
|
|
|
print("Setting LANGUAGE=" + ccode)
|
2012-12-09 20:20:05 +00:00
|
|
|
os.environ['LANGUAGE'] = ccode
|
|
|
|
|
2011-02-10 22:33:23 +00:00
|
|
|
idx = lang.find("_")
|
|
|
|
if idx != -1:
|
|
|
|
short_code = lang[0:idx]
|
|
|
|
else:
|
|
|
|
short_code = ccode
|
|
|
|
lyx_dir = os.popen("dirname \"" + lyx_exe + "\"").read().rstrip()
|
2012-12-12 13:54:38 +00:00
|
|
|
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"):
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Executing: grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'")
|
2012-12-12 13:54:38 +00:00
|
|
|
lyx_name = os.popen("grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'").read().rstrip()
|
2012-12-11 17:59:05 +00:00
|
|
|
else:
|
2017-04-24 15:42:24 +00:00
|
|
|
print('Could not determine PACKAGE name needed for translations\n')
|
2012-12-12 13:54:38 +00:00
|
|
|
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")
|
2011-01-29 14:42:53 +00:00
|
|
|
else:
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Unrecognised Command '" + c + "'\n")
|
2011-01-30 15:58:08 +00:00
|
|
|
failed = True
|
|
|
|
|
2017-04-24 15:42:24 +00:00
|
|
|
print("Test case terminated: ")
|
2011-01-30 15:58:08 +00:00
|
|
|
if failed:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(1,"FAIL")
|
2011-01-30 15:58:08 +00:00
|
|
|
else:
|
2017-05-16 11:01:43 +00:00
|
|
|
die(0, "Ok")
|