Example #1
0
 def __m2r(self): 
     logging.debug("Pushing menus into resources...")
     if isSystemLevelMenu(self.__input):
         logging.debug("\tMenus file is System Level.")
         file = SysMenuFile( 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
             logging.debug("\t\tUpdating %s @> %s"%(name,cpath))
             resource.updateMenus(projFile)
             
     else:
         logging.debug("\tMenus file is Project or language Level.")
         projFile = RCMenuFile( 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.updateMenus(projFile)
             else: raise MissingLangCodeError()  
Example #2
0
def ConvertMenuCSV2XML(newpath, csvFile, preloaded=True, autosave=False):
    """A utility function for converting between the CSV and XML versions
    of the System Menu Files. 
    """
    if not preloaded: csvFile.load()
    xml = SysMenuFile( newpath )
    for project in csvFile.getProjects():
        xml._projs[project] = csvFile.getProjectMenus( project )
    if autosave: xml.save()
    return xml
Example #3
0
 def makeSysMenu( projMenuFiles, sysMenuPath, autosave=True  ): 
     """Passing in a list of paths to menu files, and a path for the new 
     System level menu file, this function will join all of them into a 
     new Master menu file for your entire solution.
     """
     smf = SysMenuFile(sysMenuPath)
     for file in projMenuFiles:
         name = iohelp.lastdirname(file)
         try:
             smf.addProjLevelFile(name, file)
         except Exception as e: logging.exception(e)
     if autosave: smf.save()
     return smf
Example #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
        
        
Example #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