14 def dir_lang (file, lang):
15 path_components = [lang] + file.split ('/')[1:]
16 return os.path.join (*path_components)
18 ## Translation of GIT Commit: <hash>
19 REVISION_RE = re.compile ('.*GIT [Cc]ommittish: ([a-f0-9]+)', re.DOTALL)
20 CVS_DIFF = 'git diff %(revision)s HEAD -- %(original)s | cat'
22 def check_file (original, translated):
23 s = open (translated).read ()
24 m = REVISION_RE.match (s)
26 sys.stderr.write ('error: ' + translated + \
27 ": no 'GIT committish: <hash>' found.\nPlease check " + \
28 'the whole file against the original in English, then ' + \
29 'fill in HEAD committish in the header.\n')
31 revision = m.group (1)
33 c = CVS_DIFF % vars ()
35 sys.stderr.write ('running: ' + c)
38 def do_file (file_name, langdefs):
40 sys.stderr.write ('%s...\n' % file_name)
41 file_lang = file_name.split ('/')[0]
42 if file_lang in langdefs.LANGDICT.keys():
43 check_lang = file_lang
47 raise 'cannot determine language for: ' + file_name
49 original = dir_lang (file_name, '')
50 translated = dir_lang (file_name, check_lang)
51 check_file (original, translated)
54 sys.stdout.write (r'''
56 check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
58 This script is licensed under the GNU GPL.
64 p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
65 description="This script is licensed under the GNU GPL.")
66 p.add_option ("--language",
70 p.add_option ("--verbose",
74 help="the GIT directory to merge.")
76 (options, files) = p.parse_args ()
77 verbose = options.verbose
78 lang = options.language
80 return (files[0], files[1:])
83 import_path, files = do_options ()
85 sys.path.append (import_path)
91 if __name__ == '__main__':