Skip to content

Commit

Permalink
REBASE_BEFORE_MERGE: Incorporate calculate_deb_checksums() suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
quba42 committed Nov 15, 2018
1 parent f3158f4 commit d13f5a4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions plugins/pulp_deb/plugins/distributors/metadata_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def write_release_file(path, meta_data, release_meta_files):

# Add the checksum fields to the deb822 object:
for file_path in release_meta_files:
checksums = calculate_checksums(file_path)
checksums = calculate_deb_checksums(file_path)
file_size = os.path.getsize(file_path)
relative_path = os.path.relpath(file_path, path)
for checksum_type in checksum_fields:
Expand All @@ -164,24 +164,25 @@ def write_release_file(path, meta_data, release_meta_files):
return output_file_path


def calculate_checksums(input_file_path):
def calculate_deb_checksums(input_file_path):
"""
Uses util.calculate_checksums() to calculate the md5sum, sha1, and sha256
of a file. The return dict uses the keys 'md5sum', 'sha1', and 'sha256'.
of a file. The return dict is guaranteed to use the deb style keys
'md5sum', 'sha1', and 'sha256'.
:param file_path: the path to the file for which checksums are needed
:returns: a dict containing the checksums
"""
CHECKSUM_TYPES = [util.TYPE_MD5, util.TYPE_SHA1, util.TYPE_SHA256]
CHECKSUM_TYPES = {
'md5sum': util.TYPE_MD5,
'sha1': util.TYPE_SHA1,
'sha256': util.TYPE_SHA256,
}

with open(input_file_path) as input_file:
checksums = util.calculate_checksums(input_file, CHECKSUM_TYPES)
checksums = util.calculate_checksums(input_file, CHECKSUM_TYPES.values())

checksums['md5sum'] = checksums.pop(util.TYPE_MD5)
checksums['sha1'] = checksums.pop(util.TYPE_SHA1)
checksums['sha256'] = checksums.pop(util.TYPE_SHA256)

return checksums
return {deb_key: checksums[util_key] for deb_key, util_key in CHECKSUM_TYPES.items()}


def gzip_compress_file(input_file_path):
Expand Down

0 comments on commit d13f5a4

Please sign in to comment.