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 ### Renamed files map to ensure continuity of file history
23 ## Map of new_name: old_name
25 'usage.tely': 'user/lilypond-program.tely',
26 'notation.tely': 'user/lilypond.tely',
27 'learning.tely': 'user/lilypond-learning.tely',
28 'changes.tely': 'topdocs/NEWS.tely',
31 # FIXME: Hardcoded file names!?
32 manuals_subdirectories_re = \
33 re.compile ('(usage|automated-engraving|changes|essay|extending|web|learning|notation)/')
35 def add_old_name (file_path):
36 for new_path in renames_map:
37 if file_path.endswith (new_path):
38 old_file_path = file_path.replace (new_path,
39 renames_map[new_path])
42 if file_path.endswith ('macros.itexi'):
43 old_file_path = file_path.replace ('macros.itexi',
45 elif file_path.endswith ('.itely'):
46 old_file_path = manuals_subdirectories_re.sub ('user/',
48 elif 'snippets/' in file_path:
49 old_file_path = file_path.replace ('snippets/',
53 return file_path + ' ' + old_file_path
55 revision_re = re.compile ('GIT [Cc]ommittish:\s+([a-f0-9]+)')
56 vc_diff_cmd = 'git diff -M %(color_flag)s %(revision)s \
57 %(upper_revision)s -- %(original_with_old_name)s | cat'
58 no_committish_fatal_error = """error: %s: no 'GIT committish: <hash>' found.
59 Please check the whole file against the original in English, then
60 fill in HEAD committish in the header.
63 def check_translated_doc (original, translated_file, translated_contents,
64 color=False, upper_revision='HEAD'):
65 m = revision_re.search (translated_contents)
67 sys.stderr.write (no_committish_fatal_error % translated_file)
69 revision = m.group (1)
74 color_flag = '--color --color-words'
76 color_flag = '--no-color'
77 original_with_old_name = add_old_name (original)
78 c = vc_diff_cmd % vars ()
80 sys.stderr.write ('running: ' + c)