#!/usr/bin/python
import os, sys, glob, string
import subprocess 

file_list = []

for dir in glob.glob(os.getcwd()):
	for item in glob.glob(dir + '/*.po'):
		file_list.append(item)

file_list.sort()

for item in file_list:
	#(child_stdin, child_stdout, child_stderr) = os.popen3("msgfmt --statistics " + item)
	p = subprocess.Popen("msgfmt --statistics " + item, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) 
	(child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr)

	fields = string.split(child_stdout.readline())
	translated = untranslated = fuzzy = 0

	for n in range(0, len(fields)-1):
		if fields[n+1] == "translated":
			translated = fields[n]
		if fields[n+1] == "untranslated":
			untranslated = fields[n]
		if fields[n+1] == "fuzzy":
			fuzzy = fields[n]

	(dir, file) = os.path.split(item)
	os.unlink(dir + "/messages.mo")

	complete = int(translated)*100/(int(translated)+int(fuzzy)+int(untranslated))
	print "%8s  %6d %6d %6d  :  %3d%%" % (file, int(translated), int(fuzzy), int(untranslated), complete)

# 23.01.2008, 05.01.2010
# http://clayo.org


