]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/check_translation.py
Merge branch 'master' of /home/lilycvs/git/lily/
[lilypond.git] / buildscripts / check_translation.py
1 #!@PYTHON@
2
3 import __main__
4 import optparse
5 import gettext
6 import os
7 import re
8 import sys
9
10 verbose = 0
11 lang = 'C'
12 C = lang
13
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)
18
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'
22
23 def check_file (original, translated):
24     s = open (translated).read ()
25     m = REVISION_RE.search (s)
26     if not m:
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')
31         sys.exit (1)
32     revision = m.group (1)
33
34     c = CVS_DIFF % vars ()
35     if verbose:
36         sys.stderr.write ('running: ' + c)
37     os.system (c)
38
39 def do_file (file_name, lang_codes):
40     if verbose:
41         sys.stderr.write ('%s...\n' % file_name)
42     split_file_name = file_name.split ('/')
43     d1, d2 = split_file_name[0:2]
44     if d1 in lang_codes:
45         check_lang = d1
46         lang_dir_index = 0
47     elif d2 in lang_codes:
48         check_lang = d2
49         lang_dir_index = 1
50     else:
51         check_lang = lang
52     if check_lang == C:
53         raise Exception ('cannot determine language for ' + file_name)
54     
55     original = dir_lang (file_name, '', lang_dir_index)
56     translated = file_name
57     check_file (original, translated)
58
59 def usage ():
60     sys.stdout.write (r'''
61 Usage:
62 check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
63
64 This script is licensed under the GNU GPL.
65 ''')
66
67 def do_options ():
68     global lang, verbose
69
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",
73                   action='store',
74                   default='site',
75                   dest="language")
76     p.add_option ("--verbose",
77                   action='store_true',
78                   default=False,
79                   dest="verbose",
80                   help="the GIT directory to merge.")
81     
82     (options, files) = p.parse_args ()
83     verbose = options.verbose
84     lang = options.language
85     
86     return (files[0], files[1:])
87
88 def main ():
89     import_path, files = do_options ()
90     
91     sys.path.append (import_path)
92     import langdefs
93
94     for i in files:
95         do_file (i, langdefs.LANGDICT.keys())
96
97 if __name__ == '__main__':
98     main ()