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 'application.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 manuals_subdirectories_re = \
32 re.compile ('(application|essay|learning|notation)/')
34 def add_old_name (file_path):
35 for new_path in renames_map:
36 if file_path.endswith (new_path):
37 old_file_path = file_path.replace (new_path,
38 renames_map[new_path])
41 if file_path.endswith ('macros.itexi'):
42 old_file_path = file_path.replace ('macros.itexi',
44 elif file_path.endswith ('.itely'):
45 old_file_path = manuals_subdirectories_re.sub ('user/',
47 elif 'snippets/' in file_path:
48 old_file_path = file_path.replace ('snippets/',
52 return file_path + ' ' + old_file_path
54 revision_re = re.compile ('GIT [Cc]ommittish:\s+([a-f0-9]+)')
55 vc_diff_cmd = 'git diff -M %(color_flag)s %(revision)s \
56 %(upper_revision)s -- %(original_with_old_name)s | cat'
57 no_committish_fatal_error = """error: %s: no 'GIT committish: <hash>' found.
58 Please check the whole file against the original in English, then
59 fill in HEAD committish in the header.
62 def check_translated_doc (original, translated_file, translated_contents,
63 color=False, upper_revision='HEAD'):
64 m = revision_re.search (translated_contents)
66 sys.stderr.write (no_committish_fatal_error % translated_file)
68 revision = m.group (1)
71 color_flag = '--color --color-words'
73 color_flag = '--no-color'
74 original_with_old_name = add_old_name (original)
75 c = vc_diff_cmd % vars ()
77 sys.stderr.write ('running: ' + c)