예제 #1
0
    def __buildInventory(self):
        invTuple = self.LOCALIZATION_DICT[self.__classType]
        localLevels = ["BASE", "CONFIGURED", "SITE", "USER"]
        if self.__user == "SITE":
            localLevels = localLevels[:-1]
        if self.__user == "CONFIGURED":
            localLevels = localLevels[:-2]
        elif self.__user == "BASE":
            localLevels = localLevels[0]

        req = UtilityRequestMessage()
        cmds = []

        for level in localLevels:
            cmd = ListUtilityCommand()
            cmd.setSubDirectory(invTuple[1])
            cmd.setRecursive(False)
            cmd.setFilesOnly(True)
            cmd.setLocalizedSite(self.__siteID)
            ctx = LocalizationContext()
            ll = LocalizationLevel(level)
            locType = LocalizationType(invTuple[0])
            ctx.setLocalizationType(locType)
            ctx.setLocalizationLevel(ll)
            if level in ["CONFIGURED", "SITE"]:
                ctx.setContextName(self.__siteID)
            elif (level == "USER"):
                ctx.setContextName(self.__user)
            cmd.setContext(ctx)
            cmds.append(cmd)

        req.setCommands(cmds)

        try:
            serverResponse = self.__thrift.sendRequest(req)
        except Exception, e:
            raise RuntimeError, "Could not retrieve product inventory: " + str(e)
예제 #2
0
 def __buildInventory(self):
     invTuple = self.LOCALIZATION_DICT[self.__classType]
     localLevels = ["BASE", "CONFIGURED", "SITE", "USER"]
     if self.__user == "SITE":
         localLevels = localLevels[:-1]
     if self.__user == "CONFIGURED":
         localLevels = localLevels[:-2]
     elif self.__user == "BASE":
         localLevels = localLevels[0]
     
     req = UtilityRequestMessage()
     cmds = []
     
     for level in localLevels:             
         cmd = ListUtilityCommand()
         cmd.setSubDirectory(invTuple[1])
         cmd.setRecursive(False)
         cmd.setFilesOnly(True)
         cmd.setLocalizedSite(self.__siteID)
         ctx = LocalizationContext()
         ll = LocalizationLevel(level)
         type = LocalizationType(invTuple[0])
         ctx.setLocalizationType(type)
         ctx.setLocalizationLevel(ll)
         if level in ["CONFIGURED", "SITE"]:
             ctx.setContextName(self.__siteID)
         elif (level == "USER"):
             ctx.setContextName(self.__user)
         cmd.setContext(ctx)
         cmds.append(cmd)
 
     req.setCommands(cmds)
     
     try:
         serverResponse = self.__thrift.sendRequest(req)
     except Exception, e:
         raise RuntimeError,  "Could not retrieve product inventory: " + str(e)
예제 #3
0
def getTextInventory(category):
    if SourceUser not in ["SITE", "CONFIGURED", "BASE"]:
        locLevels = [LOCALIZATION_LEVELS[-1]]
    elif SourceUser == "SITE":
        locLevels = [LOCALIZATION_LEVELS[-2]]
    elif SourceUser == "CONFIGURED":
        locLevels = [LOCALIZATION_LEVELS[1]]
    else:
        locLevels = [LOCALIZATION_LEVELS[0]]

    invTuple = LOCALIZATION_DICT[category]
    inventory = {}
    for level in locLevels:
        req = UtilityRequestMessage()
        cmds = []
        cmd = ListUtilityCommand()
        cmd.setSubDirectory(invTuple[1])
        cmd.setRecursive(False)
        cmd.setFilesOnly(True)
        cmd.setLocalizedSite(SourceSite)
        ctx = LocalizationContext()
        ll = LocalizationLevel(level)
        type = LocalizationType(invTuple[0])
        ctx.setLocalizationType(type)
        ctx.setLocalizationLevel(ll)
        if (level == "USER"):
            ctx.setContextName(SourceUser)
        if (level in ["CONFIGURED", "SITE"]):
            ctx.setContextName(SourceSite)
        cmd.setContext(ctx)
        cmds.append(cmd)
        req.setCommands(cmds)

        try:
            serverResponse = Source.sendRequest(req)
        except:
            logException("Error getting inventory.")
            return None

        for response in serverResponse.getResponses():
            for entry in response.getEntries():
                if not entry.getProtectedFile():
                    filePath = entry.getFileName()
                    filename = os.path.split(filePath)[1]
                    shortName = os.path.splitext(filename)[0]
                    record = textInventoryRecord(filePath, entry.getContext(),
                                                 entry.getProtectedFile())
                    inventory[shortName] = record

    return inventory
