Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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