Beispiel #1
0
 def getSysDialogFile(self, path, save=False, langcodes=None):
     """ Generates a System Dialog 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.
     """
     global DialogIdMatcher
     dlog = SysDialogFile(path)
     projdialogs = {} # projkey -> { dialogid -> dialog }
     for mid, ids in self.__mergelist.items():
         for idn in ids:
             if DialogIdMatcher.search(idn) is not None:
                 projkey, did, strid = DialogIdMatcher.search(idn).groups()
                 try:    val = copy.deepcopy( self.__strings[mid] )
                 except: val = copy.deepcopy( self.__pruned[mid] )
                 val.setID( strid )
                 val = val.limitByCodes( langcodes )
                 
                 if projdialogs.get(projkey) is None:
                     projdialogs[projkey] = {}
                 
                 if projdialogs[projkey].get(did, None) is None:
                     dialog = RCDialog(did)
                     dialog._values.append(val)
                     projdialogs[projkey][did] = dialog
                 else:
                     projdialogs[projkey][did]._values.append(val)
     
     for projkey, dlogs in projdialogs.items():
         dlog._projs[self.getProjName(projkey)] = dlogs.values()
     if save: dlog.save()
     return dlog
Beispiel #2
0
 def __d2r(self): 
     logging.debug("Pushing dialogs into resources...")
     if isSystemLevelDialog(self.__input):
         logging.debug("\tDialogs file is System level.")
         file = SysDialogFile( 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.updateDialogs(projFile)
     else:
         logging.debug("\tDialogs file is Project or language Level.")
         projFile = RCDialogFile( 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.updateDialogs(projFile)
             else: raise MissingLangCodeError()  
Beispiel #3
0
 def makeSysDialog( projDialogFiles, sysDialogPath, autosave=True ): 
     """Passing in a list of paths to dialog files, and a path for the new
     System level dialog file, this function will join all of them into 
     a new Master dialog file for your entire solution.
     """
     sdf = SysDialogFile( sysDialogPath )
     for file in projDialogFiles:
         name = iohelp.lastdirname(file)
         try:
             sdf.addProjLevelFile(name, file)
         except Exception as e: logging.exception(e)
     if autosave: sdf.save()
     return sdf
Beispiel #4
0
    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
        
        
Beispiel #5
0
 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