예제 #4
0
def _executeLocalizationFileListRetrieval(filename, localizationLevels, localizedSite, 
                                          localizationUser, loctype, thrift):
    '''
    @param filename: the name of the localization file
    @param localizationLevels: a list of localization levels that should be checked
        for the specified localization file
    @param localizedSite: the site that localization information should be
        retrieved for (if applicable)
    @param localizationUser: the user that localization information should
        be retrieved for (if applicable)
    @param loctype: the type of localization files to retrieve
    @param thrift: an instance of the thrift client used to communicate
        with EDEX
    @return: a list of the localization files associated with the specified
        file name wrapped in a server response
    @summary: this function will execute a list utility command via thrift to
        retrieve a list of localization files that match the specified file name,
        that match the specified localization type, and that can be found within the
        specified localization levels.
    '''
    
    directory = os.path.dirname(filename)
    
    cmds = []
    
    # prepare the localization type
    localizationType = LocalizationType(loctype)
    
    # build the request message
    req = UtilityRequestMessage()
    for level in localizationLevels:
        cmd = ListUtilityCommand()
        cmd.setSubDirectory(directory)
        cmd.setRecursive(False)
        cmd.setFilesOnly(True)
        cmd.setLocalizedSite(localizedSite)
    
        # prepare the localization level
        localizationLevel = LocalizationLevel(level)
    
        # create a localization context
        localizationContext = LocalizationContext()
        localizationContext.setLocalizationType(localizationType)
        localizationContext.setLocalizationLevel(localizationLevel)
        if level in ['CONFIGURED', 'SITE' ]:
            localizationContext.setContextName(localizedSite)
        elif level == 'USER':
            localizationContext.setContextName(localizationUser)
        
        # build the utility command
        cmd.setContext(localizationContext)
        cmds.append(cmd)
    
    # add the command(s) to the request
    req.setCommands(cmds)
    
    try:
        serverResponse = thrift.sendRequest(req)
    except Exception, e:
        raise RuntimeError,  'Could not retrieve localization file list: ' + str(e)    
예제 #5
0
    def createListRequest(self):
        req = ListUtilityCommand()
        req.setRecursive(False)
        req.setFilesOnly(True)

        return req
예제 #6
0
def getTextInventory(category):
    if SourceUser not in ["SITE", "CONFIGURED", "BASE"]:
        locLevels = [LOCALIZATION_LEVELS[-1]]
    elif SourceUser == "SITE":
        locLevels = [LOCALIZATION_LEVELS[-2]]
    elif SourceUser == "CONFIGURED":
        locLevels = [LOCALIZATION_LEVELS[1]]
    else:
        locLevels = [LOCALIZATION_LEVELS[0]]
    
    invTuple = LOCALIZATION_DICT[category]
    inventory = {} 
    for level in locLevels:
        req = UtilityRequestMessage()
        cmds = []
        cmd = ListUtilityCommand()
        cmd.setSubDirectory(invTuple[1])
        cmd.setRecursive(False)
        cmd.setFilesOnly(True)
        cmd.setLocalizedSite(SourceSite)
        ctx = LocalizationContext()
        ll = LocalizationLevel(level)
        type = LocalizationType(invTuple[0])
        ctx.setLocalizationType(type)
        ctx.setLocalizationLevel(ll)
        if (level == "USER"):
            ctx.setContextName(SourceUser)
        if (level in ["CONFIGURED", "SITE"]):
            ctx.setContextName(SourceSite)
        cmd.setContext(ctx)
        cmds.append(cmd)
        req.setCommands(cmds)
        
        try:
            serverResponse = Source.sendRequest(req)
        except:
            logException("Error getting inventory.")
            return None
           
        for response in serverResponse.getResponses():
            for entry in response.getEntries():
                if not entry.getProtectedFile():
                    filePath = entry.getFileName()
                    filename = os.path.split(filePath)[1]
                    shortName = os.path.splitext(filename)[0]
                    record = textInventoryRecord(filePath, entry.getContext(), entry.getProtectedFile())
                    inventory[shortName] = record
    
    return inventory