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 # ugh, this is complicated; where has the good old 'git rev-parse' gone?
23 vc_revision_parse = 'git log -1 --pretty=format:%%H %s'
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 (check_lang, 'texidocs'), 'snippets', 1)
43 original = original.replace ('.texidoc', '.ly', 1)
45 original = dir_lang (file_name, '', lang_dir_index)
46 translated_contents = open (file_name).read ()
48 ## experimental feature
49 if not touch_committishes in (current_revision, 'HEAD'):
50 (changes_in_original, error) = \
51 buildlib.check_translated_doc (original,
54 upper_revision=touch_committishes)
55 if not error and not changes_in_original in ('', '\n'):
56 translated_contents = \
57 buildlib.revision_re.sub ('GIT committish: ' + current_revision,
58 translated_contents, 1)
59 f = open (file_name, 'w').write (translated_contents)
61 (diff_string, error) \
62 = buildlib.check_translated_doc (original,
65 color=use_colors and not update_mode)
68 sys.stderr.write ('warning: %s: %s' % (file_name, error))
71 if error or len (diff_string) >= os.path.getsize (original):
72 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + original)
74 diff_file = original + '.diff'
75 f = open (diff_file, 'w')
78 buildlib.read_pipe (text_editor + ' ' + file_name + ' ' + diff_file)
81 sys.stdout.write (diff_string)
84 sys.stdout.write (r'''
86 check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE...
88 This script is licensed under the GNU GPL.
92 global lang, verbose, update_mode, touch_committishes, use_colors
94 p = optparse.OptionParser (usage=\
95 "check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE...",
96 description="This script is licensed under the GNU GPL.")
97 p.add_option ("--language",
102 help="assume document language ISO 639 code LL by default")
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",
118 help='[EXPERIMENTAL] update committishes of all files that were up to \
119 date at commit COMMIT')
120 p.add_option ('-u', "--update",
124 help='call $EDITOR to update the translation')
126 (options, files) = p.parse_args ()
127 verbose = options.verbose
128 lang = options.language
129 use_colors = options.color
130 update_mode = options.update_mode
131 touch_committishes = options.touch_committishes
136 global update_mode, text_editor, touch_committishes, current_revision
138 files = do_options ()
139 if 'EDITOR' in os.environ:
140 text_editor = os.environ['EDITOR']
143 buildlib.verbose = verbose
144 (parsed_revision, error) = buildlib.read_pipe (vc_revision_parse % touch_committishes)
146 sys.stderr.write ('warning: %s' % error)
148 touch_committishes = parsed_revision.strip ()
149 current_revision = buildlib.read_pipe (vc_revision_parse % 'HEAD')[0]
152 do_file (i, langdefs.LANGDICT.keys ())
154 if __name__ == '__main__':