Updated utils and instances

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-02-17 16:20:51 +01:00
parent bfb5022b8d
commit 5c5515bec0
14 changed files with 54 additions and 34 deletions

View file

@ -48,7 +48,7 @@ from slpkg.binary.repo_init import RepoInit
from slpkg.binary.dependency import Dependencies
class BinaryInstall(BlackList):
class BinaryInstall(BlackList, Utils):
"""Install binaries packages with all dependencies from
repository
"""
@ -65,7 +65,6 @@ class BinaryInstall(BlackList):
self.yellow = _meta_.color['YELLOW']
self.endc = _meta_.color["ENDC"]
self.msg = Msg()
self.utils = Utils()
self.version = self.meta.slack_rel
self.tmp_path = self.meta.slpkg_tmp_packages
self.init_flags()
@ -163,9 +162,9 @@ class BinaryInstall(BlackList):
self.msg.template(78)
if "--download-only" in self.flag:
raise SystemExit()
self.dep_install = list(self.utils.check_downloaded(
self.dep_install = list(self.check_downloaded(
self.tmp_path, self.dep_install))
self.install = list(self.utils.check_downloaded(
self.install = list(self.check_downloaded(
self.tmp_path, self.install))
ins, upg = self.install_packages()
self.msg.reference(ins, upg)
@ -192,8 +191,8 @@ class BinaryInstall(BlackList):
lowercase
"""
if "--case-ins" in self.flag:
data = list(self.utils.package_name(self.PACKAGES_TXT))
data_dict = self.utils.case_sensitive(data)
data = list(self.package_name(self.PACKAGES_TXT))
data_dict = self.case_sensitive(data)
for pkg in self.packages:
index = self.packages.index(pkg)
for key, value in data_dict.items():
@ -204,7 +203,7 @@ class BinaryInstall(BlackList):
"""Update dependencies dictionary with all package
"""
for dep in self.dependencies:
deps = self.utils.dimensional_list(Dependencies(
deps = self.dimensional_list(Dependencies(
self.repo, self.blacklist).binary(
dep, self.flag))
self.deps_dict[dep] = deps
@ -214,7 +213,7 @@ class BinaryInstall(BlackList):
or if added to install two or more times
"""
packages = []
for mas in self.utils.remove_dbs(self.packages):
for mas in self.remove_dbs(self.packages):
if mas not in self.dependencies:
packages.append(mas)
self.packages = packages
@ -268,11 +267,11 @@ class BinaryInstall(BlackList):
self.msg.resolving()
for dep in self.packages:
dependencies = []
dependencies = self.utils.dimensional_list(Dependencies(
dependencies = self.dimensional_list(Dependencies(
self.repo, self.blacklist).binary(dep, self.flag))
requires += list(self._fix_deps_repos(dependencies))
self.deps_dict[dep] = self.utils.remove_dbs(requires)
return self.utils.remove_dbs(requires)
self.deps_dict[dep] = self.remove_dbs(requires)
return self.remove_dbs(requires)
def _fix_deps_repos(self, dependencies):
"""Fix store deps include in repository

View file

@ -30,7 +30,7 @@ from slpkg.slack.mirrors import mirrors
from slpkg.slack.slack_version import slack_ver
class RepoInit:
class RepoInit(Utils):
"""Return PACKAGES.TXT and mirror by repository
"""
def __init__(self, repo):
@ -45,7 +45,7 @@ class RepoInit:
else:
self._init_custom()
self.lib = self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT"
PACKAGES_TXT = Utils().read_file(self.lib)
PACKAGES_TXT = self.read_file(self.lib)
return PACKAGES_TXT, self.mirror
def _init_custom(self):

View file

@ -31,8 +31,10 @@ def search_pkg(name, repo):
"""Search if package exists in PACKAGES.TXT file
and return the name.
"""
PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")
names = list(Utils().package_name(PACKAGES_TXT))
utils = Utils()
black = BlackList()
PACKAGES_TXT = utils.read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT")
names = list(black.package_name(PACKAGES_TXT))
blacklist = list(BlackList().get_black())
if name in names and name not in blacklist:
return name

View file

@ -46,7 +46,7 @@ def check_md5(pkg_md5, src_file):
print(f"| Found: {md5s}")
msg.template(78)
print()
if not Msg().answer() in ["y", "Y"]:
if not msg.answer() in ["y", "Y"]:
raise SystemExit()
else:
msg.template(78)

View file

@ -30,9 +30,10 @@ from slpkg.splitting import split_package
def searching(find_pkg, directory):
"""Find packages
"""
black = BlackList()
if os.path.isdir(directory):
installed = os.listdir(directory)
blacklist = list(BlackList().get_black())
blacklist = list(black.get_black())
if os.path.exists(directory):
for pkg in installed:
if (not pkg.startswith(".") and pkg.startswith(find_pkg) and

View file

@ -38,10 +38,11 @@ def sbo_upgrade(skip, flag):
"""Return packages for upgrade
"""
msg = Msg()
black = BlackList()
msg.checking()
upgrade_names = []
data = SBoGrep(name="").names()
blacklist = list(BlackList().get_black())
blacklist = list(black.get_black())
for pkg in sbo_list():
name = split_package(pkg)[0]
ver = split_package(pkg)[1]

View file

@ -34,10 +34,12 @@ def sbo_search_pkg(name):
return url
"""
url = ""
repo = Repo().default_repository()["sbo"]
sbo_url = f"{repo}{slack_ver()}/"
SLACKBUILDS_TXT = Utils().read_file(
_meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT")
utils = Utils()
repo = Repo()
sbo = repo.default_repository()["sbo"]
sbo_url = f"{sbo}{slack_ver()}/"
SLACKBUILDS_TXT = utils.read_file(
f"{_meta_.lib_path}sbo_repo/SLACKBUILDS.TXT")
for line in SLACKBUILDS_TXT.splitlines():
if line.startswith("SLACKBUILD LOCATION"):
sbo_name = (line[23:].split("/")[-1].replace("\n", "")).strip()

View file

@ -33,6 +33,7 @@ from slpkg.pkg.find import find_package
def slack_package(prgnam):
"""Return maximum binary Slackware package from output directory
"""
msg = Msg()
binaries, cache, binary = [], "0", ""
for pkg in find_package(prgnam, _meta_.output):
if pkg.startswith(prgnam) and pkg[:-4].endswith("_SBo"):
@ -43,6 +44,6 @@ def slack_package(prgnam):
binary = bins
cache = binary
if not binary:
Msg().build_FAILED(prgnam)
msg.build_FAILED(prgnam)
raise SystemExit(1)
return ["".join(_meta_.output + binary)]

View file

@ -29,8 +29,8 @@ from slpkg.messages import Msg
def pkg_security(pkgs):
"""Check packages before install or upgrade for security
reasons. Configuration file in the /etc/slpkg/pkg_security"""
security_packages = Utils().read_file("/etc/slpkg/pkg_security")
packages, msg = [], Msg()
packages, msg, utils = [], Msg(), Utils()
security_packages = utils.read_file("/etc/slpkg/pkg_security")
for read in security_packages.splitlines():
read = read.lstrip()
if not read.startswith("#"):

View file

@ -34,20 +34,21 @@ def mirrors(name, location):
"""
rel = _meta_.slack_rel
ver = slack_ver()
repo = Repo().slack()
repo = Repo()
slack = repo.slack()
if _meta_.arch == "x86_64":
if rel == "stable":
http = f"{repo}slackware64-{ver}/{location}{name}"
http = f"{slack}slackware64-{ver}/{location}{name}"
else:
http = f"{repo}slackware64-{rel}/{location}{name}"
http = f"{slack}slackware64-{rel}/{location}{name}"
elif _meta_.arch.startswith("arm"):
if rel == "stable":
http = f"{repo}slackwarearm-{ver}/{location}{name}"
http = f"{slack}slackwarearm-{ver}/{location}{name}"
else:
http = f"{repo}slackwarearm-{rel}/{location}{name}"
http = f"{slack}slackwarearm-{rel}/{location}{name}"
else:
if rel == "stable":
http = f"{repo}slackware-{ver}/{location}{name}"
http = f"{slack}slackware-{ver}/{location}{name}"
else:
http = f"{repo}slackware-{rel}/{location}{name}"
http = f"{slack}slackware-{rel}/{location}{name}"
return http

View file

@ -32,8 +32,9 @@ def slack_ver():
"""
Open file and read Slackware version
"""
utils = Utils()
if _meta_.slackware_version in ["off", "OFF"]:
sv = Utils().read_file("/etc/slackware-version")
sv = utils.read_file("/etc/slackware-version")
version = re.findall(r"\d+", sv)
if len(sv) > 2:
return (".".join(version[:2]))

View file

@ -31,9 +31,10 @@ from slpkg.__metadata__ import MetaData as _meta_
def slackware_repository():
"""Return all official Slackware packages
"""
utils = Utils()
slack_repo, packages, names = [], [], []
slack_repo = repo_data(
Utils().read_file(f"{_meta_.lib_path}slack_repo/PACKAGES.TXT"),
utils.read_file(f"{_meta_.lib_path}slack_repo/PACKAGES.TXT"),
"slack", "")
for pkg in slack_repo[0]:
names.append(split_package(pkg)[0])

View file

@ -48,10 +48,12 @@ def it_self_update():
branch,
_meta_.__all__))
version_data = URL(ver_link).reading()
for line in version_data.splitlines():
line = line.strip()
if line.startswith("__version_info__"):
__new_version__ = ".".join(re.findall(r"\d+", line))
if __new_version__ > _meta_.__version__:
if _meta_.default_answer in ["y", "Y"]:
answer = _meta_.default_answer
@ -63,10 +65,12 @@ def it_self_update():
except EOFError:
print()
raise SystemExit(1)
if answer in ["y", "Y"]:
print() # new line after answer
else:
raise SystemExit()
dwn_link = ["https://{0}.com/{1}/{2}/-/archive/"
"{3}/{4}-{5}.tar.gz".format(repository,
_meta_.__author__,
@ -74,8 +78,10 @@ def it_self_update():
__new_version__,
_meta_.__all__,
__new_version__)]
if not os.path.exists(_meta_.build_path):
os.makedirs(_meta_.build_path)
Download(_meta_.build_path, dwn_link, repo="").start()
os.chdir(_meta_.build_path)
slpkg_tar_file = f"slpkg-{__new_version__}.tar.gz"
@ -88,6 +94,7 @@ def it_self_update():
_meta_.build_path + slpkg_tar_file)
subprocess.call("chmod +x {0}".format("install.sh"), shell=True)
subprocess.call("sh install.sh", shell=True)
else:
print(f"\n{_meta_.__all__}: There is no new version, already used the last!\n")
raise SystemExit()

View file

@ -29,14 +29,18 @@ def split_package(package):
"""
name = ver = arch = build = []
split = package.split("-")
if len(split) > 2:
build = split[-1]
build_a, build_b = "", ""
build_a = build[:1]
if build[1:2].isdigit():
build_b = build[1:2]
build = build_a + build_b
arch = split[-2]
ver = split[-3]
name = "-".join(split[:-3])
return [name, ver, arch, build]