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 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()
24 filenames
.append(filename
)
26 for filename
in filenames
:
27 in_translators
= False
31 filename
= os
.path
.join('..', filename
)
32 for line
in open(filename
).read().splitlines():
33 if line
.startswith('# Translators:'):
36 match
= re
.match(r
'# ([^<]* <[^>]*>)', line
)
38 translators
.append(match
.group(1))
40 in_translators
= False
42 match
= re
.search(r
'Last-Translator: ([^<]* <[^>]*>)', line
)
44 translators
.append(match
.group(1))
46 match
= re
.match(r
'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line
)
48 match
= re
.match(r
'"Language-Team: ([^\(]+).*\\n"', line
, re
.DOTALL
)
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
)
57 print '# FIXME (could not parse):', '!'*10, filename
, '!'*10