]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/check_translation.py
Merge branch 'master' of ssh+git://git.sv.gnu.org/srv/git/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         raise translated + ': no GIT committish: <hash> found'
27     revision = m.group (1)
28
29     c = CVS_DIFF % vars ()
30     if verbose:
31         sys.stderr.write ('running: ' + c)
32     os.system (c)
33
34 def do_file (file_name, langdefs):
35     if verbose:
36         sys.stderr.write ('%s...\n' % file_name)
37     file_lang = file_name.split ('/')[0]
38     if file_lang in langdefs.LANGDICT.keys():
39         check_lang = file_lang
40     else:
41         check_lang = lang
42     if check_lang == C:
43         raise 'cannot determine language for: ' + file_name
44     
45     original = dir_lang (file_name, '')
46     translated = dir_lang (file_name, check_lang)
47     check_file (original, translated)
48
49 def usage ():
50     sys.stdout.write (r'''
51 Usage:
52 check-translation [--language=LANG] [--verbose] BUILDSCRIPT-DIR FILE...
53
54 This script is licensed under the GNU GPL.
55 ''')
56
57 def do_options ():
58     global lang, verbose
59
60     p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...",
61                                description="This script is licensed under the GNU GPL.")
62     p.add_option ("--language",
63                   action='store',
64                   default='site',
65                   dest="language")
66     p.add_option ("--verbose",
67                   action='store_true',
68                   default=False,
69                   dest="verbose",
70                   help="the GIT directory to merge.")
71     
72     (options, files) = p.parse_args ()
73     verbose = options.verbose
74     lang = options.language
75     
76     return (files[0], files[1:])
77
78 def main ():
79     import_path, files = do_options ()
80     
81     sys.path.append (import_path)
82     import langdefs
83
84     for i in files:
85         do_file (i, langdefs)
86
87 if __name__ == '__main__':
88     main ()