]> git.lyx.org Git - features.git/blob - development/autotests/keytest.py
keytests: New script to replace 'pcregrep' in more complex cases.
[features.git] / development / autotests / keytest.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # This script generates hundreds of random keypresses per second,
4 #  and sends them to the lyx window
5 # It requires xvkbd and wmctrl
6 # It generates a log of the KEYCODES it sends as development/keystest/out/KEYCODES
7 #
8 # Adapted by Tommaso Cucinotta from the original MonKey Test by
9 # John McCabe-Dansted.
10
11 from __future__ import print_function
12 import random
13 import os
14 import re
15 import sys
16 import time
17 #from subprocess import call
18 import subprocess
19
20 print('Beginning keytest.py')
21
22 FNULL = open('/dev/null', 'w')
23
24 key_delay = ''
25
26 # Ignore status == "dead" if this is set. Used at the last commands after "\Cq"
27 dead_expected = False
28
29 class CommandSource:
30
31     def __init__(self):
32         keycode = [
33             "\[Left]",
34             '\[Right]',
35             '\[Down]',
36             '\[Up]',
37             '\[BackSpace]',
38             '\[Delete]',
39             '\[Escape]',
40             ]
41         keycode[:0] = keycode
42         keycode[:0] = keycode
43
44         keycode[:0] = ['\\']
45
46         for k in range(97, 123):
47             keycode[:0] = chr(k)
48
49         for k in range(97, 123):
50             keycode[:0] = ["\A" + chr(k)]
51
52         for k in range(97, 123):
53             keycode[:0] = ["\A" + chr(k)]
54
55         for k in range(97, 123):
56             keycode[:0] = ["\C" + chr(k)]
57
58         self.keycode = keycode
59         self.count = 0
60         self.count_max = 1999
61
62     def getCommand(self):
63         self.count = self.count + 1
64         if self.count % 200 == 0:
65             return 'RaiseLyx'
66         elif self.count > self.count_max:
67             os._exit(0)
68         else:
69             keystr = ''
70             for k in range(1, 2):
71                 keystr = keystr + self.keycode[random.randint(1,
72                         len(self.keycode)) - 1]
73             return 'KK: ' + keystr
74
75
76 class CommandSourceFromFile(CommandSource):
77
78     def __init__(self, filename, p):
79
80         self.infile = open(filename, 'r')
81         self.lines = self.infile.readlines()
82         self.infile.close()
83         linesbak = self.lines
84         self.p = p
85         print(p, self.p, 'self.p')
86         self.i = 0
87         self.count = 0
88         self.loops = 0
89
90         # Now we start randomly dropping lines, which we hope are redundant
91         # p is the probability that any given line will be removed
92
93         if p > 0.001:
94             if random.uniform(0, 1) < 0.5:
95                 print('randomdrop_independant\n')
96                 self.randomdrop_independant()
97             else:
98                 print('randomdrop_slice\n')
99                 self.randomdrop_slice()
100         if screenshot_out is None:
101             count_atleast = 100
102         else:
103             count_atleast = 1
104         self.max_count = max(len(self.lines) + 20, count_atleast)
105         if len(self.lines) < 1:
106             self.lines = linesbak
107
108     def randomdrop_independant(self):
109         p = self.p
110
111         # The next couple of lines are to ensure that at least one line is dropped
112
113         drop = random.randint(0, len(self.lines) - 1)
114         del self.lines[drop]
115         #p = p - 1 / len(self.lines)
116         origlines = self.lines
117         self.lines = []
118         for l in origlines:
119             if random.uniform(0, 1) < self.p:
120                 print('Randomly dropping line ' + l + '\n')
121             else:
122                 self.lines.append(l)
123         print('LINES\n')
124         print(self.lines)
125         sys.stdout.flush()
126
127     def randomdrop_slice(self):
128         lines = self.lines
129         if random.uniform(0, 1) < 0.4:
130             lines.append(lines[0])
131             del lines[0]
132         num_lines = len(lines)
133         max_drop = max(5, num_lines / 5)
134         num_drop = random.randint(1, 5)
135         drop_mid = random.randint(0, num_lines)
136         drop_start = max(drop_mid - num_drop / 2, 0)
137         drop_end = min(drop_start + num_drop, num_lines)
138         print(drop_start, drop_mid, drop_end)
139         print(lines)
140         del lines[drop_start:drop_end]
141         print(lines)
142         self.lines = lines
143
144     def getCommand(self):
145         if self.count >= self.max_count:
146             os._exit(0)
147         if self.i >= len(self.lines):
148             self.loops = self.loops + 1
149             if self.loops >= int(max_loops):
150                 return None
151             self.i = 0
152             return 'Loop'
153         line = self.lines[self.i].rstrip('\n')
154         self.count = self.count + 1
155         self.i = self.i + 1
156         return line
157
158 def get_proc_pid(proc_name):
159     pid=os.popen("pidof " + proc_name).read().rstrip()
160     return pid
161
162 wlistreg = re.compile(r'^(0x[0-9a-f]{5,9})\s+[^\s]+\s+([0-9]+)\s.*$')
163 def get_proc_win_id(pid, ignoreid):
164     nlist = os.popen("wmctrl -l -p").read()
165     wlist = nlist.split("\n")
166     for item in wlist:
167         m = wlistreg.match(item)
168         if m:
169             win_id = m.group(1)
170             win_pid = m.group(2)
171             if win_pid == pid:
172                 if win_id != ignoreid:
173                     return win_id
174     return None
175
176 def lyx_exists():
177     if lyx_pid is None:
178         return False
179     fname = '/proc/' + lyx_pid + '/status'
180     return os.path.exists(fname)
181
182
183 # Interruptible os.system()
184 def intr_system(cmd, ignore_err = False):
185     print("Executing " + cmd)
186     ret = os.system(cmd)
187     if os.WIFSIGNALED(ret):
188         raise KeyboardInterrupt
189     if ret != 0 and not ignore_err:
190         raise BaseException("command failed:" + cmd)
191     return ret
192
193 statreg = re.compile(r'^State:.*\(([a-z]+)\)')
194
195 resstatus = []
196 def printresstatus():
197     for line in resstatus:
198         line = line.rstrip()
199         print("    " + line.rstrip())
200     print('End of /proc-lines')
201
202 def lyx_status_retry(pid):
203     resstatus = []
204     if lyx_pid is None:
205         print('Pid is None')
206         return "dead"
207     fname = '/proc/' + pid + '/status'
208     status = "dead"
209     try:
210         f = open(fname)
211         found = False
212         for line in f:
213             resstatus.extend([line])
214             m = statreg.match(line)
215             if m:
216                 status = m.group(1)
217                 found = True
218         f.close()
219         if not found:
220             return "retry"
221         return status
222     except IOError as e:
223         print("I/O error({0}): {1}".format(e.errno, e.strerror))
224         return "dead"
225     except:
226         print("Unexpected error:", sys.exc_info()[0])
227         return "dead"
228     print('This should not happen')
229     return status
230
231 def lyx_status(pid):
232     count = 0
233     while 1:
234         status = lyx_status_retry(pid)
235         if status != "retry":
236             break
237         if count == 0:
238             print('Retrying check for status')
239         count += 1
240         time.sleep(0.01)
241     if count > 1:
242         print('Retried to read status ' + str(count) + ' times')
243     #print('lys_status() returning ' + status)
244     return status
245
246 # Return true if LyX (identified via lyx_pid) is sleeping
247 def lyx_sleeping(LYX_PID):
248     return lyx_status(LYX_PID) == "sleeping"
249
250 # Return true if LyX (identified via lyx_pid) is zombie
251 def lyx_zombie(LYX_PID):
252     return lyx_status(LYX_PID) == "zombie"
253
254 def lyx_dead(LYX_PID):
255     status = lyx_status(LYX_PID)
256     return (status == "dead") or (status == "zombie")
257
258 def wait_until_lyx_sleeping(LYX_PID):
259     before_secs = time.time()
260     while True:
261         status = lyx_status(LYX_PID)
262         if status == "sleeping":
263             return True
264         if (status == "dead") or (status == "zombie"):
265             printresstatus()
266             sys.stdout.flush()
267             if dead_expected:
268                 print('Lyx died while waiting for status == sleeping')
269                 return False
270             else:
271                 print('Lyx is dead, exiting')
272                 os._exit(1)
273         if time.time() - before_secs > 180:
274             print('Killing due to freeze (KILL_FREEZE)')
275
276             # Do profiling, but sysprof has no command line interface?
277             # intr_system("killall -KILL lyx")
278             printresstatus()
279             sys.stdout.flush()
280             os._exit(1)
281         time.sleep(0.02)
282     # Should be never reached
283     print('Wait for sleeping ends unexpectedly')
284     return False
285
286 def sendKeystringLocal(keystr, LYX_PID):
287     is_sleeping = wait_until_lyx_sleeping(LYX_PID)
288     if not is_sleeping:
289         print("Not sending \"" + keystr + "\"")
290         return
291     if not screenshot_out is None:
292         print('Making Screenshot: ' + screenshot_out + ' OF ' + infilename)
293         time.sleep(0.2)
294         intr_system('import -window root '+screenshot_out+str(x.count)+".png")
295         time.sleep(0.1)
296     actual_delay = key_delay
297     if actual_delay == '':
298         actual_delay = def_delay
299     xvpar = [xvkbd_exe]
300     if qt_frontend == 'QT5':
301         xvpar.extend(["-jump-pointer", "-no-back-pointer"])
302     else:
303         xvpar.extend(["-xsendevent"])
304     if lyx_other_window_name is None:
305         xvpar.extend(["-window", lyx_window_name])
306     else:
307         xvpar.extend(["-window", lyx_other_window_name])
308     xvpar.extend(["-delay", actual_delay, "-text", keystr])
309     print("Sending \"" + keystr + "\"")
310     subprocess.call(xvpar, stdout = FNULL, stderr = FNULL)
311     sys.stdout.flush()
312
313 Axreg = re.compile(r'^(.*)\\Ax([^\\]*)(.*)$')
314 returnreg = re.compile(r'(\\\[[A-Z][a-z]+\])(.*)$')
315
316 # recursive wrapper around sendKeystringLocal()
317 # handling \Ax-entries
318 def sendKeystringAx(line, LYX_PID):
319     global key_delay
320     saved_delay = key_delay
321     m = Axreg.match(line)
322     if m:
323         prefix = m.group(1)
324         content = m.group(2)
325         rest = m.group(3);
326         if prefix != "":
327             # since (.*) is greedy, check prefix for '\Ax' again
328             sendKeystringAx(prefix, LYX_PID)
329         sendKeystringLocal('\Ax', LYX_PID)
330         time.sleep(0.1)
331         m2 = returnreg.match(rest)
332         if m2:
333             line = m2.group(2)
334             ctrlk = m2.group(1)
335             key_delay = "1"
336             sendKeystringLocal(content + ctrlk, LYX_PID)
337             key_delay = saved_delay
338             time.sleep(controlkey_delay)
339             if line != "":
340                 sendKeystringLocal(line, LYX_PID)
341         else:
342             if content != "":
343                 sendKeystringLocal(content, LYX_PID)
344             if rest != "":
345                 sendKeystringLocal(rest, LYX_PID)
346     else:
347         if line != "":
348             sendKeystringLocal(line, LYX_PID)
349
350 specialkeyreg = re.compile(r'(.+)(\\[AC]([a-zA-Z]|\\\[[A-Z][a-z]+\]).*)$')
351 # Split line at start of each meta or controll char
352
353 def sendKeystringAC(line, LYX_PID):
354     m = specialkeyreg.match(line)
355     if m:
356         first = m.group(1)
357         second = m.group(2)
358         sendKeystringAC(first, LYX_PID)
359         sendKeystringAC(second, LYX_PID)
360     else:
361         sendKeystringAx(line, LYX_PID)
362
363 controlkeyreg = re.compile(r'^(.*\\\[[A-Z][a-z]+\])(.*\\\[[A-Z][a-z]+\])(.*)$')
364 # Make sure, only one of \[Return], \[Tab], \[Down], \[Home] etc are in one sent line
365 # e.g. split the input line on each keysym
366 def sendKeystringRT(line, LYX_PID):
367     m = controlkeyreg.match(line)
368     if m:
369         first = m.group(1)
370         second = m.group(2)
371         third = m.group(3)
372         sendKeystringRT(first, LYX_PID)
373         time.sleep(controlkey_delay)
374         sendKeystringRT(second, LYX_PID)
375         time.sleep(controlkey_delay)
376         if third != "":
377             sendKeystringRT(third, LYX_PID)
378     else:
379         sendKeystringAC(line, LYX_PID)
380
381 def system_retry(num_retry, cmd):
382     i = 0
383     rtn = intr_system(cmd)
384     while ( ( i < num_retry ) and ( rtn != 0) ):
385         i = i + 1
386         rtn = intr_system(cmd)
387         time.sleep(1)
388     if ( rtn != 0 ):
389         print("Command Failed: "+cmd)
390         print(" EXITING!\n")
391         os._exit(1)
392
393 def RaiseWindow():
394     #intr_system("echo x-session-manager PID: $X_PID.")
395     #intr_system("echo x-session-manager open files: `lsof -p $X_PID | grep ICE-unix | wc -l`")
396     ####intr_system("wmctrl -l | ( grep '"+lyx_window_name+"' || ( killall lyx ; sleep 1 ; killall -9 lyx ))")
397     print("lyx_window_name = " + lyx_window_name + "\n")
398     intr_system("wmctrl -R '"+lyx_window_name+"' ;sleep 0.1")
399     system_retry(30, "wmctrl -i -a '"+lyx_window_name+"'")
400
401
402 lyx_pid = os.environ.get('LYX_PID')
403 print('lyx_pid: ' + str(lyx_pid) + '\n')
404 infilename = os.environ.get('KEYTEST_INFILE')
405 outfilename = os.environ.get('KEYTEST_OUTFILE')
406 max_drop = os.environ.get('MAX_DROP')
407 lyx_window_name = os.environ.get('LYX_WINDOW_NAME')
408 lyx_other_window_name = None
409 screenshot_out = os.environ.get('SCREENSHOT_OUT')
410 lyx_userdir = os.environ.get('LYX_USERDIR')
411
412 max_loops = os.environ.get('MAX_LOOPS')
413 if max_loops is None:
414     max_loops = 3
415
416 extra_path = os.environ.get('EXTRA_PATH')
417 if not extra_path is None:
418   os.environ['PATH'] = extra_path + os.pathsep + os.environ['PATH']
419   print("Added " + extra_path + " to path")
420   print(os.environ['PATH'])
421
422 PACKAGE = os.environ.get('PACKAGE')
423 if not PACKAGE is None:
424   print("PACKAGE = " + PACKAGE + "\n")
425
426 PO_BUILD_DIR = os.environ.get('PO_BUILD_DIR')
427 if not PO_BUILD_DIR is None:
428   print("PO_BUILD_DIR = " + PO_BUILD_DIR + "\n")
429
430 lyx = os.environ.get('LYX')
431 if lyx is None:
432     lyx = "lyx"
433
434 lyx_exe = os.environ.get('LYX_EXE')
435 if lyx_exe is None:
436     lyx_exe = lyx
437
438 xvkbd_exe = os.environ.get('XVKBD_EXE')
439 if xvkbd_exe is None:
440     xvkbd_exe = "xvkbd"
441
442 qt_frontend = os.environ.get('QT_FRONTEND')
443 if qt_frontend is None:
444     qt_frontend = 'QT4'
445 if qt_frontend == 'QT5':
446     controlkey_delay = 0.01
447 else:
448     controlkey_delay = 0.4
449
450 locale_dir = os.environ.get('LOCALE_DIR')
451 if locale_dir is None:
452     locale_dir = '.'
453
454 def_delay = os.environ.get('XVKBD_DELAY')
455 if def_delay is None:
456     if qt_frontend == 'QT5':
457         def_delay = '1'
458     else:
459         def_delay = '1'
460
461 file_new_command = os.environ.get('FILE_NEW_COMMAND')
462 if file_new_command is None:
463     file_new_command = "\Afn"
464
465 ResetCommand = os.environ.get('RESET_COMMAND')
466 if ResetCommand is None:
467     ResetCommand = "\[Escape]\[Escape]\[Escape]\[Escape]" + file_new_command
468     #ResetCommand="\[Escape]\[Escape]\[Escape]\[Escape]\Cw\Cw\Cw\Cw\Cw\Afn"
469
470 if lyx_window_name is None:
471     lyx_window_name = 'LyX'
472
473 print('outfilename: ' + outfilename + '\n')
474 print('max_drop: ' + max_drop + '\n')
475
476 if infilename is None:
477     print('infilename is None\n')
478     x = CommandSource()
479     print('Using x=CommandSource\n')
480 else:
481     print('infilename: ' + infilename + '\n')
482     probability_we_drop_a_command = random.uniform(0, float(max_drop))
483     print('probability_we_drop_a_command: ')
484     print('%s' % probability_we_drop_a_command)
485     print('\n')
486     x = CommandSourceFromFile(infilename, probability_we_drop_a_command)
487     print('Using x=CommandSourceFromFile\n')
488
489 outfile = open(outfilename, 'w')
490
491 if not lyx_pid is None:
492     RaiseWindow()
493     # Next command is language dependent
494     #sendKeystringRT("\Afn", lyx_pid)
495
496 write_commands = True
497 failed = False
498 lineempty = re.compile(r'^\s*$')
499
500 while not failed:
501     #intr_system('echo -n LOADAVG:; cat /proc/loadavg')
502     c = x.getCommand()
503     if c is None:
504         break
505
506     # Do not strip trailing spaces, only check for 'empty' lines
507     if lineempty.match(c):
508         continue
509     outfile.writelines(c + '\n')
510     outfile.flush()
511     if c[0] == '#':
512         print("Ignoring comment line: " + c)
513     elif c[0:9] == 'TestBegin':
514         print("\n")
515         lyx_pid=get_proc_pid(lyx)
516         if lyx_pid != "":
517             print("Found running instance(s) of LyX: " + lyx_pid + ": killing them all\n")
518             intr_system("killall " + lyx, True)
519             time.sleep(0.5)
520             intr_system("killall -KILL " + lyx, True)
521             time.sleep(0.2)
522         print("Starting LyX . . .")
523         if lyx_userdir is None:
524             intr_system(lyx_exe + c[9:] + "&")
525         else:
526             intr_system(lyx_exe + " -userdir " + lyx_userdir + " " + c[9:] + "&")
527         count = 10
528         old_lyx_pid = "-7"
529         old_lyx_window_name = None
530         print("Waiting for LyX to show up . . .")
531         while count > 0:
532             lyx_pid=get_proc_pid(lyx)
533             if lyx_pid != old_lyx_pid:
534                 print('lyx_pid=' + lyx_pid)
535                 old_lyx_pid = lyx_pid
536             if lyx_pid != "":
537                 lyx_window_name=get_proc_win_id(lyx_pid, "")
538                 if not lyx_window_name is None:
539                     if old_lyx_window_name != lyx_window_name:
540                         print('lyx_win=' + lyx_window_name, '\n')
541                         old_lyx_window_name = lyx_window_name
542                     break
543             else:
544                 count = count - 1
545             time.sleep(0.5)
546         if count <= 0:
547             print('Timeout: could not start ' + lyx_exe, '\n')
548             sys.stdout.flush()
549             failed = True
550         else:
551             print('lyx_pid: ' + lyx_pid)
552             print('lyx_win: ' + lyx_window_name)
553             dead_expected = False
554             sendKeystringLocal("\C\[Home]", lyx_pid)
555             time.sleep(controlkey_delay)
556     elif c[0:5] == 'Sleep':
557         print("Sleeping for " + c[6:] + " seconds")
558         time.sleep(float(c[6:]))
559     elif c[0:4] == 'Exec':
560         cmd = c[5:].rstrip()
561         intr_system(cmd)
562     elif c == 'Loop':
563         outfile.close()
564         outfile = open(outfilename + '+', 'w')
565         print('Now Looping')
566     elif c == 'RaiseLyx':
567         print('Raising Lyx')
568         RaiseWindow()
569     elif c[0:4] == 'KK: ':
570         if lyx_exists():
571             sendKeystringRT(c[4:], lyx_pid)
572         else:
573             ##intr_system('killall lyx; sleep 2 ; killall -9 lyx')
574             if lyx_pid is None:
575               print('No path /proc/xxxx/status, exiting')
576             else:
577               print('No path /proc/' + lyx_pid + '/status, exiting')
578             os._exit(1)
579     elif c[0:4] == 'KD: ':
580         key_delay = c[4:].rstrip('\n')
581         print('Setting DELAY to ' + key_delay)
582     elif c == 'Loop':
583         RaiseWindow()
584         sendKeystringRT(ResetCommand, lyx_pid)
585     elif c[0:6] == 'Assert':
586         cmd = c[7:].rstrip()
587         result = intr_system(cmd)
588         failed = failed or (result != 0)
589         print("result=" + str(result) + ", failed=" + str(failed))
590     elif c[0:15] == 'TestEndWithKill':
591         cmd = c[16:].rstrip()
592         if lyx_dead(lyx_pid):
593             print("LyX instance not found because of crash or assert !\n")
594             failed = True
595         else:
596             print("    ------------    Forcing kill of lyx instance: " + str(lyx_pid) + "    ------------")
597             # This line below is there only to allow lyx to update its log-file
598             sendKeystringLocal("\[Escape]", lyx_pid)
599             dead_expected = True
600             while not lyx_dead(lyx_pid):
601                 intr_system("kill -9 " + str(lyx_pid), True);
602                 time.sleep(0.5)
603             if cmd != "":
604                 print("Executing " + cmd)
605                 result = intr_system(cmd)
606                 failed = failed or (result != 0)
607                 print("result=" + str(result) + ", failed=" + str(failed))
608             else:
609                 print("failed=" + str(failed))
610     elif c[0:7] == 'TestEnd':
611         #lyx_other_window_name = None
612         if lyx_dead(lyx_pid):
613             print("LyX instance not found because of crash or assert !\n")
614             failed = True
615         else:
616             print("    ------------    Forcing quit of lyx instance: " + str(lyx_pid) + "    ------------")
617             # \Ax Enter command line is sometimes blocked
618             # \[Escape] works after this
619             sendKeystringAx("\Ax\[Escape]", lyx_pid)
620             time.sleep(controlkey_delay)
621             # now we should be outside any dialog
622             # and so the function lyx-quit should work
623             sendKeystringLocal("\Cq", lyx_pid)
624             time.sleep(0.5)
625             dead_expected = True
626             is_sleeping = wait_until_lyx_sleeping(lyx_pid)
627             if is_sleeping:
628                 print('wait_until_lyx_sleeping() indicated "sleeping"')
629                 # For a short time lyx-status is 'sleeping', even if it is nearly dead.
630                 # Without the wait below, the \[Tab]-char is sent to nirvana
631                 # causing a 'beep'
632                 time.sleep(0.5)
633                 # probably waiting for Save/Discard/Abort, we select 'Discard'
634                 sendKeystringRT("\[Tab]\[Return]", lyx_pid)
635                 lcount = 0
636             else:
637                 lcount = 1
638             while not lyx_dead(lyx_pid):
639                 lcount = lcount + 1
640                 if lcount > 20:
641                     print("LyX still up, killing process and waiting for it to die...\n")
642                     intr_system("kill -9 " + str(lyx_pid), True);
643                 time.sleep(0.5)
644         cmd = c[8:].rstrip()
645         if cmd != "":
646             print("Executing " + cmd)
647             result = intr_system(cmd)
648             failed = failed or (result != 0)
649             print("result=" + str(result) + ", failed=" + str(failed))
650         else:
651             print("failed=" + str(failed))
652     elif c[0:4] == 'Lang':
653         lang = c[5:].rstrip()
654         print("Setting LANG=" + lang)
655         os.environ['LANG'] = lang
656         os.environ['LC_ALL'] = lang
657 # If it doesn't exist, create a link <locale_dir>/<country-code>/LC_MESSAGES/lyx<version-suffix>.mo
658 # pointing to the corresponding .gmo file. Needed to let lyx find the right translation files.
659 # See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg165613.html
660         idx = lang.rfind(".")
661         if idx != -1:
662             ccode = lang[0:idx]
663         else:
664             ccode = lang
665
666         print("Setting LANGUAGE=" + ccode)
667         os.environ['LANGUAGE'] = ccode
668
669         idx = lang.find("_")
670         if idx != -1:
671             short_code = lang[0:idx]
672         else:
673             short_code = ccode
674         lyx_dir = os.popen("dirname \"" + lyx_exe + "\"").read().rstrip()
675         if PACKAGE is None:
676           # on cmake-build there is no Makefile in this directory
677           # so PACKAGE has to be provided
678           if os.path.exists(lyx_dir + "/Makefile"):
679             print("Executing: grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'")
680             lyx_name = os.popen("grep 'PACKAGE =' " + lyx_dir + "/Makefile | sed -e 's/PACKAGE = \(.*\)/\\1/'").read().rstrip()
681           else:
682             print('Could not determine PACKAGE name needed for translations\n')
683             failed = True
684         else:
685           lyx_name = PACKAGE
686         intr_system("mkdir -p " + locale_dir + "/" + ccode + "/LC_MESSAGES")
687         intr_system("rm -f " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo")
688         if PO_BUILD_DIR is None:
689             if lyx_dir[0:3] == "../":
690                 rel_dir = "../../" + lyx_dir
691             else:
692                 rel_dir = lyx_dir
693             intr_system("ln -s " + rel_dir + "/../po/" + short_code + ".gmo " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo")
694         else:
695             intr_system("ln -s " + PO_BUILD_DIR + "/" + short_code + ".gmo " + locale_dir + "/" + ccode + "/LC_MESSAGES/" + lyx_name + ".mo")
696     else:
697         print("Unrecognised Command '" + c + "'\n")
698         failed = True
699
700 print("Test case terminated: ")
701 if failed:
702     print("FAIL\n")
703     os._exit(1)
704 else:
705     print("Ok\n")
706     os._exit(0)