def __s2r(self): logging.debug("Pushing strings into resources...") if isSystemLevelStringTable(self.__input): logging.debug("\tString table file is System Level.") file = SysStrTblFile( self.__input ) file.load() for cpath,name in self.__output: resource = scanRCFile(cpath) if not self.__validLangcode(resource._langcode): logging.debug("\t\tIgnoring '%s' because its not the right langcode. @> %s"%(name,cpath)) continue try: projFile = file.genProjLevelFile( resource._name, '' ) except KeyError: logging.warning("Project %s does not exist in %s"%(resource._name, self.__input)) continue resource.updateStringTables(projFile) else: logging.debug("\tString Table File is Project or Language Level.") projFile = RCStrTblFile( self.__input ) projFile.load() langs = projFile._table.getPossibleLangs() for cpath,name in self.__output: resource = scanRCFile(cpath) if not self.__validLangcode(resource._langcode): logging.debug("\t\tIgnoring '%s' because its not the right langcode. @> %s"%(name,cpath)) continue if resource._langcode in langs: logging.debug("\t\tUpdating %s @> %s"%(name,cpath)) resource.updateStringTables(projFile) else: raise MissingLangCodeError()
def __genLangLevelUtil( self, ret=False, save=True, doMenus=True, doDialogs=True, doStrings=True): """Generate the Language Level utility files for the entire system.""" for cpath,name in iohelp.dirwalk(self.__sysdir, filter=iohelp.RCFilters.RCFilter, ignore=iohelp.RCFilters.BinaryDirs): logging.debug("~ LangLevel: found filter match '%s'! "%cpath) rcs = scanRCFile( cpath ) if rcs is None: continue blank,_ = opath.splitext(cpath) totalMenus, totalDialogs, totalStrings = [],[],None if doMenus: menus = rcs.pullMenu() for menu in menus: totalMenus.append(menu) if save: #logging.debug("~ LangLevel: Saving menu file for resource '%s'! "%name) if not self.__changeoutputs: InMemMenu(blank+".menus", totalMenus).save() else: InMemMenu('', totalMenus).save(opath.join(self.__outdir, name+".menus")) if doDialogs: dialogs = rcs.pullDialog() for dialog in dialogs: totalDialogs.append(dialog) if save: #logging.debug("~ LangLevel: Saving dialog file for resource '%s'! "%name) if not self.__changeoutputs: InMemDialog(blank+".dialogs", totalDialogs).save() else: InMemDialog('', totalDialogs).save(opath.join(self.__outdir, name+".dialogs")) if doStrings: strings = rcs.pullStringTable() for table in strings: if totalStrings is None: totalStrings=table else: totalStrings.addStringTable( table ) if save: #logging.debug("~ LangLevel: Saving string file for resource '%s'! "%name) if not self.__changeoutputs: InMemTable(blank+".strtbls", totalStrings).save() else: InMemTable('', totalStrings).save(opath.join(self.__outdir, name+".strtbls")) if ret: yield (cpath, totalMenus, totalDialogs, totalStrings)
def __t2r(self): logging.debug("Pushing Translator into resources...") trans = TranslationFile( self.__input, self.__defaultLangCode() ) trans.load() logging.debug("\tPulling out sys utils") menuFile = trans.getSysMenuFile('') dlogFile = trans.getSysDialogFile('') strsFile = trans.getSysStrTblFile('') projFiles = {} for cpath,name in self.__output: resource = scanRCFile( cpath ) if not self.__validLangcode( resource._langcode ): logging.debug("\t\tIgnoring '%s' because its not the right langcode. @> %s"%(name,cpath)) continue try: if resource._name in projFiles: logging.debug("\t\tReloading proj lvl files for %s..."%resource._name) projMenus, projDlogs, projConts = projFiles[ resource._name ] else: logging.debug("\t\tPulling out proj lvl files for %s..."%resource._name) projMenus = menuFile.genProjLevelFile(resource._name, '') projDlogs = dlogFile.genProjLevelFile(resource._name, '') projConts = strsFile.genProjLevelFile(resource._name, '') projFiles[ resource._name ] = (projMenus, projDlogs, projConts) except KeyError: logging.warning("Project %s does not exist in %s. (path=%s,name=%s)"%(resource._name,self.__input,cpath,name)) continue logging.debug("\t\tUpdating %s @> %s"%(name,cpath)) buff = resource.updateMenus( projMenus, save=False ) buff = resource.updateDialogs( projDlogs, save=False, buffer=buff ) resource.updateStringTables( projConts, buffer=buff )
def copyrcs( dir, removeOld=False, editProjFiles=True, mkProjBackups=True, mkResBackups=False ): """ Copies the default language resource files and renames them to have the new language code in them. Two pass, slower but it works. """ def atPathExistsResource( path ): return opath.exists(opath.join(opath.split(path)[0], "resource.h")) or \ opath.exists(opath.join(opath.split(path)[0], "Resource.h")) projs = [] # 1st Pass: Determine what resources to create and edit project files if need be filters = ['vcxproj','filters', 'vcproj'] for cpath, name in dirwalk(dir, filter=filters, ignore=RCFilters.BinaryDirs): proj = getproj( cpath ) rc = getpath(cpath, proj+".rc") if opath.splitext(cpath)[1] == '.vcxproj': # make sure that the project even has resources # and the given resource doesn't already exist. if atPathExistsResource( cpath ) and \ not opath.exists(renameWithExt(rc)): if editProjFiles: fixVCXproj( cpath, mkProjBackups ) projs.append( proj ) else: print("!Skipping project file edit of: %s"%proj) if removeOld: projs.append(proj) elif editProjFiles and opath.splitext(cpath)[1] == '.filters': # make sure that the project even has resources # and the given language resource doesn't already exist if atPathExistsResource( cpath ) and \ not opath.exists(renameWithExt(rc)): fixProjFilters( cpath, mkProjBackups ) ## Purely for warnings! elif opath.splitext(cpath)[1] == ".vcproj": print("!---> Project '%s' has not been updated to VS 2010! SKIPPING!"%proj) # 2nd Pass: We add all of our resources! filters = RCFilters.HeaderFilter + RCFilters.RCFilter for cpath, name in dirwalk(dir, filter=filters, ignore=RCFilters.BinaryDirs): proj = getproj(cpath) if proj not in projs: continue # project was not updated, or doesn't need to be. if name.lower() == "resource.h": newpath = getpath(cpath, renameWithExt( "resource.h" )) #make sure all created headers are lowercase mycopy(cpath, newpath, removeOld, mkResBackups) elif opath.splitext(cpath)[1] == ".rc": if scanRCFile(cpath, defaultLang=DEFAULT_CODE)._langcode == DEFAULT_CODE: newpath = getpath(cpath, renameWithExt( name )) mycopy(cpath, newpath, removeOld, mkResBackups) else: continue