本文整理汇总了Python中pulp.plugins.util.verification.sanitize_checksum_type函数的典型用法代码示例。如果您正苦于以下问题:Python sanitize_checksum_type函数的具体用法?Python sanitize_checksum_type怎么用?Python sanitize_checksum_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_checksum_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rpm_search_dicts
def rpm_search_dicts(self):
ret = []
for collection in self.pkglist:
for package in collection.get("packages", []):
if len(package.get("sum") or []) == 2:
checksum = package["sum"][1]
checksumtype = verification.sanitize_checksum_type(package["sum"][0])
elif "sums" in package and "type" in package:
# these are the field names we get from an erratum upload.
# I have no idea why they are different.
checksum = package["sums"]
checksumtype = verification.sanitize_checksum_type(package["type"])
else:
checksum = None
checksumtype = None
rpm = RPM(
name=package["name"],
epoch=package["epoch"],
version=package["version"],
release=package["release"],
arch=package["arch"],
checksum=checksum,
checksumtype=checksumtype,
)
unit_key = rpm.unit_key
for key in ["checksum", "checksumtype"]:
if unit_key[key] is None:
del unit_key[key]
ret.append(unit_key)
return ret
示例2: rpm_search_dicts
def rpm_search_dicts(self):
ret = []
for collection in self.pkglist:
for package in collection.get('packages', []):
if len(package.get('sum') or []) == 2:
checksum = package['sum'][1]
checksumtype = verification.sanitize_checksum_type(package['sum'][0])
elif 'sums' in package and 'type' in package:
# these are the field names we get from an erratum upload.
# I have no idea why they are different.
checksum = package['sums']
checksumtype = verification.sanitize_checksum_type(package['type'])
else:
checksum = None
checksumtype = None
rpm = RPM(name=package['name'], epoch=package['epoch'],
version=package['version'], release=package['release'],
arch=package['arch'], checksum=checksum,
checksumtype=checksumtype)
unit_key = rpm.unit_key
for key in ['checksum', 'checksumtype']:
if unit_key[key] is None:
del unit_key[key]
ret.append(unit_key)
return ret
示例3: process_repomd_data_element
def process_repomd_data_element(data_element):
"""
Process the data elements of the repomd.xml file.
This returns a file information dictionary with the following keys:
* `name`: name of the element
* `relative_path`: the path of the metadata file, relative to the repository URL
* `checksum`: dictionary of `algorithm` and `hex_digest` keys and values
* `size`: size of the metadata file, in bytes
* `timestamp`: unix timestamp of the file's creation, as a float
* `open_checksum`: optional checksum dictionary of uncompressed metadata file
* `open_size`: optional size of the uncompressed metadata file, in bytes
:param data_element: XML data element parsed from the repomd.xml file
:return: file_info dictionary
:rtype: dict
"""
file_info = deepcopy(FILE_INFO_SKEL)
file_info['name'] = data_element.attrib['type']
location_element = data_element.find(LOCATION_TAG)
if location_element is not None:
file_info['relative_path'] = location_element.attrib['href']
checksum_element = data_element.find(CHECKSUM_TAG)
if checksum_element is not None:
checksum_type = verification.sanitize_checksum_type(checksum_element.attrib['type'])
file_info['checksum']['algorithm'] = checksum_type
file_info['checksum']['hex_digest'] = checksum_element.text
size_element = data_element.find(SIZE_TAG)
if size_element is not None:
file_info['size'] = int(size_element.text)
timestamp_element = data_element.find(TIMESTAMP_TAG)
if timestamp_element is not None:
file_info['timestamp'] = float(timestamp_element.text)
open_checksum_element = data_element.find(OPEN_CHECKSUM_TAG)
if open_checksum_element is not None:
checksum_type = verification.sanitize_checksum_type(open_checksum_element.attrib['type'])
file_info['open_checksum']['algorithm'] = checksum_type
file_info['open_checksum']['hex_digest'] = open_checksum_element.text
open_size_element = data_element.find(OPEN_SIZE_TAG)
if open_size_element is not None:
file_info['open_size'] = int(open_size_element.text)
for child in data_element.getchildren():
child.clear()
data_element.clear()
return file_info
示例4: validate
def validate(self, value):
"""
Validates that value is a checksumtype known to pulp platform
:param value: The value to validate
:type value: basestring
:return: None
"""
super(ChecksumTypeStringField, self).validate(value)
verification.sanitize_checksum_type(value)
示例5: import_unknown_metadata_files
def import_unknown_metadata_files(self, metadata_files):
"""
Import metadata files whose type is not known to us. These are any files
that we are not already parsing.
:param metadata_files: object containing access to all metadata files
:type metadata_files: pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
"""
for metadata_type, file_info in metadata_files.metadata.iteritems():
if metadata_type not in metadata_files.KNOWN_TYPES:
checksum_type = file_info['checksum']['algorithm']
checksum_type = verification.sanitize_checksum_type(checksum_type)
unit_metadata = {
'checksum': file_info['checksum']['hex_digest'],
'checksum_type': checksum_type,
}
model = models.YumMetadataFile(metadata_type,
self.sync_conduit.repo_id,
unit_metadata)
relative_path = os.path.join(model.relative_dir,
os.path.basename(file_info['local_path']))
unit = self.sync_conduit.init_unit(models.YumMetadataFile.TYPE, model.unit_key,
model.metadata, relative_path)
shutil.copyfile(file_info['local_path'], unit.storage_path)
self.sync_conduit.save_unit(unit)
示例6: process_download_reports
def process_download_reports(self, reports):
"""
Once downloading is complete, add information about each file to this
model instance. This is required before saving the new unit.
:param reports: list of successful download reports
:type reports: list(pulp.common.download.report.DownloadReport)
"""
# TODO: maybe this shouldn't be in common
metadata_files = self.metadata.setdefault('files', [])
for report in reports:
# the following data model is mostly intended to match what the
# previous importer generated.
metadata_files.append({
'checksum': report.data['checksum'],
'checksumtype': verification.sanitize_checksum_type(report.data['checksumtype']),
'downloadurl': report.url,
'filename': os.path.basename(report.data['relativepath']),
'fileName': os.path.basename(report.data['relativepath']),
'item_type': self.TYPE,
'pkgpath': os.path.join(
constants.DISTRIBUTION_STORAGE_PATH,
self.id,
os.path.dirname(report.data['relativepath']),
),
'relativepath': report.data['relativepath'],
'savepath': report.destination,
'size': report.total_bytes,
})
示例7: process_package_element
def process_package_element(element):
"""
Process one XML block from prestodelta.xml and return a models.DRPM instance
:param element: object representing one "DRPM" block from the XML file
:type element: xml.etree.ElementTree.Element
:return: models.DRPM instance for the XML block
:rtype: pulp_rpm.plugins.db.models.DRPM
"""
delta = element.find("delta")
filename = delta.find("filename")
sequence = delta.find("sequence")
size = delta.find("size")
checksum = delta.find("checksum")
checksum_type = verification.sanitize_checksum_type(checksum.attrib["type"])
return models.DRPM.from_package_info(
{
"type": "drpm",
"new_package": element.attrib["name"],
"epoch": element.attrib["epoch"],
"version": element.attrib["version"],
"release": element.attrib["release"],
"arch": element.attrib["arch"],
"oldepoch": delta.attrib["oldepoch"],
"oldversion": delta.attrib["oldversion"],
"oldrelease": delta.attrib["oldrelease"],
"filename": filename.text,
"sequence": sequence.text,
"size": int(size.text),
"checksum": checksum.text,
"checksumtype": checksum_type,
}
)
示例8: process_package_element
def process_package_element(element):
"""
Process one XML block from prestodelta.xml and return a models.DRPM instance
:param element: object representing one "DRPM" block from the XML file
:type element: xml.etree.ElementTree.Element
:return: models.DRPM instance for the XML block
:rtype: pulp_rpm.plugins.db.models.DRPM
"""
delta = element.find('delta')
filename = delta.find('filename')
sequence = delta.find('sequence')
size = delta.find('size')
checksum = delta.find('checksum')
checksum_type = verification.sanitize_checksum_type(checksum.attrib['type'])
return models.DRPM.from_package_info({
'type': 'drpm',
'new_package': element.attrib['name'],
'epoch': element.attrib['epoch'],
'version': element.attrib['version'],
'release': element.attrib['release'],
'arch': element.attrib['arch'],
'oldepoch': delta.attrib['oldepoch'],
'oldversion': delta.attrib['oldversion'],
'oldrelease': delta.attrib['oldrelease'],
'filename': filename.text,
'sequence': sequence.text,
'size': int(size.text),
'checksum': checksum.text,
'checksumtype': checksum_type,
})
示例9: import_unknown_metadata_files
def import_unknown_metadata_files(self, metadata_files):
"""
Import metadata files whose type is not known to us. These are any files
that we are not already parsing.
:param metadata_files: object containing access to all metadata files
:type metadata_files: pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
"""
for metadata_type, file_info in metadata_files.metadata.iteritems():
if metadata_type not in metadata_files.KNOWN_TYPES:
file_path = file_info['local_path']
checksum_type = file_info['checksum']['algorithm']
checksum_type = verification.sanitize_checksum_type(checksum_type)
checksum = file_info['checksum']['hex_digest']
# Find an existing model
model = models.YumMetadataFile.objects.filter(
data_type=metadata_type,
repo_id=self.repo.repo_id).first()
# If an existing model, use that
if model:
model.checksum = checksum
model.checksum_type = checksum_type
else:
# Else, create a new mode
model = models.YumMetadataFile(
data_type=metadata_type,
repo_id=self.repo.repo_id,
checksum=checksum,
checksum_type=checksum_type)
model.set_storage_path(os.path.basename(file_path))
model.save_and_import_content(file_path)
# associate/re-associate model to the repo
repo_controller.associate_single_unit(self.repo, model)
示例10: test_nothing_necessary
def test_nothing_necessary(self):
"""
Assert that the method doesn't change the checksum_type when it's not needed.
"""
checksum_type = verification.sanitize_checksum_type('sha512')
self.assertEqual(checksum_type, 'sha512')
示例11: test_none
def test_none(self):
"""
Assert correct behavior when the checksum_type is None.
"""
checksum_type = verification.sanitize_checksum_type(None)
self.assertEqual(checksum_type, None)
示例12: test_SHA256_to_sha256
def test_SHA256_to_sha256(self):
"""
Assert that "SHA256" is converted to "sha256".
"""
checksum_type = verification.sanitize_checksum_type('SHA256')
self.assertEqual(checksum_type, 'sha256')
示例13: process_package_element
def process_package_element(element):
"""
Process one XML block from prestodelta.xml and return a models.DRPM instance
:param element: object representing one "DRPM" block from the XML file
:type element: xml.etree.ElementTree.Element
:return: models.DRPM instance for the XML block
:rtype: pulp_rpm.plugins.db.models.DRPM
"""
delta = element.find('delta')
filename = delta.find('filename')
sequence = delta.find('sequence')
size = delta.find('size')
checksum = delta.find('checksum')
checksum_type = verification.sanitize_checksum_type(checksum.attrib['type'])
return models.DRPM(
new_package=element.attrib['name'],
epoch=element.attrib['epoch'],
version=element.attrib['version'],
release=element.attrib['release'],
arch=element.attrib['arch'],
oldepoch=delta.attrib['oldepoch'],
oldversion=delta.attrib['oldversion'],
oldrelease=delta.attrib['oldrelease'],
filename=filename.text,
sequence=sequence.text,
size=int(size.text),
checksum=checksum.text,
checksumtype=checksum_type)
示例14: test_ShA_to_sha1
def test_ShA_to_sha1(self):
"""
Assert that "ShA" is converted to "sha1".
"""
checksum_type = verification.sanitize_checksum_type('ShA')
self.assertEqual(checksum_type, 'sha1')
示例15: process_download_reports
def process_download_reports(self, reports):
"""
Once downloading is complete, add information about each file to this
model instance. This is required before saving the new unit.
:param reports: list of successful download reports
:type reports: list(pulp.common.download.report.DownloadReport)
"""
if not isinstance(self.files, list):
self.files = []
for report in reports:
# the following data model is mostly intended to match what the
# previous importer generated.
self.files.append({
'checksum': report.data['checksum'],
'checksumtype': verification.sanitize_checksum_type(report.data['checksumtype']),
'downloadurl': report.url,
'filename': os.path.basename(report.data['relativepath']),
'fileName': os.path.basename(report.data['relativepath']),
'item_type': "distribution",
'pkgpath': os.path.join(
self._storage_path, os.path.dirname(report.data['relativepath']),
),
'relativepath': report.data['relativepath'],
'savepath': report.destination,
'size': report.total_bytes,
})