Esempio n. 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()  
Esempio n. 2
0
 def addProjLevelFile(self, projName, path, obj=None, overwrite=True): 
     if not overwrite and projName in self._projs:
         raise KeyError("Project already exists!")
     if obj is None:
         file = RCMenuFile( path )
         if not file.load():
             raise Exception("Could not load Menu File!")
     else: file = obj
     self._projs[ projName ] = copy.deepcopy(file._menus)
     return True
Esempio n. 3
0
def ScanAndMergeMenus( newPath, menuFiles ):
    """Scans all files in a list and merges them together to make a project
    level file. This is considered a merge since its RCMenuFiles that are 
    being utilized. If there is a problem scanning, then the error is raised.
    """
    if len(menuFiles) < 1: return None
    from lslib.base.file.utility.MenuFile import ScanMenuFile, RCMenuFile
    
    # find headers for this particular resource
    headers = _getHeadersFromPath( menuFiles[0]._path )
    
    # scan all files with the headers, merging as we go.
    if len(menuFiles) == 1:
        mergedProjFile = copy.deepcopy(menuFiles[0])
        mergedProjFile._path = newPath
    else:
        mergedProjFile = RCMenuFile(newPath)
        for menufile in menuFiles: 
            ScanMenuFile(menufile, headers)
            mergedProjFile = RCMenuFile.merge(newPath, mergedProjFile, menufile, True, True)
    return mergedProjFile
Esempio n. 4
0
 def __genProjLevelUtil( self, useExisting=False, keepInMem=False, ret=False, save=True, doMenus=True, doDialogs=True, doStrings=True ): 
     """Generate the Project Level Utility files for an entire system. If 
     `useExisting` has been set to True, it will use the existing utility 
     files for generating the project files. Otherwise it will regenerate
     new lang-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 project level creation and then
     discard them.
     """
     menuFiles, dialogFiles, stringFiles = [],[],[] #our lang files
     projMenus, projDialogs, projStrings = None,None,None
     if not useExisting:
         project = ''
         basename=''
         for cpath, ms, ds, ss in self.__genLangLevelUtil(True, (not keepInMem), doMenus, doDialogs, doStrings):
             
             # if we arrive at a new project directory
             if iohelp.lastdirname(cpath) != project:
                 
                 #check first if we have any utility files from the previous 
                 #project we visited. If we do we need to create the project
                 #level files from them.
                 if len(menuFiles)>0 or len(dialogFiles)>0 or len(stringFiles)>0:
                     try:
                         if doMenus:
                             projMenus  = ScanAndMergeMenus( basename+".menus", menuFiles )
                         if doDialogs:
                             projDialogs = ScanAndMergeDialogs(basename+".dialogs", dialogFiles )
                         if doStrings:
                             projStrings = ScanAndMergeStrings(basename+".strtbls", stringFiles )
                         if save:
                             if doMenus: 
                                 if not self.__changeoutputs: projMenus.save()
                                 else: projMenus.save(opath.join(self.__outdir, project+".menus"))
                             if doDialogs: 
                                 if not self.__changeoutputs: projDialogs.save()
                                 else: projDialogs.save(opath.join(self.__outdir, project+".dialogs"))
                             if doStrings: 
                                 if not self.__changeoutputs: projStrings.save()
                                 else: projStrings.save(opath.join(self.__outdir, project+".strtbls"))
                         if ret: 
                             yield project, projMenus, projDialogs, projStrings
                     except Exception as e: logging.exception(e)
                 # now that we have all the previous project stuff set up, lets
                 #reset our project vars with the current information.
                 project = iohelp.lastdirname( cpath )
                 basename = opath.join( opath.dirname(cpath), project )
                 menuFiles, dialogFiles, stringFiles = [],[],[]
                    
             # Add our lang-level utility files to their respective lists. 
             blank,_ = opath.splitext( cpath )
             if doMenus:   menuFiles   .append( InMemMenu(blank+".menus", ms)    )
             if doDialogs: dialogFiles .append( InMemDialog(blank+".dialogs", ds))
             if doStrings: stringFiles .append( InMemTable(blank+".strtbls", ss) )
             
         #We are out of the iteration. Lets check if we finished in the middle
         #of a project (which is highly likely).
         if len(menuFiles)>0 or len(dialogFiles)>0 or len(stringFiles)>0:
             project  = iohelp.lastdirname( cpath )
             basename = opath.join( opath.dirname(cpath), project )
             if doMenus:   projMenus   = ScanAndMergeMenus( basename+".menus", menuFiles )
             if doDialogs: projDialogs = ScanAndMergeDialogs(basename+".dialogs", dialogFiles )
             if doStrings: projStrings = ScanAndMergeStrings(basename+".strtbls", stringFiles )
             if save:
                 if doMenus: 
                     if not self.__changeoutputs: projMenus.save()
                     else: projMenus.save(opath.join(self.__outdir, project+".menus"))
                 if doDialogs: 
                     if not self.__changeoutputs: projDialogs.save()
                     else: projDialogs.save(opath.join(self.__outdir, project+".dialogs"))
                 if doStrings: 
                     if not self.__changeoutputs: projStrings.save()
                     else: projStrings.save(opath.join(self.__outdir, project+".strtbls"))
             if ret: yield project, projMenus, projDialogs, projStrings
     else: #itterate through existing.
         #Loop through all the projects, and grab the utiliy files currently in
         #the directories.
         for utils in iohelp.dirwalkl(self.__sysdir,
                                       exclude=iohelp.RCFilters.SysLevelFilter, 
                                       filter=iohelp.RCFilters.UtilityFilter,
                                       ignore=iohelp.RCFilters.BinaryDirs):
             #for each utility file found, determine if its a dialog, menu, or stringtable
             #depending on which one we must add it to the correct list.
             for cpath, name in utils:
                 if iohelp.fileok(name, filter=["menus"]):
                     if not doMenus: continue
                     tmp = RCMenuFile(blank+".menus")
                     tmp.load()
                     menuFiles.append( tmp )
                 elif iohelp.fileok(name, filter=["dialogs"]):
                     if not doDialogs: continue
                     tmp = RCDialogFile(blank+".dialogs")
                     tmp.load()
                     dialogFiles.append( tmp  )
                 elif iohelp.fileok(name, filter=["strtbls"]):
                     if not doStrings: continue
                     tmp = RCStrTblFile(blank+".strtbls")
                     tmp.load()
                     stringFiles.append( tmp )
                 else: logging.error("Matched utility filter when there was no need! %s"%cpath)
             if len(menuFiles)>0 or len(dialogFiles)>0 or len(stringFiles)>0:
                 if doMenus:   projMenus   = ScanAndMergeMenus( basename+".menus", menuFiles )
                 if doDialogs: projDialogs = ScanAndMergeDialogs( basename+".dialogs", dialogFiles )
                 if doStrings: projStrings = ScanAndMergeStrings( basename+".strtbls", stringFiles )
                 if save:
                     if doMenus: 
                         if not self.__changeoutputs: projMenus.save()
                         else: projMenus.save(opath.join(self.__outdir, project+".menus"))
                     if doDialogs: 
                         if not self.__changeoutputs: projDialogs.save()
                         else: projDialogs.save(opath.join(self.__outdir, project+".dialogs"))
                     if doStrings: 
                         if not self.__changeoutputs: projStrings.save()
                         else: projStrings.save(opath.join(self.__outdir, project+".strtbls"))
                 if ret: yield project, projMenus, projDialogs, projStrings
             menuFiles, dialogFiles, stringFiles = [],[],[]
             basename = opath.join( opath.dirname(cpath), project )