Updated utils

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-02-17 13:50:20 +01:00
parent f465d6f141
commit 454aa55938
10 changed files with 31 additions and 36 deletions

View file

@ -30,13 +30,12 @@ from slpkg.utils import Utils
from slpkg.__metadata__ import MetaData as _meta_
class Config:
class Config(Utils):
"""Print or edit slpkg configuration file
"""
def __init__(self):
self.config_file = "/etc/slpkg/slpkg.conf"
self.meta = _meta_
self.utils = Utils()
self.green = _meta_.color["GREEN"]
self.red = _meta_.color["RED"]
self.cyan = _meta_.color["CYAN"]
@ -70,7 +69,7 @@ class Config:
"EDITOR",
"NOT_DOWNGRADE"
]
read_conf = self.utils.read_file(self.config_file)
read_conf = self.read_file(self.config_file)
for line in read_conf.splitlines():
if not line.startswith("#") and line.split("=")[0] in conf_args:
print(line)

View file

@ -29,7 +29,7 @@ from slpkg.__metadata__ import MetaData as _meta_
from slpkg.sbo.greps import SBoGrep
class PkgDesc:
class PkgDesc(Utils):
"""Print package description from the repository
"""
def __init__(self, name, repo, paint):
@ -38,7 +38,6 @@ class PkgDesc:
self.paint = paint
self.meta = _meta_
self.msg = Msg()
self.utils = Utils()
self.lib = ""
self.color = {
"red": self.meta.color["RED"],
@ -58,7 +57,7 @@ class PkgDesc:
if self.repo == "sbo":
description = SBoGrep(self.name).description()
else:
PACKAGES_TXT = self.utils.read_file(self.lib)
PACKAGES_TXT = self.read_file(self.lib)
for line in PACKAGES_TXT.splitlines():
if line.startswith(self.name + ":"):
description += f"{line[len(self.name) + 2:]}\n"

View file

@ -32,7 +32,7 @@ from slpkg.slack.slack_version import slack_ver
from slpkg.__metadata__ import MetaData as _meta_
class Download:
class Download(Utils):
"""Downloader manager. Slpkg use wget by default but support
curl, aria2 and httpie
"""
@ -57,7 +57,7 @@ class Download:
dwn_count = 1
self._directory_prefix()
for dwn in self.url:
self.file_name = Utils().fix_file_name(dwn.split("/")[-1])
self.file_name = self.fix_file_name(dwn.split("/")[-1])
if dwn.startswith("file:///"):
source_dir = dwn[7:-7].replace(slack_ver(), "")

View file

@ -35,7 +35,7 @@ from slpkg.slack.mirrors import mirrors
from slpkg.slack.slack_version import slack_ver
class Initialization:
class Initialization(Utils):
"""Slpkg initialization start all from here. Create local
package lists and update or upgrade these.
"""
@ -685,8 +685,7 @@ class Initialization:
for f in infiles:
if os.path.isfile(f"{path}{f}"):
# checking the encoding before read the file
utils = Utils()
code = utils.check_encoding(path, f)
code = self.check_encoding(path, f)
with open(path + f, "r", encoding=code) as in_f:
for line in in_f:
out_f.write(line)

View file

@ -31,7 +31,7 @@ from slpkg.utils import Utils
from slpkg.__metadata__ import MetaData as _meta_
class NewConfig:
class NewConfig(Utils):
"""Manage .new configuration files
"""
def __init__(self):
@ -179,9 +179,9 @@ class NewConfig:
"""Print the differences between the two files
"""
if os.path.isfile(n[:-4]):
diff1 = Utils().read_file(n[:-4]).splitlines()
diff1 = self.read_file(n[:-4]).splitlines()
if os.path.isfile(n):
diff2 = Utils().read_file(n).splitlines()
diff2 = self.read_file(n).splitlines()
lines, ln, c = [], 0, 0
for a, b in itertools.izip_longest(diff1, diff2):
ln += 1
@ -208,9 +208,9 @@ class NewConfig:
"""Merge new file into old
"""
if os.path.isfile(n[:-4]):
old = Utils().read_file(n[:-4]).splitlines()
old = self.read_file(n[:-4]).splitlines()
if os.path.isfile(n):
new = Utils().read_file(n).splitlines()
new = self.read_file(n).splitlines()
with open(n[:-4], "w") as out:
for l1, l2 in itertools.izip_longest(old, new):
if l1 is None:

View file

@ -29,7 +29,7 @@ from slpkg.url_read import URL
from slpkg.__metadata__ import MetaData as _meta_
class BuildNumber:
class BuildNumber(Utils):
"""Get build number from SlackBuild script
"""
def __init__(self, sbo_url, pkg):
@ -42,7 +42,7 @@ class BuildNumber:
if self.sbo_url:
SlackBuild = URL(f"{self.sbo_url}{self.pkg}.SlackBuild").reading()
else:
SlackBuild = Utils().read_file(f"{self.meta.build_path}{self.pkg}/{self.pkg}.SlackBuild")
SlackBuild = self.read_file(f"{self.meta.build_path}{self.pkg}/{self.pkg}.SlackBuild")
for line in SlackBuild.splitlines():
line = line.lstrip()
if line.startswith("BUILD="):

View file

@ -26,7 +26,7 @@ from slpkg.utils import Utils
from slpkg.__metadata__ import MetaData as _meta_
class SBoGrep:
class SBoGrep(Utils):
"""Grab data from SLACKBUILDS.TXT file
"""
def __init__(self, name):
@ -45,7 +45,7 @@ class SBoGrep:
self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT"
self.answer = ["y", "Y"]
self.unst = ["UNSUPPORTED", "UNTESTED"]
self.SLACKBUILDS_TXT = Utils().read_file(self.sbo_txt)
self.SLACKBUILDS_TXT = self.read_file(self.sbo_txt)
def _names_grabbing(self):
"""Generator that collecting all packages names

View file

@ -48,7 +48,7 @@ from slpkg.sbo.slack_find import slack_package
from slpkg.slack.slack_version import slack_ver
class SBoNetwork(BlackList):
class SBoNetwork(BlackList, Utils):
"""View SBo site in terminal and also read, build or
install packages
"""
@ -135,7 +135,7 @@ class SBoNetwork(BlackList):
lowercase
"""
if "--case-ins" in self.flag:
data_dict = Utils().case_sensitive(self.data)
data_dict = self.case_sensitive(self.data)
for key, value in data_dict.items():
if key == self.name.lower():
self.name = value

View file

@ -50,7 +50,7 @@ from slpkg.slack.mirrors import mirrors
from slpkg.slack.slack_version import slack_ver
class Patches(BlackList):
class Patches(BlackList, Utils):
"""Upgrade distribution from official Slackware mirrors
"""
def __init__(self, skip, flag):
@ -75,7 +75,6 @@ class Patches(BlackList):
self.installed = []
self.comp_sum = []
self.uncomp_sum = []
self.utils = Utils()
self.msg.checking()
if self.version == "stable":
self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT",
@ -111,7 +110,7 @@ class Patches(BlackList):
if self.msg.answer() in ["y", "Y"]:
Download(self.patch_path, self.dwn_links,
repo="slack").start()
self.upgrade_all = list(self.utils.check_downloaded(
self.upgrade_all = list(self.check_downloaded(
self.patch_path, self.upgrade_all))
self.upgrade()
self.kernel()

View file

@ -38,7 +38,7 @@ from slpkg.binary.search import search_pkg
from slpkg.binary.dependency import Dependencies
class TrackingDeps(BlackList):
class TrackingDeps(BlackList, Utils):
"""View tree of dependencies and also
highlight packages with color green
if already installed and color red
@ -51,7 +51,6 @@ class TrackingDeps(BlackList):
self.flag = flag
self.meta = _meta_
self.msg = Msg()
self.utils = Utils()
self.green = self.meta.color["GREEN"]
self.yellow = self.meta.color["YELLOW"]
self.cyan = self.meta.color["CYAN"]
@ -78,8 +77,8 @@ class TrackingDeps(BlackList):
self.repositories()
if self.find_pkg:
self.dependencies_list.reverse()
self.requires = self.utils.dimensional_list(self.dependencies_list)
self.dependencies = self.utils.remove_dbs(self.requires)
self.requires = self.dimensional_list(self.dependencies_list)
self.dependencies = self.remove_dbs(self.requires)
if self.dependencies == []:
self.dependencies = ["No dependencies"]
if "--graph=" in self.flag:
@ -130,9 +129,9 @@ class TrackingDeps(BlackList):
if self.find_pkg:
self.dependencies_list = Requires(self.flag).sbo(self.name)
else:
PACKAGES_TXT = self.utils.read_file(
PACKAGES_TXT = self.read_file(
f"{self.meta.lib_path}{self.repo}_repo/PACKAGES.TXT")
self.names = list(self.utils.package_name(PACKAGES_TXT))
self.names = list(self.package_name(PACKAGES_TXT))
self.bin_case_insensitive()
self.find_pkg = search_pkg(self.name, self.repo)
if self.find_pkg:
@ -146,7 +145,7 @@ class TrackingDeps(BlackList):
"""
if "--case-ins" in self.flag:
data = SBoGrep(name="").names()
data_dict = self.utils.case_sensitive(data)
data_dict = self.case_sensitive(data)
for key, value in data_dict.items():
if key == self.name.lower():
self.name = value
@ -156,7 +155,7 @@ class TrackingDeps(BlackList):
lowercase
"""
if "--case-ins" in self.flag:
data_dict = self.utils.case_sensitive(self.names)
data_dict = self.case_sensitive(self.names)
for key, value in data_dict.items():
if key == self.name.lower():
self.name = value
@ -173,7 +172,7 @@ class TrackingDeps(BlackList):
dep_path = f"{self.meta.log_path}dep/"
logs = find_package("", dep_path)
for log in logs:
deps = self.utils.read_file(f"{dep_path}{log}")
deps = self.read_file(f"{dep_path}{log}")
for dep in deps.splitlines():
if pkg == dep:
used.append(log)
@ -187,12 +186,12 @@ class TrackingDeps(BlackList):
for dep in dependencies:
deps = Requires(flag="").sbo(dep)
if dep not in self.deps_dict.values():
self.deps_dict[dep] = self.utils.dimensional_list(deps)
self.deps_dict[dep] = self.dimensional_list(deps)
else:
for dep in dependencies:
deps = Dependencies(self.repo, self.black).binary(dep, flag="")
if dep not in self.deps_dict.values():
self.deps_dict[dep] = self.utils.dimensional_list(deps)
self.deps_dict[dep] = self.dimensional_list(deps)
def deps_used(self, pkg, used):
"""Create dependencies dictionary