#!/usr/bin/env python

#This script handles updates of the 'betahaus.maps.openmember' i18n domain

import subprocess, sys, os

DOMAIN = 'betahaus.maps.openmember'
PRODUCTS = ['betahaus.maps.openmember']

def generate():
    paths = []
    
    for product in PRODUCTS:
        parts = product.split('.')
        paths.append("../../../../%s/%s/%s/%s" % (product,parts[0],parts[1],parts[2]))
    
    command = "i18ndude rebuild-pot --pot i18n/generated.pot --create %s %s" % (DOMAIN, " ".join(paths) )
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    print p.stdout.read()

def merge():
    print "Merging manual entries"
    command = "i18ndude merge --pot i18n/generated.pot --merge i18n/manual.pot"
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    print p.stdout.read()

def sync():
    print "Syncing i18n files"
    command = "i18ndude sync --pot i18n/generated.pot i18n/%s*.po" % (DOMAIN,)
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    print p.stdout.read()

generate()
merge()
sync()
print 'All done'
