2 # -*- coding: utf-8 -*-
4 # generate_commits.py - Generate Git commits based on Transifex updates
5 # Thomas Perl <thp@gpodder.org>; 2012-08-16
15 process
= subprocess
.Popen(['git', 'status', '--porcelain'] +
16 glob
.glob('../../mygpo/locale/*/LC_MESSAGES/django.po'), stdout
=subprocess
.PIPE
)
17 stdout
, stderr
= process
.communicate()
18 for line
in stdout
.splitlines():
19 status
, filename
= line
.strip().split()
21 filenames
.append(filename
)
23 for filename
in filenames
:
24 in_translators
= False
28 filename
= os
.path
.join('..', '..', filename
)
29 for line
in open(filename
).read().splitlines():
30 if line
.startswith('# Translators:'):
33 match
= re
.match(r
'# ([^<]* <[^>]*>)', line
)
35 translators
.append(match
.group(1))
37 in_translators
= False
39 match
= re
.search(r
'Last-Translator: ([^<]* <[^>]*>)', line
)
41 translators
.append(match
.group(1))
43 match
= re
.match(r
'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line
)
45 match
= re
.match(r
'"Language-Team: ([^\(]+).*\\n"', line
, re
.DOTALL
)
47 language
= match
.group(1).strip()
49 if translators
and language
is not None:
50 if len(translators
) != 1:
51 print '# Warning: %d other translators' % (len(translators
) - 1,)
52 print 'git commit --author="%s" --message="Updated %s translation" %s' % (translators
[0], language
, filename
)
54 print '# FIXME (could not parse):', '!'*10, filename
, '!'*10