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
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 _getHeadersFromPath( path ): basePath = opath.dirname( path ) headers = [] for cpath, name in iohelp.dirwalk(basePath, filter=iohelp.RCFilters.HeaderFilter, ignore=iohelp.RCFilters.BinaryDirs): if name.lower().startswith("resource"): headers.append(cpath) return headers
def restoreBackups( dir ): bklen = len(BACKUP_TAG) for cpath, name in dirwalk(dir, ignore=RCFilters.BinaryDirs): if name[-bklen:] == BACKUP_TAG: newpath = cpath[:-bklen] # delete the old one remove(newpath) # restore old old backup copy( cpath, newpath ) # remove backup file remove(cpath) print("Restored backup of: %s"%newpath)
def __init__(self, inputPath, inputType, outputPath, outputType, langcodes=None, makenew=False): self.__input = inputPath self.__inputType = inputType self.__outputType = outputType self.__makenew = makenew self.__output = [] self.__langcodes = langcodes self.__outputPath = outputPath if makenew or PusherOutputs.isSingleFile( outputType ): self.__output.append( (outputPath, opath.split(outputPath)[1])) else: self.__output = \ [ x for x in dirwalk( outputPath, filter=PusherOutputs.Filter(outputType), ignore=RCFilters.BinaryDirs ) ]
def removeBackups( dir ): bklen = len(BACKUP_TAG) for cpath, name in dirwalk(dir, ignore=RCFilters.BinaryDirs): if name[-bklen:] == BACKUP_TAG: remove(cpath) print("Removed backup: %s"%cpath)