3 # This file is part of LilyPond, the GNU music typesetter.
5 # LilyPond is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # LilyPond is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
32 def dir_lang (file, lang, lang_dir_index):
33 path_components = file.split ('/')
34 path_components[lang_dir_index] = lang
35 return os.path.join (*path_components)
37 # ugh, this is complicated; where has the good old 'git rev-parse' gone?
38 vc_revision_parse = 'git log -1 --pretty=format:%%H %s'
40 def do_file (file_name, lang_codes):
42 sys.stderr.write ('%s...\n' % file_name)
43 split_file_name = file_name.split ('/')
44 d1, d2 = split_file_name[0:2]
48 elif d2 in lang_codes:
54 raise Exception ('cannot determine language for ' + file_name)
56 if os.path.splitext (file_name)[1] == '.texidoc':
57 original = file_name.replace (os.path.join (check_lang, 'texidocs'), 'snippets', 1)
58 original = original.replace ('.texidoc', '.ly', 1)
60 original = dir_lang (file_name, '', lang_dir_index)
61 translated_contents = open (file_name).read ()
63 ## experimental feature
64 if not touch_committishes in (current_revision, 'HEAD'):
65 (changes_in_original, error) = \
66 buildlib.check_translated_doc (original,
69 upper_revision=touch_committishes)
70 if not error and not changes_in_original in ('', '\n'):
71 translated_contents = \
72 buildlib.revision_re.sub ('GIT committish: ' + current_revision,
73 translated_contents, 1)
74 f = open (file_name, 'w').write (translated_contents)
76 (diff_string, error) \
77 = buildlib.check_translated_doc (original,
80 color=use_colors and not update_mode)
83 sys.stderr.write ('warning: %s: %s' % (file_name, error))
86 if error or len (diff_string) >= os.path.getsize (original):
87 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
89 diff_file = original + '.diff'
90 f = open (diff_file, 'w')
93 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
96 sys.stdout.write (diff_string)
99 sys.stdout.write (r'''
101 check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE...
105 global lang, verbose, update_mode, touch_committishes, use_colors
107 p = optparse.OptionParser (usage=\
108 "check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE...",
110 p.add_option ("--language",
115 help="assume document language ISO 639 code LL by default")
116 p.add_option ("--no-color",
117 action='store_false',
120 help="do not print ANSI-colored output")
121 p.add_option ("--verbose",
125 help="print details, including executed shell commands")
129 dest="touch_committishes",
131 help='[EXPERIMENTAL] update committishes of all files that were up to \
132 date at commit COMMIT')
133 p.add_option ('-u', "--update",
137 help='call $EDITOR to update the translation')
139 (options, files) = p.parse_args ()
140 verbose = options.verbose
141 lang = options.language
142 use_colors = options.color
143 update_mode = options.update_mode
144 touch_committishes = options.touch_committishes
149 global update_mode, text_editor, touch_committishes, current_revision
151 files = do_options ()
152 if 'EDITOR' in os.environ:
153 text_editor = os.environ['EDITOR']
156 buildlib.verbose = verbose
157 (parsed_revision, error) = buildlib.read_pipe (vc_revision_parse % touch_committishes)
159 sys.stderr.write ('warning: %s' % error)
161 touch_committishes = parsed_revision.strip ()
162 current_revision = buildlib.read_pipe (vc_revision_parse % 'HEAD')[0]
165 do_file (i, langdefs.LANGDICT.keys ())
167 if __name__ == '__main__':