def CopyProp(strSrc, strDest): astrSrc = strSrc.split(':') astrDest = strDest.split(':') strSrcKey = astrSrc[1] strDestKey = astrDest[1] for strLocale in astrLocales: strPropFileBase = 'client/loc/' + strLocale strSrcPropFilePath = os.path.join(strPropFileBase, astrSrc[0]+".properties") pfSrc = PropFile(strSrcPropFilePath) strDestPropFilePath = os.path.join(strPropFileBase, astrDest[0]+".properties") pfDest = PropFile(strDestPropFilePath) if strSrcKey in pfSrc.dProps: prop = pfSrc.dProps[strSrcKey] prop.key = strDestKey pfDest.addProp(pfSrc.dProps[strSrcKey]) else: print "missing property " + strSrcKey + " in " + strSrcPropFilePath pfDest.save() print "copy prop from " + str(astrSrc) + " to " + strDest
def diff_props(strOldProps, strNewProps, fOut, fVerbose=False): fOut.write(codecs.BOM_UTF8) pfOld = PropFile(strOldProps) pfNew = PropFile(strNewProps) apropDiff = [] for strKey, p in pfNew.dProps.iteritems(): if not (strKey in pfOld.dProps) or not p.equals( pfOld.dProps[strKey]): if fVerbose: print " - " + strKey apropDiff.append(p) apropDiff.sort(lambda x, y: cmp(x.key, y.key)) for p in apropDiff: p.writeTo(fOut)
def install_props(obPropDiffFile, strDestRoot, strLocale, fnPreprocess=None): strDestBase = os.path.join(strDestRoot, strLocale) fSuccess = True pfDiff = PropFile(obPropDiffFile, fnPreprocess) # Output property files (with changes) keyed by path dpfOut = {} astrPrint = [] dpfSeen = {} for strKey, p in pfDiff.dProps.iteritems(): astrParts = strKey.split('.', 1) if len(astrParts) != 2: raise "ERROR: Diff prop key has no file: " + strKey + ", file = " + str( obPropDiffFile) + ", line: " + str(p.line) strOutPropPath = os.path.join(strDestBase, astrParts[0] + '.properties') p.key = astrParts[1] # Now we have the property with a short key and the output property path if not strOutPropPath in dpfOut: dpfOut[strOutPropPath] = PropFile(strOutPropPath) pfOut = dpfOut[strOutPropPath] pfOut.addProp(p) if obPropDiffFile.find('no_NO') > -1: astrPrint.append(strKey) for pfOut in dpfOut.itervalues(): pfOut.save() astrPrint.sort() for strPrint in astrPrint: print strPrint return fSuccess
def readProps(strPropBase, strLocale, strPropFileName): strPath = os.path.join(strPropBase, strLocale, strPropFileName + '.properties') return PropFile(strPath)
patLocale = re.compile('[a-z][a-z]_[a-z][a-z]', re.IGNORECASE) astrLocales = [] for dLocaleInfo in LocaleInfo.LocaleListSortedByName(): if dLocaleInfo['locale'] != 'en_US': astrLocales.append(dLocaleInfo['locale']) AddNewLocales() # Take care of properties strPropFileBase = 'client/loc/en_US' for strPropFileName in os.listdir(strPropFileBase): strSrcPropFilePath = os.path.join(strPropFileBase, strPropFileName) if strSrcPropFilePath.lower().endswith('.' + 'properties'): pfSrc = PropFile(strSrcPropFilePath) # Found a properties file. for strLocale in astrLocales: strDstPropFilePath = strSrcPropFilePath.replace('en_US', strLocale) if not os.path.exists(strDstPropFilePath): if fReportOnly: fLocError = True print "Missing file: " + strDstPropFilePath else: copyfile(strSrcPropFilePath, strDstPropFilePath) else: pfDst = PropFile(strDstPropFilePath, None, 'dummyloc') fDirty = False astrDirtyLocales = [] for strKey, p in pfSrc.dProps.iteritems():