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 makeSysStrTbl( projStrTblFiles, sysStrTblPath, autosave=True ): """Passing in a list of paths to string table files, and a path for a new System level string table file, this function will join all of them into a new Master string table file for your entire solution. """ ssf = SysStrTblFile(sysStrTblPath) for file in projStrTblFiles: name = iohelp.lastdirname(file) try: ssf.addProjLevelFile(name, file) except Exception as e: logging.exception(e) if autosave: ssf.save() return ssf
def getSysStrTblFile(self, path, save=False, langcodes=None): """ Generates a System String Table File from the internals of the translation file. This does not save the file, instead is merely returned. This can be changed, by setting `save` to True. """ strtblfile = SysStrTblFile( path ) projtables = {} # projkey -> RCStrTbl for mid, ids in self.__mergelist.items(): for idn in ids: if ConstantIdMatcher.search(idn) is not None: projkey, consid = ConstantIdMatcher.search(idn).groups() try: val = copy.deepcopy( self.__strings[mid] ) except: val = copy.deepcopy( self.__pruned[mid] ) val.setID( consid ) if projtables.get(projkey, None) is None: projtables[projkey] = RCStrTbl() projtables[projkey].addStringValue( val.limitByCodes(langcodes) ) for proj, strtbl in projtables.items(): strtblfile._projs[ self.getProjName(proj) ] = strtbl if save: strtblfile.save() return strtblfile
def __genTranslator( self, langcodes, useExisting=False, keepInMem=False, save=True, ret=False, order=False, prunepath=None, markconflicts=False ): """Generate the translator file for the entire system.""" if self.__changeoutputs: newpath = opath.join(self.__outdir, Joiner.TRANS_FILENAME) else: newpath = opath.join(self.__sysdir, Joiner.TRANS_FILENAME) if not useExisting: menuFile, dialogFile, stringFile = self.__genSysLevelUtil(useExisting=False, useExistingLangLevel=False, keepInMem=keepInMem, save=False) else: #we must load by hand. basename = opath.join( self.__sysdir, Joiner.MASTER_FILENAME ) menuFile = SysMenuFile(basename+".menus") dialogFile = SysDialogFile(basename+".dialogs") stringFile = SysStrTblFile(basename+".strtbls") menuFile.load() ; dialogFile.load() ; stringFile.load() trans = MakeTranslationFile(newpath, menuFile, dialogFile, stringFile, True, save, langcodes, order, False, prunepath, markconflicts) if ret: return trans
def __genSysLevelUtil( self, useExisting=False, useExistingLangLevel=False, keepInMem=False, save=True, doMenus=True, doDialogs=True, doStrings=True ): """Generate the System Level Utility files for an entire system. If `useExisting` has been set to True, it will use the existing project level utility files for generating the system level. Otherwise it will regenerate new project level files (ie, overwrite existing). If `keepInMem` is True, it wont overwrite existing files, instead it will generate the new files and keep them in memory for the system level creation and then discard them. """ if self.__changeoutputs: basename = opath.join(self.__outdir, Joiner.MASTER_FILENAME) else: basename = opath.join(self.__sysdir, Joiner.MASTER_FILENAME) sysMenus = SysMenuFile(basename+".menus") sysDialogs = SysDialogFile(basename+".dialogs") sysStrings = SysStrTblFile(basename+".strtbls") if not useExisting: for project, menuFile, dialogFile, stringFile in self.__genProjLevelUtil(useExistingLangLevel, keepInMem, True, useExisting, doMenus, doDialogs, doStrings): if doMenus: sysMenus.addProjLevelFile(project, '', obj=menuFile) if doDialogs: sysDialogs.addProjLevelFile(project, '', obj=dialogFile) if doStrings: sysStrings.addProjLevelFile(project, '', obj=stringFile) else: # iterate through # Since we can't generate new ones, we have to go look for them in subdirs. # Also since we are looking through the subdirs, we run the risk of pulling out # lang-level utility files. So we need to prune those too. for utils in iohelp.dirwalkl(self.__sysdir, exclude=iohelp.RCFilters.SysLevelFilter, filter=iohelp.RCFilters.UtilityFilter, ignore=iohelp.RCFilters.BinaryDirs): strFound, menuFound, dialogFound = False, False, False # we have all the util files for the project. for cpath,name in utils: project = iohelp.lastdirname( cpath ) # if file is lang-lvl, then skip it. if opath.splitext(name)[0] != project: logging.debug("thought was lang-lvl: %s,%s"%(project, opath.splitext(name)[0])) continue #TODO: not very elegant! plus is it true?? logging.debug("filter time: %s"%name) if iohelp.fileok(name, filter=iohelp.RCFilters.MenuFilter): menuFound = True if not doMenus: continue sysMenus.addProjLevelFile( project, cpath ) elif iohelp.fileok(name, filter=iohelp.RCFilters.DialogFilter): dialogFound = True if not doDialogs: continue sysDialogs.addProjLevelFile( project, cpath ) elif iohelp.fileok(name, filter=iohelp.RCFilters.StrTblFilter): strFound = True if not doStrings: continue sysStrings.addProjLevelFile(project, cpath ) else: logging.error("Matched utility filter when there was no need! %s"%cpath) if not (strFound and menuFound and dialogFound): logging.warning("Was unable to find all of %s's utility files."%project) if save: if doMenus: sysMenus.save() if doDialogs: sysDialogs.save() if doStrings: sysStrings.save() return sysMenus, sysDialogs, sysStrings
def __trans2sys(self): logging.debug("Pushing Translator into System Level Utilities...") trans = TranslationFile( self.__input, self.__defaultLangCode() ) trans.load() if self.__makenew: logging.debug("\tPulling out new sys utils") trans.getSysMenuFile( opath.join(self.__outputPath, "System_Strings.master.menus"), True, self.__langcodes ) trans.getSysDialogFile( opath.join(self.__outputPath, "System_Strings.master.dialogs"), True, self.__langcodes ) trans.getSysStrTblFile( opath.join(self.__outputPath, "System_Strings.master.strtbls"), True, self.__langcodes ) logging.debug("\tSaved new system files from translator!") return logging.debug("\tPulling new sys utils to merge") menuFile = trans.getSysMenuFile('') dlogFile = trans.getSysDialogFile('') strsFile = trans.getSysStrTblFile('') strtbl, menus, dlogs = False, False, False for cpath,_ in self.__output: if opath.splitext(cpath)[1] == "strtbls" and \ PusherOutputs.isStringTable( self.__outputType ): if strtbl: #only allow one? logging.warning("\tFound another system string table file. Skipping: %s"%cpath) continue tmp = SysStrTblFile(cpath) tmp.load() logging.debug("\tUpdating @> %s"%cpath) tmp.updateFromTranslation(strsFile, autosave=True) strtbl = True elif opath.splitext(cpath)[1] == "menus" and \ PusherOutputs.isMenu( self.__outputType ): if menus: #only allow one? logging.warning("\tFound another system menu file. Skipping: %s"%cpath) continue tmp = SysMenuFile(cpath) tmp.load() logging.debug("\tUpdating @> %s"%cpath) tmp.updateFromTranslation(menuFile, autosave=True) menus = True elif opath.splitext(cpath)[1] == "dialogs" and \ PusherOutputs.isDialog( self.__outputType ): if dlogs: #only allow one? logging.warning("\tFound another system dialog file. Skipping: %s"%cpath) continue tmp = SysDialogFile(cpath) tmp.load() logging.debug("\tUpdating @> %s"%cpath) tmp.updateFromTranslation(dlogFile, autosave=True) dlogs = True # after we're done, lets inform them if there was something missing. if not strtbl: logging.debug("\tCould not find system string table file!") if not dlogs: logging.debug("\tCould not find system dialog file!") if not menus: logging.debug("\tCould not find system menu file!")