示例#1
0
文件: srmetadata.py 项目: ESDS/sm
    def getVdiInfo(self, Dict, generateSector = 0):
        util.SMlog("Entering VDI info")
        try:
            vdi_info = ''
            # HP split into 2 functions, 1 for generating the first 2 sectors,
            # which will be called by all classes
            # and one specific to this class
            if generateSector == 1 or generateSector == 0:
                Dict[NAME_LABEL_TAG] = \
                        xml.sax.saxutils.escape(Dict[NAME_LABEL_TAG])
                Dict[NAME_DESCRIPTION_TAG] = \
                        xml.sax.saxutils.escape(Dict[NAME_DESCRIPTION_TAG])
                if len(Dict[NAME_LABEL_TAG]) + len(Dict[NAME_DESCRIPTION_TAG]) > \
                    MAX_VDI_NAME_LABEL_DESC_LENGTH:
                    if len(Dict[NAME_LABEL_TAG]) > MAX_VDI_NAME_LABEL_DESC_LENGTH/2:
                        length = util.unictrunc(Dict[NAME_LABEL_TAG], \
                                MAX_VDI_NAME_LABEL_DESC_LENGTH/2)

                        util.SMlog('warning: name-label truncated from ' \
                                + str(len(Dict[NAME_LABEL_TAG])) + ' to ' \
                                + str(length) + ' bytes')

                        Dict[NAME_LABEL_TAG] = Dict[NAME_LABEL_TAG][:length]
                   
                    if len(Dict[NAME_DESCRIPTION_TAG]) > \
                        MAX_VDI_NAME_LABEL_DESC_LENGTH/2: \

                        length = util.unictrunc(Dict[NAME_DESCRIPTION_TAG], \
                                MAX_VDI_NAME_LABEL_DESC_LENGTH/2)

                        util.SMlog('warning: description truncated from ' \
                            + str(len(Dict[NAME_DESCRIPTION_TAG])) + \
                            ' to ' + str(length) + ' bytes')

                        Dict[NAME_DESCRIPTION_TAG] = \
                                Dict[NAME_DESCRIPTION_TAG][:length]
                       
                # Fill the open struct and write it
                vdi_info += getSector(VDI_SECTOR_1 % (Dict[NAME_LABEL_TAG], 
                                                      Dict[NAME_DESCRIPTION_TAG]))
           
            if generateSector == 2 or generateSector == 0:
                sector2 = ''
                
                if not Dict.has_key(VDI_DELETED_TAG):
                    Dict.update({VDI_DELETED_TAG:'0'})
                
                for tag in Dict.keys():
                    if tag == NAME_LABEL_TAG or tag == NAME_DESCRIPTION_TAG:
                        continue
                    sector2 += getXMLTag(tag) % Dict[tag]
                    
                sector2 += VDI_CLOSING_TAG
                vdi_info += getSector(sector2)
            return vdi_info
       
        except Exception, e:
            util.SMlog("Exception generating vdi info: %s. Error: %s" % \
                       (Dict, str(e)))
            raise
示例#2
0
    def getVdiInfo(self, Dict, generateSector = 0):
        util.SMlog("Entering VDI info")
        try:
            vdi_info = ''
            # HP split into 2 functions, 1 for generating the first 2 sectors,
            # which will be called by all classes
            # and one specific to this class
            if generateSector == 1 or generateSector == 0:
                Dict[NAME_LABEL_TAG] = \
                        xml.sax.saxutils.escape(Dict[NAME_LABEL_TAG])
                Dict[NAME_DESCRIPTION_TAG] = \
                        xml.sax.saxutils.escape(Dict[NAME_DESCRIPTION_TAG])
                if len(Dict[NAME_LABEL_TAG]) + len(Dict[NAME_DESCRIPTION_TAG]) > \
                    MAX_VDI_NAME_LABEL_DESC_LENGTH:
                    if len(Dict[NAME_LABEL_TAG]) > MAX_VDI_NAME_LABEL_DESC_LENGTH/2:
                        length = util.unictrunc(Dict[NAME_LABEL_TAG], \
                                MAX_VDI_NAME_LABEL_DESC_LENGTH/2)

                        util.SMlog('warning: name-label truncated from ' \
                                + str(len(Dict[NAME_LABEL_TAG])) + ' to ' \
                                + str(length) + ' bytes')

                        Dict[NAME_LABEL_TAG] = Dict[NAME_LABEL_TAG][:length]
                   
                    if len(Dict[NAME_DESCRIPTION_TAG]) > \
                        MAX_VDI_NAME_LABEL_DESC_LENGTH/2: \

                        length = util.unictrunc(Dict[NAME_DESCRIPTION_TAG], \
                                MAX_VDI_NAME_LABEL_DESC_LENGTH/2)

                        util.SMlog('warning: description truncated from ' \
                            + str(len(Dict[NAME_DESCRIPTION_TAG])) + \
                            ' to ' + str(length) + ' bytes')

                        Dict[NAME_DESCRIPTION_TAG] = \
                                Dict[NAME_DESCRIPTION_TAG][:length]
                       
                # Fill the open struct and write it
                vdi_info += getSector(VDI_SECTOR_1 % (Dict[NAME_LABEL_TAG], 
                                                      Dict[NAME_DESCRIPTION_TAG]))
           
            if generateSector == 2 or generateSector == 0:
                sector2 = ''
                
                if VDI_DELETED_TAG not in Dict:
                    Dict.update({VDI_DELETED_TAG:'0'})
                
                for tag in Dict.keys():
                    if tag == NAME_LABEL_TAG or tag == NAME_DESCRIPTION_TAG:
                        continue
                    sector2 += getXMLTag(tag) % Dict[tag]
                    
                sector2 += VDI_CLOSING_TAG
                vdi_info += getSector(sector2)
            return vdi_info
       
        except Exception as e:
            util.SMlog("Exception generating vdi info: %s. Error: %s" % \
                       (Dict, str(e)))
            raise
示例#3
0
文件: srmetadata.py 项目: euanh/sm
def getSectorAlignedXML(tagName, value):
    # truncate data if we breach the 512 limit
    if len("<%s>%s</%s>" % (tagName, value, tagName)) > SECTOR_SIZE:
        length = util.unictrunc(value, SECTOR_SIZE - 2 * len(tagName) - 5)
        util.SMlog('warning: SR ' + tagName + ' truncated from ' \
                + str(len(value)) + ' to ' + str(length) + ' bytes')
        value = value[:length]

    return "<%s>%s</%s>" % (tagName, value, tagName)
示例#4
0
文件: srmetadata.py 项目: ESDS/sm
def getSectorAlignedXML(tagName, value):
    # truncate data if we breach the 512 limit
    if len("<%s>%s</%s>" % (tagName, value, tagName)) > SECTOR_SIZE:
        length = util.unictrunc(value, SECTOR_SIZE - 2*len(tagName) - 5)
        util.SMlog('warning: SR ' + tagName + ' truncated from ' \
                + str(len(value)) + ' to ' + str(length) + ' bytes')
        value = value[:length]
        
    return "<%s>%s</%s>" % (tagName, value, tagName)