17 def dir_lang (file, lang, lang_dir_index):
18 path_components = file.split ('/')
19 path_components[lang_dir_index] = lang
20 return os.path.join (*path_components)
22 vc_last_revision = 'git log --pretty=format:%%H %(file_name)s | head -1'
23 vc_last_texidoc_revision = 'git log -Stexidoc%(preferred_language)s --pretty=format:%%H %(file_name)s | head -1'
25 def do_file (file_name, lang_codes):
27 sys.stderr.write ('%s...\n' % file_name)
28 split_file_name = file_name.split ('/')
29 d1, d2 = split_file_name[0:2]
33 elif d2 in lang_codes:
39 raise Exception ('cannot determine language for ' + file_name)
41 if os.path.splitext (file_name)[1] == '.texidoc':
42 original = file_name.replace (os.path.join ('texidocs' + os.path.sep, 'lsr' + os.path.sep, 1)
43 original = original.replace ('.texidoc', '.ly', 1)
45 # URG dirty .texidoc files manipulation in a dirty way
46 if touch_committishes and buildlib.check_translated_doc (original,
49 color=use_colors and not update_mode)[1]:
50 (estimated_revision, error) = buildlib.read_pipe (vc_last_texidoc_revision % vars ())
52 sys.stderr.write ('warning: %s: %s' % (file_name, error))
53 estimated_revision = estimated_revision.strip ()
54 translated_contents = re.sub (r'(?m)^%+\s*Translation of GIT committish:.*\n', '', translated_contents)
55 f = open (file_name, 'w')
56 f.write (full_translated_contents[:translated_contents_start])
57 f.write ('%% Translation of GIT committish: ' + estimated_revision + '\n')
58 f.write (translated_contents)
59 f.write (full_translated_contents[translated_contents_end:])
61 original = dir_lang (file_name, '', lang_dir_index)
62 translated_contents = open (file_name).read ()
64 (diff_string, error) \
65 = buildlib.check_translated_doc (original,
68 color=use_colors and not update_mode)
71 sys.stderr.write ('warning: %s: %s' % (file_name, error))
74 if error or len (diff_string) >= os.path.getsize (original):
75 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
77 diff_file = original + '.diff'
78 f = open (diff_file, 'w')
81 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
84 sys.stdout.write (diff_string)
87 sys.stdout.write (r'''
89 check-translation [--language=LANG] [--verbose] [--update] FILE...
91 This script is licensed under the GNU GPL.
95 global lang, verbose, update_mode, touch_committishes, use_colors
97 p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
98 description="This script is licensed under the GNU GPL.")
99 p.add_option ("--language",
103 p.add_option ("--no-color",
104 action='store_false',
107 help="do not print ANSI-colored output")
108 p.add_option ("--verbose",
112 help="print details, including executed shell commands")
116 dest="touch_committishes",
117 help=optparse.SUPPRESS_HELP)
118 p.add_option ('-u', "--update",
122 help='call $EDITOR to update the translation')
124 (options, files) = p.parse_args ()
125 verbose = options.verbose
126 lang = options.language
127 use_colors = options.color
128 update_mode = options.update_mode
129 touch_committishes = options.touch_committishes
134 global update_mode, text_editor
136 files = do_options ()
137 if 'EDITOR' in os.environ:
138 text_editor = os.environ['EDITOR']
142 buildlib.verbose = verbose
145 do_file (i, langdefs.LANGDICT.keys ())
147 if __name__ == '__main__':