class ControlFile:
def __init__(self):
- self.control = re.compile(r'^(C[ONPpRrC]):\s*(.*)$')
+ self.control = re.compile(r'^(C[ONPpRrC])([A-Za-z0-9]*):\s*(.*)$')
self.fileformat = re.compile(r'^((\>\>?)[,\s]\s*)?([^\s]+)\s*$')
- self.cntrname = None
- self.cntrfile = None
-
- def open(self, filename):
- if not self.cntrfile is None:
- self.cntrfile.close()
- self.cntrfile = None
- self.cntrname = None
+ self.cntrfile = dict()
+ # Map keytest marker to pattern-file-marker for searchPatterns.pl
+ self.convertSearchMark = { 'CN': 'Comment: ',
+ 'CP': 'Simple: ', 'Cp': 'ErrSimple: ',
+ 'CR': 'Regex: ', 'Cr': 'ErrRegex: '}
+
+ def __open(self, handle, filename):
+ if handle in self.cntrfile:
+ self.cntrfile[handle].close()
+ del self.cntrfile[handle]
m = self.fileformat.match(filename)
if m:
type = m.group(2)
append = False
else:
append = False
- self.cntrname = filename
if append:
- self.cntrfile = open(filename, 'a')
+ self.cntrfile[handle] = open(filename, 'a')
else:
- self.cntrfile = open(filename, 'w')
+ self.cntrfile[handle] = open(filename, 'w')
- def close(self):
- if not self.cntrfile is None:
- self.cntrfile.close()
- self.cntrfile = None
- self.cntrname = None
- # make the method below 'private'
- def __addline(self, pat):
- self.cntrfile.writelines(pat + "\n")
+ def closeall(self):
+ handles = self.cntrfile.keys()
+ for handle in handles:
+ self.__close(handle)
+
+ def __close(self, handle):
+ if handle in self.cntrfile:
+ name = self.cntrfile[handle].name
+ self.cntrfile[handle].close()
+ del self.cntrfile[handle]
+ print("Closed ctrl " + handle + " (" + name + ")")
- def getfname(self):
- return self.cntrname
+ # make the method below 'private'
+ def __addline(self, handle, pat):
+ self.cntrfile[handle].writelines(pat + "\n")
def dispatch(self, c):
m = self.control.match(c)
if not m:
return False
command = m.group(1)
- text = m.group(2)
+ handle = m.group(2)
+ if handle is None:
+ handle = ""
+ text = m.group(3)
if command == "CO":
- self.open(text);
+ self.__open(handle, text);
elif command == "CC":
- self.close()
+ self.__close(handle)
else:
- if not self.cntrfile is None:
- if command == "CN":
- self.__addline("Comment: " + text)
- elif command == "CP":
- self.__addline("Simple: " + text)
- elif command == "Cp":
- self.__addline("ErrSimple: " + text)
- elif command == "CR":
- self.__addline("Regex: " + text)
- elif command == "Cr":
- self.__addline("ErrRegex: " + text)
+ if handle in self.cntrfile:
+ if command in self.convertSearchMark:
+ self.__addline(handle, self.convertSearchMark[command] + text)
else:
die(1,"Error, Unrecognised Command '" + command + "'")
+ elif handle != "":
+ die(1, "Ctrl-file " + handle + " not in use")
return True
def __init__(self):
self.shortcut_entry = re.compile(r'^\s*"([^"]+)"\s*\"([^"]+)\"')
self.bindings = {}
- self.bind = re.compile(r'^\s*\\bind\s+"([^"]+)"')
+ self.unbindings = {}
+ self.bind = re.compile(r'^\s*\\(un)?bind\s+"([^"]+)"')
if lyx_userdir_ver is None:
self.dir = lyx_userdir
else:
else:
die(1, "cad shortcut spec(" + c + ")")
+ def __UnuseShortcut(self, c):
+ m = self.shortcut_entry.match(c)
+ if m:
+ sh = m.group(1)
+ fkt = m.group(2)
+ self.unbindings[sh] = fkt
+ else:
+ die(1, "cad shortcut spec(" + c + ")")
+
def __PrepareShortcuts(self):
if not self.dir is None:
tmp = tempfile.NamedTemporaryFile(suffix='.bind', delete=False)
m = self.bind.match(line)
if m:
bindfound = True
- val = m.group(1)
+ val = m.group(2)
if val in self.bindings:
if self.bindings[val] != "":
tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
self.bindings[val] = ""
+ elif val in self.unbindings:
+ if self.unbindings[val] != "":
+ tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+ self.unbindings[val] = ""
else:
tmp.write(line + '\n')
elif not bindfound:
)
for val in self.bindings:
if not self.bindings[val] is None:
- if self.bindings[val] != "":
+ if self.bindings[val] != "":
tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
self.bindings[val] = ""
+ for val in self.unbindings:
+ if not self.unbindings[val] is None:
+ if self.unbindings[val] != "":
+ tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+ self.unbindings[val] = ""
tmp.close()
shutil.move(tmp.name, self.dir + '/bind/user.bind')
else:
def dispatch(self, c):
if c[0:12] == 'UseShortcut ':
self.__UseShortcut(c[12:])
+ elif c[0:14] == 'UnuseShortcut ':
+ self.__UnuseShortcut(c[14:])
elif c == 'PrepareShortcuts':
print('Preparing usefull sortcuts for tests')
self.__PrepareShortcuts()
lyx_other_window_name = None
screenshot_out = os.environ.get('SCREENSHOT_OUT')
lyx_userdir = os.environ.get('LYX_USERDIR')
-lyx_userdir_ver = os.environ.get('LYX_USERDIR_23x')
+lyx_userdir_ver = os.environ.get('LYX_USERDIR_24x')
+if lyx_userdir is None:
+ lyx_userdir = lyx_userdir_ver
max_loops = os.environ.get('MAX_LOOPS')
if max_loops is None:
if qt_frontend is None:
qt_frontend = 'QT4'
if qt_frontend == 'QT5':
- controlkey_delay = 0.01
+ # Some tests sometimes failed with value 0.01 on Qt5.8
+ controlkey_delay = 0.4
else:
controlkey_delay = 0.4
failed = failed or (result != 0)
print("result=" + str(result) + ", failed=" + str(failed))
elif c[0:15] == 'TestEndWithKill':
- marked.close()
+ marked.closeall()
cmd = c[16:].rstrip()
if lyx_dead(lyx_pid):
print("LyX instance not found because of crash or assert !\n")
#lyx_other_window_name = None
if lyx_dead(lyx_pid):
print("LyX instance not found because of crash or assert !\n")
- marked.close()
+ marked.closeall()
failed = True
else:
print(" ------------ Forcing quit of lyx instance: " + str(lyx_pid) + " ------------")
# and so the function lyx-quit should work
sendKeystring("\Cq", lyx_pid)
marked.dispatch('CP: action=lyx-quit')
- marked.close()
+ marked.dispatch('CC:')
time.sleep(0.5)
dead_expected = True
is_sleeping = wait_until_lyx_sleeping(lyx_pid)
print('Could not determine PACKAGE name needed for translations\n')
failed = True
else:
- lyx_name = PACKAGE
+ 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: