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(
16 os
.path
.dirname(os
.path
.abspath(__file__
)),
27 process
= subprocess
.Popen(
28 ["git", "status", "--porcelain"] + glob
.glob(pofiles
), stdout
=subprocess
.PIPE
30 stdout
, stderr
= process
.communicate()
31 for line
in stdout
.splitlines():
32 status
, filename
= line
.strip().split()
34 filenames
.append(filename
)
36 for filename
in filenames
:
37 in_translators
= False
41 filename
= os
.path
.join("..", "..", filename
)
42 for line
in open(filename
).read().splitlines():
43 if line
.startswith("# Translators:"):
46 match
= re
.match(r
"# ([^<]* <[^>]*>)", line
)
48 translators
.append(match
.group(1))
50 in_translators
= False
52 match
= re
.search(r
"Last-Translator: ([^<]* <[^>]*>)", line
)
54 translators
.append(match
.group(1))
56 match
= re
.match(r
'"Language-Team: ([^\(]+) \(http://www.transifex.net/', line
)
58 match
= re
.match(r
'"Language-Team: ([^\(]+).*\\n"', line
, re
.DOTALL
)
60 language
= match
.group(1).strip()
62 if translators
and language
is not None:
63 if len(translators
) != 1:
64 print("# Warning: %d other translators" % (len(translators
) - 1,))
66 'git commit --author="%s" --message="Updated %s translation" %s'
67 % (translators
[0], language
, filename
)
70 print("# FIXME (could not parse):", "!" * 10, filename
, "!" * 10)