Exemplo n.º 1
0
 def __init__(self, customConfig='ProbeConfig'):
     if os.path.exists(customConfig):
         self.__configname = customConfig
     else:
         DebugPrint(
             0, "Error: configuration file %s doesn't exist" %
             (customConfig, ))
         raise utils.InternalError(
             "Error: configuration file %s doesn't exist" %
             (customConfig, ))
Exemplo n.º 2
0
    def __init__(self):

        # See the function ResourceType for details on the
        # parameter
        if not config.Config:
            DebugPrint(0, "Error: Configuration is not initialized")
            raise utils.InternalError("Configuration is not initialized")

        DebugPrint(2, 'Creating a Record ' + utils.TimeToString())
        self.XmlData = []
        self.__ProbeName = Config.get_ProbeName()
        self.__ProbeNameDescription = r''
        self.__SiteName = Config.get_SiteName()
        self.__SiteNameDescription = r''
        self.__Grid = Config.get_Grid()
        self.__GridDescription = r''
        self.RecordData = []
        self.TransientInputFiles = []
        self.__VOOverrid = Config.get_VOOverride()
def __ResourceTool__(
    action,
    xmlDoc,
    usageRecord,
    namespace,
    prefix,
    key,
    value=r'',
):
    '''Private routine sitting underneath (possibly) several public ones'''

    if value == None:
        value = r''

    if action != 'UpdateFirst' and action != 'ReadValues' and action != 'ReadFirst' and action \
        != 'AddIfMissingValue' and action != 'AddIfMissingKey' and action != 'UnconditionalAdd':
        raise utils.InternalError(
            "__ResourceTool__ gets unrecognized action '%s'" % action)

    resourceNodes = usageRecord.getElementsByTagNameNS(namespace, 'Resource')
    wantedResource = None
    foundValues = []

    # Look for existing resource of desired type

    for resource in resourceNodes:
        description = resource.getAttributeNS(namespace, 'description')
        if description == key:
            if action == 'UpdateFirst':
                wantedResource = resource
                break
            elif action == 'AddIfMissingValue':

                # Kick out if we have the attribute and value

                if resource.firstChild and resource.firstChild.data == value:
                    return None
            elif action == 'AddIfMissingKey':

                # Kick out, since we're not missing the key

                return None
            elif action == 'ReadFirst' and resource.firstChild:
                return resource.firstChild.data
            elif action == 'ReadValues' and resource.firstChild:
                foundValues.append(resource.firstChild.data)

    if action == 'ReadValues' or action == 'ReadFirst':
        return foundValues  # Done, no updating necessary

    # Found

    if wantedResource:  # UpdateFirst
        if wantedResource.firstChild:  # Return replaced value
            oldValue = wantedResource.firstChild.data
            wantedResource.firstChild.data = value
            return oldValue
        else:

            # No text data node

            textNode = xmlDoc.createTextNode(value)
            wantedResource.appendChild(textNode)
    else:

        # AddIfMissing{Key,Value}, UpdateFirst and UnconditionalAdd
        # should all drop through to here.
        # Create Resource node

        wantedResource = xmlDoc.createElementNS(namespace, prefix + 'Resource')
        wantedResource.setAttribute(prefix + 'description', key)
        textNode = xmlDoc.createTextNode(value)
        wantedResource.appendChild(textNode)
        usageRecord.appendChild(wantedResource)

    return None