Back to index

plone3  3.1.7
admix.py
Go to the documentation of this file.
00001 """
00002    Usage: admix.py <target-product> <source-product>
00003 """
00004 
00005 import os, sys, shutil
00006 from utils import getPoFiles, getLanguage
00007 
00008 __I18NDUDE = os.environ.get('I18NDUDE', 'i18ndude')
00009 
00010 def main():
00011     if len(sys.argv) < 3:
00012         print 'You have to specify the target and source product.'
00013         sys.exit(1)
00014 
00015     target = sys.argv[1]
00016     source = sys.argv[2]
00017 
00018     os.chdir('..')
00019     os.chdir('i18n')
00020 
00021     targetPoFiles = getPoFiles(target)
00022     sourcePoFiles = getPoFiles(source)
00023 
00024     if targetPoFiles == [] or sourcePoFiles == []:
00025         print 'No po-files were found for one of the given products.'
00026         sys.exit(3)
00027 
00028     for t in targetPoFiles:
00029         targetLanguage = getLanguage(target,t)
00030         for s in sourcePoFiles:
00031             sourceLanguage = getLanguage(source,s)
00032             if targetLanguage and sourceLanguage and targetLanguage == sourceLanguage:
00033                 print '%s %s <- %s' % (getLanguage(target, t), t, s)
00034                 os.system(__I18NDUDE + (' admix %s %s > %s-new') % (t, s, t))
00035                 targetpath = os.path.join(os.curdir, t)
00036                 os.remove(targetpath)
00037                 if not os.path.exists(targetpath):
00038                     shutil.copy(t+'-new', t)
00039                     os.remove(targetpath+'-new')
00040 
00041 if __name__ == '__main__':
00042     main()