Added cheksum file

This commit is contained in:
Dimitris Zlatanidis 2022-06-18 10:18:00 +03:00
parent 2ecb5d407f
commit 386ac68bd5
2 changed files with 39 additions and 32 deletions

36
slpkg/checksum.py Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import hashlib
from dataclasses import dataclass
from slpkg.metadata import Metadata
from slpkg.views.views import ViewMessage
@dataclass
class Md5sum:
''' Checksum the sources. '''
flags: str
build_path: str = Metadata.build_path
def check(self, source, checksum, name):
path = f'{self.build_path}/{name}'
filename = f'{path}/{source.split("/")[-1]}'
md5 = self.read_file(filename)
file_check = hashlib.md5(md5).hexdigest()
if file_check not in checksum:
print('\nExpected:', ''.join(checksum))
print('Found:', file_check)
print(f'\nMD5SUM check for {name} FAILED.')
view = ViewMessage()
view.question(self.flags)
def read_file(self, filename):
with open(filename, 'rb') as f:
return f.read()

View file

@ -3,11 +3,11 @@
import os
import shutil
import hashlib
import subprocess
from dataclasses import dataclass
from slpkg.downloader import Wget
from slpkg.checksum import Md5sum
from slpkg.metadata import Metadata
from slpkg.queries import SBoQueries
from slpkg.utilities import Utilities
@ -163,8 +163,8 @@ class Slackbuilds:
for source, checksum in zip(sources.split(), checksums[0].split()):
wget.download(path, source)
md5sum = Md5sum(source, checksum, name)
md5sum.check()
md5sum = Md5sum(self.flags)
md5sum.check(source, checksum, name)
def remove_file_if_exists(self, path: str, file: str):
''' Clean the the old files. '''
@ -177,32 +177,3 @@ class Slackbuilds:
directory = f'{path}/{folder}'
if os.path.isdir(directory):
shutil.rmtree(directory)
@dataclass
class Md5sum:
''' Checksum the sources. '''
source: str
checksum: str
name: str
build_path: str = Metadata.build_path
def check(self):
path = f'{self.build_path}/{self.name}'
filename = f'{path}/{self.source.split("/")[-1]}'
md5 = self.read_file(filename)
file_check = hashlib.md5(md5).hexdigest()
if file_check not in self.checksum:
print('\nExpected:', ''.join(self.checksum))
print('Found:', file_check)
print(f'\nMD5SUM check for {self.sbo} FAILED.')
view = ViewMessage()
view.question(['--no'])
def read_file(self, filename):
with open(filename, 'rb') as f:
return f.read()