14 def dir_lang (file, lang, lang_dir_index):
15 path_components = file.split ('/')
16 path_components[lang_dir_index] = lang
17 return os.path.join (*path_components)
19 ## Translation of GIT Commit: <hash>
20 REVISION_RE = re.compile ('GIT [Cc]ommittish: ([a-f0-9]+)')
21 CVS_DIFF = 'git diff %(revision)s HEAD -- %(original)s | cat'
23 def check_file (original, translated):
24 s = open (translated).read ()
25 m = REVISION_RE.search (s)
27 sys.stderr.write ('error: ' + translated + \
28 ": no 'GIT committish: <hash>' found.\nPlease check " + \
29 'the whole file against the original in English, then ' + \
30 'fill in HEAD committish in the header.\n')
32 revision = m.group (1)
34 c = CVS_DIFF % vars ()
36 sys.stderr.write ('running: ' + c)
39 def do_file (file_name, lang_codes):
41 sys.stderr.write ('%s...\n' % file_name)
42 split_file_name = file_name.split ('/')
43 d1, d2 = split_file_name[0:2]
47 elif d2 in lang_codes:
53 raise Exception ('cannot determine language for ' + file_name)
55 original = dir_lang (file_name, '', lang_dir_index)
56 translated = file_name
57 check_file (original, translated)
60 sys.stdout.write (r'''
62 check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
64 This script is licensed under the GNU GPL.
70 p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
71 description="This script is licensed under the GNU GPL.")
72 p.add_option ("--language",
76 p.add_option ("--verbose",
80 help="the GIT directory to merge.")
82 (options, files) = p.parse_args ()
83 verbose = options.verbose
84 lang = options.language
86 return (files[0], files[1:])
89 import_path, files = do_options ()
91 sys.path.append (import_path)
95 do_file (i, langdefs.LANGDICT.keys())
97 if __name__ == '__main__':