9 def read_pipe (command):
10 child = subprocess.Popen (command,
11 stdout = subprocess.PIPE,
12 stderr = subprocess.PIPE,
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 ()
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 --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.
29 def check_translated_doc (original, translated_file, translated_contents,
30 color=False, upper_revision='HEAD'):
31 m = revision_re.search (translated_contents)
33 sys.stderr.write (no_committish_fatal_error % translated_file)
35 revision = m.group (1)
38 color_flag = '--color --color-words'
40 color_flag = '--no-color'
41 c = vc_diff_cmd % vars ()
43 sys.stderr.write ('running: ' + c)