fix paths in generate_commits.py
[mygpo.git] / tools / i18n / generate_commits.py
blob3268fad3dbabdc5c10f5dd3c33b2c6199386646d
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # generate_commits.py - Generate Git commits based on Transifex updates
5 # Thomas Perl <thp@gpodder.org>; 2012-08-16
8 import re
9 import glob
10 import subprocess
11 import os.path
13 filenames = []
15 pofiles = os.path.join(os.path.dirname(os.path.abspath(__file__)),
16 '..', '..', '..', 'mygpo', 'locale', '*', 'LC_MESSAGES', 'django.po')
18 process = subprocess.Popen(['git', 'status', '--porcelain'] +
19 glob.glob(pofiles), stdout=subprocess.PIPE)
20 stdout, stderr = process.communicate()
21 for line in stdout.splitlines():
22 status, filename = line.strip().split()
23 if status == 'M':
24 filenames.append(filename)
26 for filename in filenames:
27 in_translators = False
28 translators = []
29 language = None
31 filename = os.path.join('..', '..', filename)
32 for line in open(filename).read().splitlines():
33 if line.startswith('# Translators:'):
34 in_translators = True
35 elif in_translators:
36 match = re.match(r'# ([^<]* <[^>]*>)', line)
37 if match:
38 translators.append(match.group(1))
39 else:
40 in_translators = False
42 match = re.search(r'Last-Translator: ([^<]* <[^>]*>)', line)
43 if match:
44 translators.append(match.group(1))
46 match = re.match(r'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line)
47 if not match:
48 match = re.match(r'"Language-Team: ([^\(]+).*\\n"', line, re.DOTALL)
49 if match:
50 language = match.group(1).strip()
52 if translators and language is not None:
53 if len(translators) != 1:
54 print '# Warning: %d other translators' % (len(translators) - 1,)
55 print 'git commit --author="%s" --message="Updated %s translation" %s' % (translators[0], language, filename)
56 else:
57 print '# FIXME (could not parse):', '!'*10, filename, '!'*10