Back to index

plone3  3.1.7
rebuild-pot.py
Go to the documentation of this file.
00001 """
00002    Usage: rebuild-pot.py <product> <path to products dir>
00003 
00004    If you are lazy you can also use atct, atrbw etc. as shorthands and if you
00005    set your INSTANCE_HOME correctly it will automagically use the right version.
00006 
00007    So 'rebuilt-pot.py atrbw' is a valid shorthand.
00008 """
00009 
00010 import os, sys, string
00011 from utils import getLongProductName, getProductPath
00012 
00013 try:
00014     import win32api
00015     WIN32 = True
00016 except ImportError:
00017     WIN32 = False
00018 
00019 __I18NDUDE = os.environ.get('I18NDUDE', 'i18ndude')
00020 __INSTANCE_HOME = os.environ.get('INSTANCE_HOME', '')
00021 
00022 def rebuild(product, folder=''):
00023     product = getLongProductName(product)
00024 
00025     pot = product + '.pot'
00026     manualpot = '%s-manual.pot' % product
00027     generatedpot = '%s-generated.pot' % product
00028     if '/' in product:
00029         product = product.split('/')[1]
00030 
00031     log = 'rebuild-%s-pot.log' % product
00032     domain = product
00033 
00034     os.chdir('..')
00035     os.chdir('i18n')
00036 
00037     if not os.path.isfile(manualpot):
00038         print 'Manual pot missing for the given product: %s.' % manualpot
00039         sys.exit(3)
00040 
00041     folder2 = ''
00042     if product == 'plone':
00043         packages = (
00044             'archetypes.kss',
00045             'plone.contentrules',
00046             'plone.fieldsets',
00047             'plone.i18n',
00048             'plone.locking',
00049             'plone.memoize',
00050             'plone.openid',
00051             'plone.portlets',
00052             'plone.portlet.collection',
00053             'plone.portlet.static',
00054             'plone.session',
00055             'plone.intelligenttext',
00056             'plone.app.contentmenu',
00057             'plone.app.content',
00058             'plone.app.contentrules',
00059             'plone.app.controlpanel',
00060             'plone.app.customerize',
00061             'plone.app.form',
00062             'plone.app.i18n',
00063             'plone.app.iterate',
00064             'plone.app.kss',
00065             'plone.app.layout',
00066             'plone.app.linkintegrity',
00067             'plone.app.portlets',
00068             'plone.app.redirector',
00069             'plone.app.viewletmanager',
00070             'plone.app.vocabularies',
00071             'plone.app.workflow',
00072             'plone.app.openid',
00073             'Products.Archetypes',
00074             'Products.CMFDiffTool',
00075         )
00076         add_products = (
00077             'Archetypes',
00078             'CMFDiffTool',
00079         )
00080 
00081         src = os.path.join(__INSTANCE_HOME, 'src')
00082         for package in packages:
00083             p = os.path.join(src, package)
00084             if os.path.isdir(p):
00085                 folder2 += ' %s' % p
00086         src = os.path.join(__INSTANCE_HOME, 'products')
00087         for prod in add_products:
00088             p = os.path.join(src, prod)
00089             if os.path.isdir(p):
00090                 folder2 += ' %s' % p
00091 
00092     foldererror = False
00093     if not os.path.isdir(folder) and folder == '':
00094         folder = os.path.join(__INSTANCE_HOME, 'Products')
00095         if os.path.isdir(folder):
00096             folder = os.path.join(folder, getProductPath(product))
00097             if not os.path.isdir(folder):
00098                 # Try the src folder instead
00099                 base = os.path.basename(folder)
00100                 src = os.path.join(__INSTANCE_HOME, 'src')
00101                 package = os.path.join(src, 'Products.%s' % base)
00102                 if os.path.isdir(package):
00103                     folder = package
00104                 else:
00105                     foldererror = True
00106         else:
00107             foldererror = True
00108     else:
00109         foldererror = True
00110 
00111     if foldererror:
00112         print 'Directory (%s) could not be found.' % folder
00113         sys.exit(4)
00114 
00115     # Remove the original file
00116     if os.path.isfile(pot):
00117         os.remove(pot)
00118 
00119     print 'Using %s to build new pot.\n' % folder
00120     cmd = __I18NDUDE + (' rebuild-pot --pot %s --create %s --merge %s ') % (pot, domain, manualpot)
00121     if product == 'plone':
00122         cmd += '--merge2 %s ' % generatedpot
00123     if product == 'plone':
00124         ignores = ('rss_template.pt',
00125                    'metadata_edit_form.cpt',
00126                    'metadirectives.py',
00127                    'Discussion_Item.xml',
00128                   )
00129         cmd += '--exclude="%s" ' % ' '.join(ignores)
00130     if product.startswith('kupu'):
00131         ignores = ('mmbase',
00132                    'widgeteer',
00133                    'kupu_kjax_support.xml.pt',
00134                    'kupu_migration.xml.pt',
00135                   )
00136         cmd += '--exclude="%s" ' % ' '.join(ignores)
00137     if product == 'plone':
00138         cmd += '%s %s > %s 2>&1' % (folder, folder2, log)
00139         # For debugging
00140         # cmd += '%s %s' % (folder, folder2)
00141     else:
00142         cmd += '%s > %s 2>&1' % (folder, log)
00143     print 'Rebuilding to %s - this takes a while, logging to %s' % (pot, log)
00144     os.system(cmd)
00145 
00146 def main():
00147     if len(sys.argv) < 2:
00148         print 'You have to specify an option.'
00149         sys.exit(1)
00150 
00151     if len(sys.argv) == 2:
00152         rebuild(sys.argv[1])
00153     else:
00154         rebuild(sys.argv[1], sys.argv[2])
00155 
00156 if __name__ == '__main__':
00157     main()