def unpackFromDomNode(self, fileListNode): """ Unpack a File List from a DOM File List Node object. fileListNode: DOM File List Node object (Node). Returns: Reference to object itself. """ self.setId(getAttribValue(fileListNode, "Id")) self.setComment(getAttribValue(fileListNode, "Comment", 1)) self.setStatus(getAttribValue(fileListNode, "Status", 1)) # Unpack the File Status Elements. fileStatusNodes = ngamsGetChildNodes(fileListNode, "FileStatus") for fileStatusNode in fileStatusNodes: fileStatusObj = ngamsFileInfo.ngamsFileInfo() self.addFileInfoObj(fileStatusObj) fileStatusObj.unpackFromDomNode(fileStatusNode) # Unpack File List Elements. fileListNodes = ngamsGetChildNodes(fileListNode, "FileList") for fileListNode in fileListNodes: fileListObj = ngamsFileList() self.addFileListObj(fileListObj) fileListObj.unpackFromDomNode(fileListNode) return self
def unpackFromDomNode(self, diskNode, ignoreVarDiskPars=0): """ Unpack the disk information contained in a DOM DiskStatus Node and set the members of the object accordingly. diskNode: DOM Disk Node (Node). ignoreVarDiskPars: Ignore the variable part of the disk status: Host ID, Slot ID, Mounted, Mount Point (integer/0|1). Returns: Reference to object itself. """ T = TRACE() self.setDiskId(getAttribValue(diskNode, "DiskId")) self.setArchive(getAttribValue(diskNode, "Archive")) instDate = getAttribValue(diskNode, "InstallationDate") if instDate: self.setInstallationDate(fromiso8601(instDate)) self.setType(getAttribValue(diskNode, "Type")) self.setManufacturer(getAttribValue(diskNode, "Manufacturer", 1)) self.setLogicalName(getAttribValue(diskNode, "LogicalName")) # These attributes are not contained in certain Status XML # Documents, e.g. in the NgasDiskInfo files. if (not ignoreVarDiskPars): self.setHostId(getAttribValue(diskNode, "HostId")) self.setSlotId(getAttribValue(diskNode, "SlotId")) self.setMounted(getAttribValue(diskNode, "Mounted")) self.setMountPoint(getAttribValue(diskNode, "MountPoint")) self.setNumberOfFiles(getAttribValue(diskNode, "NumberOfFiles")) self.setAvailableMb(getAttribValue(diskNode, "AvailableMb")) self.setBytesStored(getAttribValue(diskNode, "BytesStored")) self.setCompleted(getAttribValue(diskNode, "Completed")) compDate = getAttribValue(diskNode, "CompletionDate", 1) if compDate: self.setCompletionDate(fromiso8601(compDate)) self.setChecksum(getAttribValue(diskNode, "Checksum")) write_time = getAttribValue(diskNode, "TotalDiskWriteTime") if write_time: self.setTotalDiskWriteTime(float(write_time)) # Handle files. fileNodes = diskNode.getElementsByTagName("FileStatus") for fileNode in fileNodes: fileInfo = ngamsFileInfo.ngamsFileInfo().\ unpackFromDomNode(fileNode, self.getDiskId()) self.addFileObj(fileInfo) return self
def unpackXmlDoc(self, doc, getStatus=0, ignoreVarDiskPars=0): """ Unpack a status report stored in an XML document and set the members of the class accordingly. doc: Status report as XML document (string). getStatus: Extract also the status information from the XML document (0|1/integer). ignoreVarDiskPars: Ignore the variable part of the disk status: Host ID, Slot ID, Mounted, Mount Point (integer/0|1). Returns: Reference to object itself. """ dom = xml.dom.minidom.parseString(doc) ngamsStatusEl = ngamsGetChildNodes(dom, NGAMS_XML_STATUS_ROOT_EL)[0] # Get the information from the Status Element. nodeList = dom.getElementsByTagName("Status") self.setDate(getAttribValue(nodeList[0], "Date")) self.setVersion(getAttribValue(nodeList[0], "Version")) self.setHostId(getAttribValue(nodeList[0], "HostId")) if (getStatus): self.setStatus(getAttribValue(nodeList[0], "Status")) self.setMessage(getAttribValue(nodeList[0], "Message")) if (getStatus): self.setState(getAttribValue(nodeList[0], "State")) self.setSubState(getAttribValue(nodeList[0], "SubState")) # Get the optional request handling status. requestId = getAttribValue(nodeList[0], "RequestId", 1) if (requestId): self.setRequestId(requestId) requestTime = getAttribValue(nodeList[0], "RequestTime", 1) if (requestTime): self.setRequestTime(fromiso8601(requestTime)) completionPercent = getAttribValue(nodeList[0], "CompletionPercent", 1) if (completionPercent): self.setCompletionPercent(completionPercent) expectedCount = getAttribValue(nodeList[0], "ExpectedCount", 1) if (expectedCount): self.setExpectedCount(expectedCount) actualCount = getAttribValue(nodeList[0], "ActualCount", 1) if (actualCount): self.setActualCount(actualCount) estTotalTime = getAttribValue(nodeList[0], "EstTotalTime", 1) if (estTotalTime): self.setEstTotalTime(float(estTotalTime)) remainingTime = getAttribValue(nodeList[0], "RemainingTime", 1) if (remainingTime): self.setRemainingTime(float(remainingTime)) lastRequestStatUpdate = getAttribValue(nodeList[0], "LastRequestStatUpdate", 1) if (lastRequestStatUpdate): self.setLastRequestStatUpdate(fromiso8601(lastRequestStatUpdate)) completionTime = getAttribValue(nodeList[0], "CompletionTime", 1) if (completionTime): self.setCompletionTime(fromiso8601(completionTime)) # Unpack the NG/AMS Configuration information. ngamsCfgRootNode = dom.getElementsByTagName("NgamsCfg") if (len(ngamsCfgRootNode) > 0): tolerant = 1 self.__ngamsCfg.unpackFromRootNode(ngamsCfgRootNode[0], tolerant) # Unpack Disk Status Elements and File Status Elements. diskNodes = dom.getElementsByTagName("DiskStatus") for diskNode in diskNodes: diskInfo = ngamsDiskInfo.ngamsDiskInfo().\ unpackFromDomNode(diskNode, ignoreVarDiskPars) self.addDiskStatus(diskInfo) # Unpack File Lists. fileListNodes = dom.getElementsByTagName("FileList") for fileListNode in fileListNodes: fileListObj = ngamsFileList.ngamsFileList() self.addFileList(fileListObj) fileListObj.unpackFromDomNode(fileListNode) # Unpack Containers. Loop over the root containers, # then let them deal with their own recursion rootContainerEls = [node for node in ngamsStatusEl.childNodes \ if node.nodeType == xml.dom.minidom.Node.ELEMENT_NODE\ and node.tagName == 'Container'] for rootContainerEl in rootContainerEls: container = ngamsContainer.ngamsContainer() container.unpackFromDomNode(rootContainerEl) self.addContainer(container) dom.unlink() return self
def unpackFromDomNode(self, fileNode, diskId=None): """ Unpack the file information contained in a DOM FileStatus Node and set the members of the object accordingly. fileNode: DOM File Node object (DOM object). diskId: Disk ID for disk where file is stored (string). Returns: Reference to object itself. """ if (diskId != None): self.setDiskId(diskId) else: self.setDiskId(getAttribValue(fileNode, "DiskId", 1)) uncomprSize = getAttribValue(fileNode, "UncompressedFileSize", 1) checksumPi = getAttribValue(fileNode, "ChecksumPlugIn", 1) self.\ setChecksum(getAttribValue(fileNode, "Checksum", 1)).\ setChecksumPlugIn(checksumPi).\ setCompression(getAttribValue(fileNode, "Compression", 1)).\ setFileId(getAttribValue(fileNode, "FileId", 1)).\ setFilename(getAttribValue(fileNode, "FileName", 1)).\ setUncompressedFileSize(uncomprSize).\ setFileSize(getAttribValue(fileNode, "FileSize", 1)).\ setFileStatus(getAttribValue(fileNode, "FileStatus", 1)).\ setFileVersion(getAttribValue(fileNode, "FileVersion", 1)).\ setFormat(getAttribValue(fileNode, "Format", 1)).\ setGroup(getAttribValue(fileNode, "Group", 1)).\ setIgnore(getAttribValue(fileNode, "Ignore", 1)).\ setOwner(getAttribValue(fileNode, "Owner", 1)).\ setPermissions(getAttribValue(fileNode, "Permissions", 1)).\ setTag(getAttribValue(fileNode, "Tag", 1)).\ setIoTime(getAttribValue(fileNode, "TotalIoTime", 1)).\ setIngestionRate(getAttribValue(fileNode, "IngestionRate", 1)).\ setContainerId(getAttribValue(fileNode, "ContainerId", 1)) creation_date = getAttribValue(fileNode, "CreationDate", 1) if creation_date: self.setCreationDate(fromiso8601(creation_date)) ingestion_date = getAttribValue(fileNode, "IngestionDate", 1) if ingestion_date: self.setIngestionDate(fromiso8601(ingestion_date)) mod_date = getAttribValue(fileNode, "ModificationDate", 1) if mod_date: self.setModDate(fromiso8601(mod_date)) acc_date = getAttribValue(fileNode, "ModificationDate", 1) if acc_date: self.setAccDate(fromiso8601(acc_date)) return self