Project

Profile

Help

Issue #3370 » debpkgr.patch

mihai.ibanescu@gmail.com, 07/10/2018 09:59 PM

View differences:

debpkgr/debpkg.py
from __future__ import unicode_literals
import logging
import six
import sys
import inspect
......
return 'DebPkgMD5sums(%s)' % self
def __str__(self):
results = u""
keys = sorted([x for x in self.keys()])
for k in keys:
results += u"{0} {1}\n".format(k, self.get(k))
# for k, v in self.items():
# results += u"%s %s\n" % (k, v)
return results
encoding = DebPkg.ENCODINGS[0]
if six.PY3:
return self.dump(encoding=encoding)
return self.dump(encoding=encoding).encode(encoding)
class DebPkgRequires(object):
......
"""Represent a binary debian package"""
__slots__ = ("_c", "_h", "_md5", "_deps", "_version", "_scripts")
ENCODINGS = ["utf-8", "iso-8859-1"]
def __init__(self, control, hashes, md5sums, scripts={}):
if isinstance(control, dict):
......
using keyword arguments.
"""
debpkg = debfile.DebFile(filename=path)
# existance of md5sums in control part is optional
try:
md5sums = debpkg.md5sums(encoding='utf-8')
except debfile.DebError as err:
log.warn('While processing %s: %s', path, err.args[0])
md5sums = None
md5sums = cls.read_md5sums(debpkg, path)
control = debpkg.control.debcontrol().copy()
scripts = debpkg.control.scripts()
hashes = cls.make_hashes(path)
control.update(kwargs)
return cls(control, hashes, md5sums, scripts=scripts)
@classmethod
def read_md5sums(cls, pkg, path):
for encoding in cls.ENCODINGS:
try:
return DebPkgMD5sums(pkg.md5sums(encoding=encoding),
encoding=encoding)
except UnicodeDecodeError:
continue
except debfile.DebError as err:
log.warn('While processing %s: %s', path, err.args[0])
return None
# Re-raise last exception if we ran out of encodings to try
raise
def dump(self, path):
return self.package.dump(path)
tests/unit/pkg_test.py
self.files_data = sorted([x for x in self.hashes_data.keys()])
self.md5sum_string = 'MD5sum 5fc5c0cb24690e78d6c6a2e13753f1aa\n'\
'SHA1 5e26ae3ebf9f7176bb7fd01c9e802ac8e223cdcc\n'\
'SHA256 d80568c932f54997713bb7832c6da6aa04992919'\
'f3d0f47afb6ba600a7586780\n'
self.md5sum_string = '''\
MD5sum: 5fc5c0cb24690e78d6c6a2e13753f1aa
SHA256: d80568c932f54997713bb7832c6da6aa04992919f3d0f47afb6ba600a7586780
SHA1: 5e26ae3ebf9f7176bb7fd01c9e802ac8e223cdcc
'''
self.files_string = 'usr/share/doc/foo/README.Debian\n'\
'usr/share/doc/foo/changelog.Debian.gz\n'\
(5-5/5)