slpkg/slpkg/grep_md5.py

50 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/python3
2014-10-27 07:02:36 +02:00
# -*- coding: utf-8 -*-
2014-12-03 16:28:01 +02:00
# grep_md5.py file is part of slpkg.
2014-10-27 07:02:36 +02:00
# Copyright 2014-2022 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
2014-10-27 07:02:36 +02:00
# All rights reserved.
2014-12-19 06:57:56 +02:00
# Slpkg is a user-friendly package manager for Slackware installations
2014-10-27 07:02:36 +02:00
# https://gitlab.com/dslackw/slpkg
2014-10-27 07:02:36 +02:00
# 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/>.
2015-05-28 06:07:13 +03:00
2015-08-21 02:15:43 +03:00
from slpkg.slack.mirrors import mirrors
2014-10-27 07:02:36 +02:00
2015-08-21 02:15:43 +03:00
from slpkg.url_read import URL
from slpkg.__metadata__ import MetaData as _meta_
2014-11-14 10:55:35 +02:00
2014-10-27 07:02:36 +02:00
2014-12-03 03:42:55 +02:00
def pkg_checksum(binary, repo):
2015-09-27 12:11:01 +03:00
"""Return checksum from CHECKSUMS.md5 file by repository
2015-06-05 14:42:52 +03:00
"""
2015-06-28 14:25:25 +03:00
md5 = "None"
2015-06-07 08:26:42 +03:00
if repo == "slack_patches" and _meta_.slack_rel == "stable":
2014-12-16 22:18:50 +02:00
CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "patches/")).reading()
2015-06-07 08:26:42 +03:00
elif repo == "slack_patches" and _meta_.slack_rel == "current":
2014-12-20 08:16:11 +02:00
CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "")).reading()
2014-12-29 09:46:02 +02:00
elif repo == "slpkg":
2015-06-07 08:26:42 +03:00
CHECKSUMS_md5 = URL(_meta_.CHECKSUMS_link).reading()
2014-12-16 22:18:50 +02:00
else:
lib = f"{_meta_.lib_path}{repo}_repo/CHECKSUMS.md5"
2014-12-26 17:17:58 +02:00
f = open(lib, "r")
2014-12-16 22:18:50 +02:00
CHECKSUMS_md5 = f.read()
f.close()
2014-12-03 03:42:55 +02:00
for line in CHECKSUMS_md5.splitlines():
if line.endswith(f"/{binary}"):
2014-12-03 03:42:55 +02:00
md5 = line.split()[0]
return md5