mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-30 20:34:38 +01:00
Make code more readable
This commit is contained in:
parent
40759022fb
commit
89dee26d88
10 changed files with 120 additions and 0 deletions
|
@ -71,9 +71,12 @@ class Database:
|
|||
md5sum=cache[6], md5sum64=cache[7],
|
||||
requires=cache[8], short_description=cache[9])
|
||||
self.session.add(data)
|
||||
|
||||
cache = [] # reset cache after 11 lines
|
||||
|
||||
bar.next()
|
||||
bar.finish()
|
||||
|
||||
self.session.commit()
|
||||
|
||||
def open_file(self, file):
|
||||
|
|
|
@ -46,11 +46,13 @@ class AutoBuild:
|
|||
self.files_exist()
|
||||
self.info_file()
|
||||
sources = self.sources
|
||||
|
||||
if len(sources) > 1 and self.sbo_sources != sources:
|
||||
sources = self.sbo_sources
|
||||
# If the list does not have the same order uses from .info
|
||||
# order.
|
||||
BuildPackage(self.script, sources, self.path, auto=True).build()
|
||||
|
||||
raise SystemExit()
|
||||
|
||||
def info_file(self):
|
||||
|
@ -66,7 +68,9 @@ class AutoBuild:
|
|||
if not os.path.isfile(self.path + self.script):
|
||||
raise SystemExit("\nslpkg: Error: SlackBuild archive.tar.gz "
|
||||
"not found\n")
|
||||
|
||||
for src in self.sources:
|
||||
|
||||
if not os.path.isfile(self.path + src):
|
||||
raise SystemExit(f"\nslpkg: Error: Source file '{src}' "
|
||||
f"not found\n")
|
||||
|
|
|
@ -39,15 +39,21 @@ class BuildNumber(Utils):
|
|||
|
||||
def get(self):
|
||||
num = "NO_BUILD"
|
||||
|
||||
if self.sbo_url:
|
||||
SlackBuild = URL(f"{self.sbo_url}"
|
||||
f"{self.pkg}.SlackBuild").get_request()
|
||||
|
||||
else:
|
||||
SlackBuild = self.read_file(f"{self.meta.build_path}{self.pkg}/"
|
||||
f"{self.pkg}.SlackBuild")
|
||||
|
||||
for line in SlackBuild.splitlines():
|
||||
|
||||
line = line.lstrip()
|
||||
|
||||
if line.startswith("BUILD="):
|
||||
num = re.findall(r"\d+", line)
|
||||
break
|
||||
|
||||
return "".join(num)
|
||||
|
|
|
@ -43,17 +43,22 @@ def sbo_upgrade(skip, flag):
|
|||
upgrade_names = []
|
||||
data = SBoGrep(name="").names()
|
||||
blacklist = list(black.get_black())
|
||||
|
||||
for pkg in sbo_list():
|
||||
name = split_package(pkg)[0]
|
||||
ver = split_package(pkg)[1]
|
||||
|
||||
if (name in data and name not in skip and name not in blacklist):
|
||||
sbo_package = f"{name}-{SBoGrep(name).version()}"
|
||||
package = f"{name}-{ver}"
|
||||
|
||||
if parse_version(sbo_package) > parse_version(package):
|
||||
upgrade_names.append(name)
|
||||
msg.done()
|
||||
|
||||
if "--checklist" in flag:
|
||||
upgrade_names = choose_upg(upgrade_names)
|
||||
|
||||
return upgrade_names
|
||||
|
||||
|
||||
|
@ -61,5 +66,6 @@ def sbo_list():
|
|||
"""Returns all SBo packages
|
||||
"""
|
||||
for pkg in os.listdir(_meta_.pkg_path):
|
||||
|
||||
if pkg.endswith("_SBo"):
|
||||
yield pkg
|
||||
|
|
|
@ -51,14 +51,20 @@ class Requires(BlackList):
|
|||
sys.setrecursionlimit(10000)
|
||||
dependencies = []
|
||||
requires = SBoGrep(name).requires()
|
||||
|
||||
if requires:
|
||||
|
||||
for req in requires:
|
||||
|
||||
# avoids adding %README% as dependency and if
|
||||
# requires in the blacklist
|
||||
if "%README%" not in req and req not in self.blacklist:
|
||||
dependencies.append(req)
|
||||
|
||||
self.deep_check(tuple(dependencies))
|
||||
|
||||
return self.dep_results
|
||||
|
||||
else:
|
||||
return []
|
||||
|
||||
|
|
|
@ -74,11 +74,14 @@ class SBoNetwork(BlackList, Utils):
|
|||
self._SOURCES = self.meta.SBo_SOURCES
|
||||
self.msg.reading()
|
||||
self.case_insensitive()
|
||||
|
||||
if "--checklist" in self.flag:
|
||||
self.with_checklist()
|
||||
|
||||
grep = SBoGrep(self.name)
|
||||
self.sbo_files = grep.files()
|
||||
self.sbo_url = sbo_search_pkg(self.name)
|
||||
|
||||
if self.sbo_url:
|
||||
self.sbo_desc = grep.description()[len(self.name) + 2:-1]
|
||||
self.source_dwn = grep.source().split()
|
||||
|
@ -86,6 +89,7 @@ class SBoNetwork(BlackList, Utils):
|
|||
self.sbo_dwn = SBoLink(self.sbo_url).tar_gz()
|
||||
self.sbo_version = grep.version()
|
||||
self.dwn_srcs = self.sbo_dwn.split() + self.source_dwn
|
||||
|
||||
if "--checklist" not in self.flag or not self.sbo_url and self.name:
|
||||
self.msg.done()
|
||||
|
||||
|
@ -101,8 +105,11 @@ class SBoNetwork(BlackList, Utils):
|
|||
if self.sbo_url and self.name not in self.get_black():
|
||||
self.prgnam = f"{self.name}-{self.sbo_version}"
|
||||
self.view_sbo()
|
||||
|
||||
while True:
|
||||
|
||||
self.read_choice()
|
||||
|
||||
choice = {
|
||||
"r": self.choice_README,
|
||||
"R": self.choice_README,
|
||||
|
@ -128,10 +135,12 @@ class SBoNetwork(BlackList, Utils):
|
|||
"quit": self.choice_quit,
|
||||
"Q": self.choice_quit
|
||||
}
|
||||
|
||||
try:
|
||||
choice[self.choice]()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
else:
|
||||
self.msg.pkg_not_found("\n", self.name, "Can't view", "\n")
|
||||
raise SystemExit(1)
|
||||
|
@ -140,9 +149,12 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""Matching packages distinguish between uppercase and
|
||||
lowercase
|
||||
"""
|
||||
|
||||
if "--case-ins" in self.flag:
|
||||
data_dict = self.case_sensitive(self.data)
|
||||
|
||||
for key, value in data_dict.items():
|
||||
|
||||
if key == self.name.lower():
|
||||
self.name = value
|
||||
|
||||
|
@ -174,11 +186,13 @@ class SBoNetwork(BlackList, Utils):
|
|||
"quit": "quit",
|
||||
"Q": "quit"
|
||||
}
|
||||
|
||||
try:
|
||||
message = " Choose an option > "
|
||||
self.choice = input(f"{self.grey}{message}{self.endc}")
|
||||
except EOFError:
|
||||
raise SystemExit('\n')
|
||||
|
||||
try:
|
||||
print("{0}\x1b[1A{1}{2}{3}\n".format(
|
||||
" " * len(message), self.cyan, commands[self.choice],
|
||||
|
@ -233,15 +247,19 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""Download, build and install the package
|
||||
"""
|
||||
pkg_security([self.name])
|
||||
|
||||
if not find_package(self.prgnam, self.meta.pkg_path):
|
||||
self.build()
|
||||
self.install()
|
||||
delete_folder(self.build_folder)
|
||||
|
||||
raise SystemExit()
|
||||
|
||||
else:
|
||||
self.msg.template(78)
|
||||
self.msg.pkg_found(self.prgnam)
|
||||
self.msg.template(78)
|
||||
|
||||
raise SystemExit()
|
||||
|
||||
def choice_clear_screen(self):
|
||||
|
@ -260,10 +278,12 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""
|
||||
sbo_url = self.sbo_url.replace("/slackbuilds/", "/repository/")
|
||||
br1, br2, fix_sp = "", "", " "
|
||||
|
||||
if self.meta.use_colors in ["off", "OFF"]:
|
||||
br1 = "("
|
||||
br2 = ")"
|
||||
fix_sp = ""
|
||||
|
||||
print() # new line at start
|
||||
self.msg.template(78)
|
||||
print(f"| {' ' * 28}{self.grey}SlackBuilds Repository{self.endc}")
|
||||
|
@ -280,8 +300,10 @@ class SBoNetwork(BlackList, Utils):
|
|||
print(f"| {self.red}R{self.endc}{br2}EADME View the README file")
|
||||
print(f"| {self.red}S{self.endc}{br2}lackBuild View the .SlackBuild file")
|
||||
print(f"| In{br1}{self.red}f{self.endc}{br2}o{fix_sp} View the .info file")
|
||||
|
||||
if "doinst.sh" in self.sbo_files.split():
|
||||
print(f"| D{br1}{self.red}o{self.endc}{br2}inst.sh{fix_sp} View the doinst.sh file")
|
||||
|
||||
print(f"| {self.red}D{self.endc}{br2}ownload Download this package")
|
||||
print(f"| {self.red}B{self.endc}{br2}uild Download and build")
|
||||
print(f"| {self.red}I{self.endc}{br2}nstall Download/Build/Install")
|
||||
|
@ -293,23 +315,29 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""Using dialog and checklist option
|
||||
"""
|
||||
data = []
|
||||
|
||||
if not self.name:
|
||||
data = self.data
|
||||
|
||||
else:
|
||||
for name in self.data:
|
||||
if self.name in name:
|
||||
data.append(name)
|
||||
|
||||
if data:
|
||||
text = "Press 'spacebar' to choose SlackBuild for view"
|
||||
title = " SlackBuilds.org "
|
||||
backtitle = f"{_meta_.__all__} {_meta_.__version__}"
|
||||
status = False
|
||||
pkg = DialogUtil(data, text, title, backtitle, status).checklist()
|
||||
|
||||
if pkg and len(pkg) > 1:
|
||||
os.system("clear")
|
||||
raise SystemExit("\nslpkg: Error: Choose only one package\n")
|
||||
|
||||
if pkg is None:
|
||||
raise SystemExit(1)
|
||||
|
||||
self.name = "".join(pkg)
|
||||
os.system("clear")
|
||||
|
||||
|
@ -326,8 +354,10 @@ class SBoNetwork(BlackList, Utils):
|
|||
lines = sum(1 for line in page.splitlines())
|
||||
diff = rows - lines
|
||||
fill = "\n" * diff
|
||||
|
||||
if diff > 0:
|
||||
return fill
|
||||
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
@ -337,6 +367,7 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""
|
||||
self.FAULT = ""
|
||||
UNST = ["UNSUPPORTED", "UNTESTED"]
|
||||
|
||||
if "".join(self.source_dwn) in UNST:
|
||||
self.FAULT = "".join(self.source_dwn)
|
||||
|
||||
|
@ -345,27 +376,38 @@ class SBoNetwork(BlackList, Utils):
|
|||
"""
|
||||
pkg_security([self.name])
|
||||
self.error_uns()
|
||||
|
||||
if self.FAULT:
|
||||
print()
|
||||
self.msg.template(78)
|
||||
print(f"| Package {self.prgnam} {self.red} {self.FAULT} "
|
||||
f"{self.endc}")
|
||||
self.msg.template(78)
|
||||
|
||||
else:
|
||||
sources = []
|
||||
|
||||
if not os.path.exists(self.meta.build_path):
|
||||
os.makedirs(self.meta.build_path)
|
||||
|
||||
if not os.path.exists(self._SOURCES):
|
||||
os.makedirs(self._SOURCES)
|
||||
|
||||
os.chdir(self.meta.build_path)
|
||||
|
||||
Download(self.meta.build_path, self.sbo_dwn.split(),
|
||||
repo="sbo").start()
|
||||
|
||||
Download(self._SOURCES, self.source_dwn, repo="sbo").start()
|
||||
|
||||
script = self.sbo_dwn.split("/")[-1]
|
||||
|
||||
for src in self.source_dwn:
|
||||
sources.append(src.split("/")[-1])
|
||||
|
||||
BuildPackage(script, sources, self.meta.build_path,
|
||||
auto=False).build()
|
||||
|
||||
slack_package(self.prgnam) # check if build
|
||||
|
||||
def install(self):
|
||||
|
|
|
@ -60,14 +60,18 @@ class QueuePkgs(Utils):
|
|||
"# In this file, you can create a list of\n",
|
||||
"# packages you want to build or install.\n",
|
||||
"#\n"]
|
||||
|
||||
if not os.path.exists(self.meta.lib_path):
|
||||
os.mkdir(self.meta.lib_path)
|
||||
|
||||
if not os.path.exists(self.queue):
|
||||
os.mkdir(self.queue)
|
||||
|
||||
if not os.path.isfile(self.queue_list):
|
||||
with open(self.queue_list, "w") as queue:
|
||||
for line in queue_file:
|
||||
queue.write(line)
|
||||
|
||||
self.queued = self.read_file(self.queue_list)
|
||||
|
||||
def packages(self):
|
||||
|
@ -75,7 +79,9 @@ class QueuePkgs(Utils):
|
|||
file.
|
||||
"""
|
||||
for read in self.queued.splitlines():
|
||||
|
||||
read = read.lstrip()
|
||||
|
||||
if not read.startswith("#"):
|
||||
yield read.replace("\n", "")
|
||||
|
||||
|
@ -83,8 +89,10 @@ class QueuePkgs(Utils):
|
|||
"""Prints packages from queue
|
||||
"""
|
||||
print("Packages in the queue:")
|
||||
|
||||
for pkg in self.packages():
|
||||
print(f"{self.green}{pkg}{self.endc}")
|
||||
|
||||
print()
|
||||
|
||||
def add(self, pkgs):
|
||||
|
@ -92,27 +100,39 @@ class QueuePkgs(Utils):
|
|||
"""
|
||||
queue_list = list(self.packages())
|
||||
pkgs = list(OrderedDict.fromkeys(pkgs))
|
||||
|
||||
print("Add packages in the queue:")
|
||||
|
||||
with open(self.queue_list, "a") as queue:
|
||||
|
||||
for pkg in pkgs:
|
||||
|
||||
find = sbo_search_pkg(pkg)
|
||||
|
||||
if pkg not in queue_list and find is not None:
|
||||
print(f"{self.green}{pkg}{self.endc}")
|
||||
queue.write(pkg + "\n")
|
||||
|
||||
else:
|
||||
print(f"{self.red}{pkg}{self.endc}")
|
||||
|
||||
print()
|
||||
|
||||
def remove(self, pkgs):
|
||||
"""Removes packages from the queue
|
||||
"""
|
||||
print("Remove packages from the queue:")
|
||||
|
||||
with open(self.queue_list, "w") as queue:
|
||||
|
||||
for line in self.queued.splitlines():
|
||||
|
||||
if line not in pkgs:
|
||||
queue.write(line + "\n")
|
||||
|
||||
else:
|
||||
print(f"{self.red}{line}{self.endc}")
|
||||
|
||||
print()
|
||||
|
||||
def build(self):
|
||||
|
@ -120,27 +140,37 @@ class QueuePkgs(Utils):
|
|||
"""
|
||||
sources = []
|
||||
packages = list(self.packages())
|
||||
|
||||
if packages:
|
||||
|
||||
for pkg in packages:
|
||||
|
||||
if pkg not in SBoGrep(pkg).names():
|
||||
raise SystemExit(f"\nPackage '{pkg}' was not found in "
|
||||
f"the SBo repository\n")
|
||||
|
||||
if not os.path.exists(self.meta.build_path):
|
||||
os.mkdir(self.meta.build_path)
|
||||
|
||||
if not os.path.exists(self._SOURCES):
|
||||
os.mkdir(self._SOURCES)
|
||||
|
||||
sbo_url = sbo_search_pkg(pkg)
|
||||
sbo_dwn = SBoLink(sbo_url).tar_gz()
|
||||
source_dwn = SBoGrep(pkg).source().split()
|
||||
os.chdir(self.meta.build_path)
|
||||
script = sbo_dwn.split("/")[-1]
|
||||
|
||||
Download(self.meta.build_path, sbo_dwn.split(),
|
||||
repo="sbo").start()
|
||||
|
||||
for src in source_dwn:
|
||||
Download(self._SOURCES, src.split(), repo="sbo").start()
|
||||
sources.append(src.split("/")[-1])
|
||||
|
||||
BuildPackage(script, sources, self.meta.build_path,
|
||||
auto=False).build()
|
||||
|
||||
else:
|
||||
raise SystemExit("\nPackages not found in the queue for "
|
||||
"building\n")
|
||||
|
@ -149,17 +179,24 @@ class QueuePkgs(Utils):
|
|||
"""Installs packages from the queue
|
||||
"""
|
||||
packages = list(self.packages())
|
||||
|
||||
if packages:
|
||||
|
||||
print() # new line at start
|
||||
|
||||
for pkg in packages:
|
||||
|
||||
ver = SBoGrep(pkg).version()
|
||||
prgnam = f"{pkg}-{ver}"
|
||||
|
||||
if find_package(prgnam, self.meta.output):
|
||||
binary = slack_package(prgnam)
|
||||
PackageManager(binary).upgrade(flag="--install-new")
|
||||
|
||||
else:
|
||||
print(f"\nPackage {prgnam} not found in the "
|
||||
f"{self.meta.output} for installation\n")
|
||||
|
||||
else:
|
||||
raise SystemExit("\nPackages not found in the queue for "
|
||||
"installation\n")
|
||||
|
|
|
@ -40,6 +40,8 @@ class SBoArch:
|
|||
"""
|
||||
if self.arch.startswith("i") and self.arch.endswith("86"):
|
||||
self.arch = self.x86
|
||||
|
||||
elif self.meta.arch.startswith("arm"):
|
||||
self.arch = self.arm
|
||||
|
||||
return self.arch
|
||||
|
|
|
@ -38,16 +38,20 @@ def slack_package(prgnam):
|
|||
TAG, binaries, cache, binary = "_SBo", [], "0", ""
|
||||
|
||||
for exp in os.environ.keys():
|
||||
|
||||
if exp == "TAG":
|
||||
TAG = os.environ["TAG"]
|
||||
break
|
||||
|
||||
for pkg in find_package(prgnam, _meta_.output):
|
||||
|
||||
if pkg.startswith(prgnam) and pkg[:-4].endswith(TAG):
|
||||
binaries.append(pkg)
|
||||
|
||||
for bins in binaries:
|
||||
|
||||
binary = bins
|
||||
|
||||
if parse_version(bins) > parse_version(cache):
|
||||
binary = bins
|
||||
cache = binary
|
||||
|
|
|
@ -99,6 +99,7 @@ class SBoInstall(BlackList, Utils):
|
|||
tagc = ""
|
||||
self.is_upgrade = is_upgrade
|
||||
self.case_insensitive()
|
||||
|
||||
for _sbo in self.slackbuilds:
|
||||
|
||||
if _sbo in self.data and _sbo not in self.blacklist:
|
||||
|
@ -106,6 +107,7 @@ class SBoInstall(BlackList, Utils):
|
|||
self.deps += sbo_deps
|
||||
self.deps_dict[_sbo] = self.one_for_all(sbo_deps)
|
||||
self.package_found.append(_sbo)
|
||||
|
||||
else:
|
||||
self.package_not_found.append(_sbo)
|
||||
|
||||
|
@ -138,6 +140,7 @@ class SBoInstall(BlackList, Utils):
|
|||
else:
|
||||
print("\nThe following packages will be automatically "
|
||||
"installed or upgraded \nwith new version:\n")
|
||||
|
||||
self.top_view()
|
||||
self.msg.upg_inst(self.is_upgrade)
|
||||
|
||||
|
@ -147,6 +150,7 @@ class SBoInstall(BlackList, Utils):
|
|||
name = "-".join(sbo.split("-")[:-1])
|
||||
self.view_packages(tagc, name, sbo.split("-")[-1],
|
||||
self.select_arch(arch))
|
||||
|
||||
self.view_installing_for_deps()
|
||||
|
||||
# view dependencies
|
||||
|
@ -163,6 +167,7 @@ class SBoInstall(BlackList, Utils):
|
|||
print("\nMatching summary")
|
||||
print("=" * 79)
|
||||
raise SystemExit(f"Total {count_total} matching packages\n")
|
||||
|
||||
print("\nInstalling summary")
|
||||
print("=" * 79)
|
||||
print(f"{self.grey}Total {count_total} "
|
||||
|
@ -199,6 +204,7 @@ class SBoInstall(BlackList, Utils):
|
|||
onelist, dependencies = [], []
|
||||
onelist = self.dimensional_list(self.deps)
|
||||
dependencies = self.remove_dbs(onelist)
|
||||
|
||||
for dep in dependencies:
|
||||
deps = Requires(self.flag).sbo(dep)
|
||||
self.deps_dict[dep] = self.one_for_all(deps)
|
||||
|
@ -214,6 +220,7 @@ class SBoInstall(BlackList, Utils):
|
|||
|
||||
if "--download-only" in self.flag:
|
||||
raise SystemExit()
|
||||
|
||||
self.msg.reference(installs, upgraded)
|
||||
write_deps(self.deps_dict)
|
||||
delete_folder(self.build_folder)
|
||||
|
@ -397,6 +404,7 @@ class SBoInstall(BlackList, Utils):
|
|||
|
||||
if "--download-only" in self.flag:
|
||||
continue
|
||||
|
||||
sources = list(self.filenames(src_link))
|
||||
BuildPackage(script, sources, self.build_folder,
|
||||
auto=False).build()
|
||||
|
@ -420,6 +428,7 @@ class SBoInstall(BlackList, Utils):
|
|||
|
||||
else:
|
||||
PackageManager(binary).upgrade(flag="--install-new")
|
||||
|
||||
return installs, upgraded
|
||||
|
||||
def not_downgrade(self, prgnam):
|
||||
|
@ -437,6 +446,7 @@ class SBoInstall(BlackList, Utils):
|
|||
print(f"| Package {name} does not downgrade, "
|
||||
f"setting by user")
|
||||
self.msg.template(78)
|
||||
|
||||
return True
|
||||
|
||||
def sbosrcarsh(self, prgnam, sbo_link, src_link):
|
||||
|
|
Loading…
Add table
Reference in a new issue