]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/check_translation.py
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[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 = 'site'
12 C = lang
13
14 def dir_lang (file, lang):
15     path_components = [lang] + file.split ('/')[1:]
16     return os.path.join (*path_components)
17
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'
21
22 def check_file (original, translated):
23     s = open (translated).read ()
24     m = REVISION_RE.match (s)
25     if not m:
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')
30         sys.exit (1)
31     revision = m.group (1)
32
33     c = CVS_DIFF % vars ()
34     if verbose:
35         sys.stderr.write ('running: ' + c)
36     os.system (c)
37
38 def do_file (file_name, langdefs):
39     if verbose:
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
44     else:
45         check_lang = lang
46     if check_lang == C:
47         raise 'cannot determine language for: ' + file_name
48     
49     original = dir_lang (file_name, '')
50     translated = dir_lang (file_name, check_lang)
51     check_file (original, translated)
52
53 def usage ():
54     sys.stdout.write (r'''
55 Usage:
56 check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
57
58 This script is licensed under the GNU GPL.
59 ''')
60
61 def do_options ():
62     global lang, verbose
63
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",
67                   action='store',
68                   default='site',
69                   dest="language")
70     p.add_option ("--verbose",
71                   action='store_true',
72                   default=False,
73                   dest="verbose",
74                   help="the GIT directory to merge.")
75     
76     (options, files) = p.parse_args ()
77     verbose = options.verbose
78     lang = options.language
79     
80     return (files[0], files[1:])
81
82 def main ():
83     import_path, files = do_options ()
84     
85     sys.path.append (import_path)
86     import langdefs
87
88     for i in files:
89         do_file (i, langdefs)
90
91 if __name__ == '__main__':
92     main ()