added support checksum for sbo repo

This commit is contained in:
Dimitris Zlatanidis 2014-09-09 21:03:22 +03:00
parent 18c6d8d7f1
commit e2222fb7d7
5 changed files with 87 additions and 10 deletions

32
slpkg/checksum.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# checksum.py file is part of slpkg.
# Copyright 2014 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
# All rights reserved.
# Utility for easy management packages in Slackware
# https://github.com/dslackw/slpkg
# Slpkg is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import hashlib
def md5sum(source):
'''
Calculate the md5 checksum
'''
with open(source) as file_to_check:
data = file_to_check.read()
return hashlib.md5(data).hexdigest()

View file

@ -76,7 +76,7 @@ def s_user(user):
def build_FAILED(sbo_url, prgnam):
print("\n{0}<-- FAILED{1} to build the package {2}".format(colors.RED, colors.ENDC, prgnam))
print("See log file in slpkg_Build directory or read README file:")
print("See log file in /var/log/slpkg/logs directory or read README file:")
print("{0}{1}\n".format(sbo_url, "README"))
def template(max):

View file

@ -28,8 +28,12 @@ import shutil
import tarfile
import subprocess
from messages import pkg_not_found
from colors import colors
from checksum import md5sum
from __metadata__ import log_path
from messages import pkg_not_found, template
from sbo.greps import sbo_checksum_pkg
def build_package(script, sources, path):
'''
@ -44,7 +48,7 @@ def build_package(script, sources, path):
if not os.path.exists(logs):
os.mkdir(logs)
log_date = time.strftime("%c")
template = ("#" * 79 + "\n\n")
log_line = ("#" * 79 + "\n\n")
try:
if os.path.isfile(logs + log_file):
os.remove(logs + log_file)
@ -52,20 +56,41 @@ def build_package(script, sources, path):
tar.extractall()
tar.close()
for src in sources:
sbo_md5 = sbo_checksum_pkg(prgnam)
md5 = md5sum(src)
if sbo_md5 != md5:
template(78)
print("| MD5SUM check for {0} [ {1}FAILED{2} ]".format(
src, colors.RED, colors.ENDC))
template(78)
print("| Expected: {0}".format(md5))
print("| Found: {0}".format(sbo_md5))
template(78)
read = raw_input("\nDo you want to continue [Y/n]? ")
if read == "Y" or read == "y":
pass
else:
sys.exit()
else:
template(78)
print("| MD5SUM check for {0} [ {1}PASS{2} ]".format(
src, colors.GREEN, colors.ENDC))
template(78)
print # new line after pass checksum
shutil.copy2(src, prgnam)
os.chdir(path + prgnam)
subprocess.call("chmod +x {0}.SlackBuild".format(prgnam), shell=True)
with open(logs + log_file, "w") as log: # write headers to log file
log.write(template)
log.write(log_line)
log.write("File : " + log_file + "\n")
log.write("Path : " + logs + "\n")
log.write("Date : " + log_date + "\n\n")
log.write(template)
log.write(log_line)
log.close()
with open(logs + log_file, "a") as log: # append END tag to a log file
log.write(template)
log.write(log_line)
log.write(" " * 38 + "E N D\n\n")
log.write(template)
log.write(log_line)
subprocess.Popen("./{0}.SlackBuild 2>&1 | tee -a {1}{2}".format(
prgnam, logs, log_file), shell=True, stdout=sys.stdout).communicate()
log.close()

View file

@ -78,5 +78,21 @@ def sbo_version_pkg(name):
sbo_name = line[17:].strip()
if line.startswith("SLACKBUILD VERSION: "):
if sbo_name == name:
sbo_url = sbo_search_pkg(name)
return line[20:].strip()
def sbo_checksum_pkg(name):
if arch == "x86_64":
for line in open(lib_path + "sbo_repo/SLACKBUILDS.TXT", "r"):
if arch == "x86_64":
if line.startswith("SLACKBUILD NAME: "):
sbo_name = line[17:].strip()
if line.startswith("SLACKBUILD MD5SUM_x86_64: "):
if sbo_name == name:
if line[26:].strip():
return line[26:].strip()
for line in open(lib_path + "sbo_repo/SLACKBUILDS.TXT", "r"):
if line.startswith("SLACKBUILD NAME: "):
sbo_name = line[17:].strip()
if line.startswith("SLACKBUILD MD5SUM: "):
if sbo_name == name:
return line[19:].strip()

View file

@ -26,6 +26,7 @@ import sys
import subprocess
from colors import colors
from checksum import md5sum
from functions import get_file
from __metadata__ import tmp, pkg_path, build_path, log_path, sp
from messages import pkg_not_found, pkg_found, template, build_FAILED
@ -162,7 +163,7 @@ def sbo_build(name):
print("Total {0} {1}.".format(len(dependencies), msg_ins))
print("{0} {1} will be installed, {2} allready installed and {3} {4}".format(
count_installed, msg_ins, pkg_sum, count_upgraded, msg_upg))
print("will be upgraded.")
print("will be upgraded.\n")
'''
Check if package supported by arch
before proceed to install
@ -173,7 +174,10 @@ def sbo_build(name):
if item == un:
print("\n{0}The package {1}{2}\n".format(colors.RED, item, ENDC))
sys.exit()
read = raw_input("\nDo you want to continue [Y/n]? ")
# exit if all packages already installed
if pkg_sum == len(dependencies):
sys.exit()
read = raw_input("Do you want to continue [Y/n]? ")
if read == "Y" or read == "y":
if not os.path.exists(build_path):
os.mkdir(build_path)