def UpdateHtml(): strBaseDir = os.path.join(os.getcwd(), 'website','app') for strFile in ['noaccess.html', 'noaccess_guest.html', 'noaccess_registered.html']: for dLocaleInfo in LocaleInfo.LocaleListSortedByName(): astrLocaleLinks = [] for dLocaleInfo2 in LocaleInfo.LocaleListSortedByName(): strClass = '' if dLocaleInfo2['locale'] == dLocaleInfo['locale']: strClass = 'selected' astrLocaleLinks.append('\t<a href="/?locale=' + dLocaleInfo2['locale'] + '" class="' + strClass + '">' + dLocaleInfo2['name'] + '</a>') strFooterLocaleLinks = "\n\t\t|\n".join(astrLocaleLinks) strPath = os.path.join(strBaseDir, dLocaleInfo['locale'], strFile) try: fin = open(strPath, 'rb') strContents = fin.read() fin.close() except: strPath = strPath.replace(dLocaleInfo['locale'], 'en_US') print "Reading contents from en_US location: ", strPath fin = open(strPath, 'rb') strContents = fin.read() fin.close() try: strOut = ReplaceGeneratedCode2(strContents, "FooterLocaleList", strFooterLocaleLinks) except: print "Error writing", strPath print "strContents" print strContents raise P4File.p4write(strPath, strOut, "updateLocales")
def UpdateLocaleInfoAs(): print "Updating LocaleInfo.as" strPath = os.path.join(os.getcwd(), 'as','util','picnik','util','LocaleInfo.as') fin = open(strPath, 'rb') strContents = fin.read() fin.close() strInsert = "\t\tstatic private var _aobAllLocales:Array = [\n\t\t\t" fFirst = True for dLocaleInfo in LocaleInfo.LocaleListSortedByName(): if not fFirst: strInsert += ",\n\t\t\t" strLine = "{" fFirstKey = True # these are the keys we are interested in dKeys = { 'label':{'fnGet':lambda x : x['name']}, 'locale':{'sortPriority':0}, 'flag':{'fnGet':lambda x : x['locale'][3:].lower()}, 'useSystemFont':{}, 'nonBold':{}, 'countries':{}, 'googleCode':{}, 'googlePlus':{'fOptional':True} } atKeys = sorted(dKeys.items(), key=lambda t: (t[1].get('sortPriority', 100), t[0])) for atKeys in atKeys: strKey, dKeyInfo = atKeys if 'fnGet' in dKeyInfo: obVal = dKeyInfo['fnGet'](dLocaleInfo) else: if not (strKey in dLocaleInfo): if dKeyInfo.get('fOptional', False): continue else: print "ERROR: Locale missing field: " + strKey print dLocaleInfo sys.exit(1) obVal = dLocaleInfo[strKey] if not fFirstKey: strLine += ", " fFirstKey = False strLine += strKey + ": " if type(obVal) == type(True): strLine += str(obVal).lower() elif type(obVal) == type([]): strLine += str(obVal) else: # everything else is a string strLine += "'" + str(obVal) + "'" strLine += "}" strInsert += strLine fFirst = False strInsert += "\n\t\t];\n" strOut = ReplaceGeneratedCode(strContents, "LocaleInfo", strInsert) P4File.p4write(strPath, strOut, "updateLocales")