]> git.donarmstrong.com Git - lilypond.git/blob - python/auxiliar/buildlib.py
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / python / auxiliar / buildlib.py
1 #!@PYTHON@
2
3 import subprocess
4 import re
5 import sys
6
7 verbose = False
8
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)
21
22 revision_re = re.compile ('GIT [Cc]ommittish:\s+([a-f0-9]+)')
23 vc_diff_cmd = 'git diff --patience -M %(color_flag)s %(revision)s %(upper_revision)s -- %(original)s | cat'
24 no_committish_fatal_error = """error: %s: no 'GIT committish: <hash>' found.
25 Please check the whole file against the original in English, then
26 fill in HEAD committish in the header.
27 """
28
29 def check_translated_doc (original, translated_file, translated_contents,
30                           color=False, upper_revision='HEAD'):
31     m = revision_re.search (translated_contents)
32     if not m:
33         sys.stderr.write (no_committish_fatal_error % translated_file)
34         sys.exit (1)
35     revision = m.group (1)
36
37     if color:
38         color_flag = '--color --color-words'
39     else:
40         color_flag = '--no-color'
41     c = vc_diff_cmd % vars ()
42     if verbose:
43         sys.stderr.write ('running: ' + c)
44     return read_pipe (c)