mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-08 07:21:30 +00:00
archive: update pull_dsc to use _source_urls() and verify_file_checksum()
This commit is contained in:
parent
20dd65b281
commit
8682c44957
@ -31,7 +31,6 @@ from urllib.error import (URLError, HTTPError)
|
|||||||
from urllib.parse import (quote, urlparse)
|
from urllib.parse import (quote, urlparse)
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
import codecs
|
import codecs
|
||||||
import hashlib
|
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
@ -82,21 +81,11 @@ class Dsc(debian.deb822.Dsc):
|
|||||||
|
|
||||||
def verify_file(self, pathname):
|
def verify_file(self, pathname):
|
||||||
"Verify that pathname matches the checksums in the dsc"
|
"Verify that pathname matches the checksums in the dsc"
|
||||||
if os.path.isfile(pathname):
|
if not os.path.isfile(pathname):
|
||||||
|
return False
|
||||||
alg, checksums = self.get_strongest_checksum()
|
alg, checksums = self.get_strongest_checksum()
|
||||||
size, digest = checksums[os.path.basename(pathname)]
|
size, digest = checksums[os.path.basename(pathname)]
|
||||||
if os.path.getsize(pathname) != size:
|
return verify_file_checksum(pathname, alg, digest, size)
|
||||||
return False
|
|
||||||
hash_func = getattr(hashlib, alg)()
|
|
||||||
f = open(pathname, 'rb')
|
|
||||||
while True:
|
|
||||||
buf = f.read(hash_func.block_size)
|
|
||||||
if buf == b'':
|
|
||||||
break
|
|
||||||
hash_func.update(buf)
|
|
||||||
f.close()
|
|
||||||
return hash_func.hexdigest() == digest
|
|
||||||
return False
|
|
||||||
|
|
||||||
def compare_dsc(self, other):
|
def compare_dsc(self, other):
|
||||||
"""Check whether any files in these two dscs that have the same name
|
"""Check whether any files in these two dscs that have the same name
|
||||||
@ -343,11 +332,17 @@ class SourcePackage(object):
|
|||||||
if parsed.scheme == '':
|
if parsed.scheme == '':
|
||||||
self._dsc_source = 'file://' + os.path.abspath(self._dsc_source)
|
self._dsc_source = 'file://' + os.path.abspath(self._dsc_source)
|
||||||
parsed = urlparse(self._dsc_source)
|
parsed = urlparse(self._dsc_source)
|
||||||
url = self._dsc_source
|
self._download_dsc(self._dsc_source)
|
||||||
else:
|
else:
|
||||||
url = self._lp_url(self.dsc_name, source=True)
|
for url in self._source_urls(self.dsc_name):
|
||||||
|
dlerr = None
|
||||||
|
try:
|
||||||
self._download_dsc(url)
|
self._download_dsc(url)
|
||||||
|
break
|
||||||
|
except DownloadError as e:
|
||||||
|
dlerr = e
|
||||||
|
else:
|
||||||
|
raise dlerr
|
||||||
self._check_dsc()
|
self._check_dsc()
|
||||||
|
|
||||||
def _download_dsc(self, url):
|
def _download_dsc(self, url):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user