* [Buildroot] [PATCH] scanpypi: add support for licence files checksums
@ 2018-01-15 10:04 yegorslists at googlemail.com
2018-01-15 21:13 ` Thomas Petazzoni
0 siblings, 1 reply; 2+ messages in thread
From: yegorslists at googlemail.com @ 2018-01-15 10:04 UTC (permalink / raw)
To: buildroot
From: Yegor Yefremov <yegorslists@googlemail.com>
Store the list of detected licence files in the main object and
automatically add their sha256 checksums when creating *.hash file.
Bonus: fix wrong indentation.
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
utils/scanpypi | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/utils/scanpypi b/utils/scanpypi
index d3b0d2f..765bfdc 100755
--- a/utils/scanpypi
+++ b/utils/scanpypi
@@ -24,6 +24,8 @@ import tempfile
import imp
from functools import wraps
+BUF_SIZE = 65536
+
try:
import spdx_lookup as liclookup
except ImportError:
@@ -132,6 +134,7 @@ class BuildrootPackage():
self.filename = None
self.url = None
self.version = None
+ self.license_files = []
def fetch_package_info(self):
"""
@@ -439,12 +442,12 @@ class BuildrootPackage():
filenames = ['LICENCE', 'LICENSE', 'LICENSE.RST', 'LICENSE.TXT',
'COPYING', 'COPYING.TXT']
- license_files = list(find_file_upper_case(filenames, self.tmp_extract))
+ self.license_files = list(find_file_upper_case(filenames, self.tmp_extract))
- lines.append(self.__get_license_names(license_files))
+ lines.append(self.__get_license_names(self.license_files))
license_files = [license.replace(self.tmp_extract, '')[1:]
- for license in license_files]
+ for license in self.license_files]
if len(license_files) > 0:
if len(license_files) > 1:
print('More than one file found for license:',
@@ -508,7 +511,7 @@ class BuildrootPackage():
lines = []
if self.used_url['md5_digest']:
md5_comment = '# md5 from {url}, sha256 locally computed\n'.format(
- url=self.metadata_url)
+ url=self.metadata_url)
lines.append(md5_comment)
hash_line = '{method}\t{digest} {filename}\n'.format(
method='md5',
@@ -522,6 +525,20 @@ class BuildrootPackage():
filename=self.filename)
lines.append(hash_line)
+ for license_file in self.license_files:
+ sha256 = hashlib.sha256()
+ with open(license_file, 'rb') as lic_f:
+ while True:
+ data = lic_f.read(BUF_SIZE)
+ if not data:
+ break
+ sha256.update(data)
+ hash_line = '{method}\t{digest} {filename}\n'.format(
+ method='sha256',
+ digest=sha256.hexdigest(),
+ filename=os.path.basename(license_file))
+ lines.append(hash_line)
+
with open(path_to_hash, 'w') as hash_file:
hash_file.writelines(lines)
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* [Buildroot] [PATCH] scanpypi: add support for licence files checksums
2018-01-15 10:04 [Buildroot] [PATCH] scanpypi: add support for licence files checksums yegorslists at googlemail.com
@ 2018-01-15 21:13 ` Thomas Petazzoni
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni @ 2018-01-15 21:13 UTC (permalink / raw)
To: buildroot
Hello,
On Mon, 15 Jan 2018 11:04:50 +0100, yegorslists at googlemail.com wrote:
> From: Yegor Yefremov <yegorslists@googlemail.com>
>
> Store the list of detected licence files in the main object and
> automatically add their sha256 checksums when creating *.hash file.
>
> Bonus: fix wrong indentation.
>
> Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
> ---
> utils/scanpypi | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
Applied to master, thanks.
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-15 21:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-15 10:04 [Buildroot] [PATCH] scanpypi: add support for licence files checksums yegorslists at googlemail.com
2018-01-15 21:13 ` Thomas Petazzoni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox