Fix define-markup error messages
[lilypond.git] / python / auxiliar / buildlib.py
blobcd99586ff81038832afcae4b9c31468cde8766b5
1 #!@PYTHON@
3 import subprocess
4 import re
5 import sys
7 verbose = False
9 def read_pipe (command):
10 child = subprocess.Popen (command,
11 stdout = subprocess.PIPE,
12 stderr = subprocess.PIPE,
13 shell = True)
14 (output, error) = child.communicate ()
15 code = str (child.wait ())
16 if not child.stdout or child.stdout.close ():
17 print "pipe failed: %(command)s" % locals ()
18 if code != '0':
19 error = code + ' ' + error
20 return (output, error)
22 revision_re = re.compile ('GIT [Cc]ommittish:\s+([a-f0-9]+)')
23 vc_diff_cmd = 'git diff %(color_flag)s %(revision)s HEAD -- %(original)s | cat'
25 def check_translated_doc (original, translated_file, translated_contents, color=False):
26 m = revision_re.search (translated_contents)
27 if not m:
28 sys.stderr.write ('error: ' + translated_file + \
29 ": no 'GIT committish: <hash>' found.\nPlease check " + \
30 'the whole file against the original in English, then ' + \
31 'fill in HEAD committish in the header.\n')
32 sys.exit (1)
33 revision = m.group (1)
35 if color:
36 color_flag = '--color'
37 else:
38 color_flag = '--no-color'
39 c = vc_diff_cmd % vars ()
40 if verbose:
41 sys.stderr.write ('running: ' + c)
42 return read_pipe (c)