Improving code for Python 3

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-01-13 21:32:43 +01:00
parent 9edec1f999
commit 985ac59374
3 changed files with 40 additions and 50 deletions

View file

@ -50,6 +50,9 @@ class QueuePkgs:
"#\n" "#\n"
] ]
self.meta = _meta_ self.meta = _meta_
self.green = _meta_.color["GREEN"]
self.red = _meta_.color["RED"]
self.endc = _meta_.color["ENDC"]
self.quit = False self.quit = False
self.queue = self.meta.lib_path + "queue/" self.queue = self.meta.lib_path + "queue/"
self.queue_list = self.queue + "queue_list" self.queue_list = self.queue + "queue_list"
@ -82,8 +85,7 @@ class QueuePkgs:
print("\nPackages in the queue:\n") print("\nPackages in the queue:\n")
for pkg in self.packages(): for pkg in self.packages():
if pkg: if pkg:
print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, print(f"{self.green}{pkg}{self.endc}")
self.meta.color["ENDC"]))
self.quit = True self.quit = True
if self.quit: if self.quit:
print() # new line at exit print() # new line at exit
@ -98,13 +100,11 @@ class QueuePkgs:
for pkg in pkgs: for pkg in pkgs:
find = sbo_search_pkg(pkg) find = sbo_search_pkg(pkg)
if pkg not in queue_list and find is not None: if pkg not in queue_list and find is not None:
print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, print(f"{self.green}{pkg}{self.endc}")
self.meta.color["ENDC"]))
queue.write(pkg + "\n") queue.write(pkg + "\n")
self.quit = True self.quit = True
else: else:
print("{0}{1}{2}".format(self.meta.color["RED"], pkg, print(f"{self.red}{pkg}{self.endc}")
self.meta.color["ENDC"]))
self.quit = True self.quit = True
queue.close() queue.close()
if self.quit: if self.quit:
@ -119,8 +119,7 @@ class QueuePkgs:
if line not in pkgs: if line not in pkgs:
queue.write(line + "\n") queue.write(line + "\n")
else: else:
print("{0}{1}{2}".format(self.meta.color["RED"], line, print(f"{self.red}{line}{self.endc}")
self.meta.color["ENDC"]))
self.quit = True self.quit = True
queue.close() queue.close()
if self.quit: if self.quit:
@ -161,13 +160,13 @@ class QueuePkgs:
print() # new line at start print() # new line at start
for pkg in packages: for pkg in packages:
ver = SBoGrep(pkg).version() ver = SBoGrep(pkg).version()
prgnam = "{0}-{1}".format(pkg, ver) prgnam = f"{pkg}-{ver}"
if find_package(prgnam, self.meta.output): if find_package(prgnam, self.meta.output):
binary = slack_package(prgnam) binary = slack_package(prgnam)
PackageManager(binary).upgrade(flag="--install-new") PackageManager(binary).upgrade(flag="--install-new")
else: else:
print("\nPackage {0} not found in the {1} for " print(f"\nPackage {prgnam} not found in the {self.meta.output} for "
"installation\n".format(prgnam, self.meta.output)) f"installation\n")
else: else:
print("\nPackages not found in the queue for installation\n") print("\nPackages not found in the queue for installation\n")
raise SystemExit(1) raise SystemExit(1)

View file

@ -34,7 +34,7 @@ def sbo_search_pkg(name):
return url return url
""" """
repo = Repo().default_repository()["sbo"] repo = Repo().default_repository()["sbo"]
sbo_url = "{0}{1}/".format(repo, slack_ver()) sbo_url = f"{repo}{slack_ver()}/"
SLACKBUILDS_TXT = Utils().read_file( SLACKBUILDS_TXT = Utils().read_file(
_meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT") _meta_.lib_path + "sbo_repo/SLACKBUILDS.TXT")
for line in SLACKBUILDS_TXT.splitlines(): for line in SLACKBUILDS_TXT.splitlines():

View file

@ -57,6 +57,10 @@ class SBoInstall:
pkg_security(self.slackbuilds) pkg_security(self.slackbuilds)
self.flag = flag self.flag = flag
self.meta = _meta_ self.meta = _meta_
self.green = _meta_.color["GREEN"]
self.yellow = _meta_.color["YELLOW"]
self.grey = _meta_.color["GREY"]
self.endc = _meta_.color["ENDC"]
self.msg = Msg() self.msg = Msg()
self.arch = SBoArch().get() self.arch = SBoArch().get()
self.build_folder = self.meta.build_path self.build_folder = self.meta.build_path
@ -145,19 +149,15 @@ class SBoInstall:
if self.match and [""] != self.slackbuilds: if self.match and [""] != self.slackbuilds:
print("\nMatching summary") print("\nMatching summary")
print("=" * 79) print("=" * 79)
print("Total {0} matching packages\n".format(count_total)) print(f"Total {count_total} matching packages\n")
raise SystemExit(1) raise SystemExit(1)
print("\nInstalling summary") print("\nInstalling summary")
print("=" * 79) print("=" * 79)
print("{0}Total {1} {2}.".format( print(f"{self.grey}Total {count_total} {self.msg.pkg(count_total)}.")
self.meta.color["GREY"], count_total, print(f"{self.count_uni} {self.msg.pkg(self.count_uni)} will be installed, "
self.msg.pkg(count_total))) f"{self.count_ins} already installed and "
print("{0} {1} will be installed, {2} already installed and " f"{self.count_upg} {self.msg.pkg(self.count_upg)}")
"{3} {4}".format(self.count_uni, print(f"will be upgraded.{self.endc}\n")
self.msg.pkg(self.count_uni),
self.count_ins, self.count_upg,
self.msg.pkg(self.count_upg)))
print("will be upgraded.{0}\n".format(self.meta.color["ENDC"]))
self.continue_to_install() self.continue_to_install()
else: else:
self.msg.not_found(self.is_upgrade) self.msg.not_found(self.is_upgrade)
@ -227,7 +227,7 @@ class SBoInstall:
sbo_versions, sources = [], [] sbo_versions, sources = [], []
for sbo in slackbuilds: for sbo in slackbuilds:
status(0.02) status(0.02)
sbo_ver = "{0}-{1}".format(sbo, SBoGrep(sbo).version()) sbo_ver = f"{sbo}-{SBoGrep(sbo).version()}"
sbo_versions.append(sbo_ver) sbo_versions.append(sbo_ver)
sources.append(SBoGrep(sbo).source()) sources.append(SBoGrep(sbo).source())
return [sbo_versions, sources] return [sbo_versions, sources]
@ -250,13 +250,12 @@ class SBoInstall:
"""View top template """View top template
""" """
self.msg.template(78) self.msg.template(78)
print("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}".format( print(f"| Packages{' ' * 16}"
"| Package", " " * 17, f"New version{' ' * 8}"
"New version", " " * 8, f"Arch{' ' * 4}"
"Arch", " " * 4, f"Build{' ' * 2}"
"Build", " " * 2, f"Repos{' ' * 10}"
"Repos", " " * 10, f"Size")
"Size"))
self.msg.template(78) self.msg.template(78)
def view_packages(self, *args): def view_packages(self, *args):
@ -267,12 +266,11 @@ class SBoInstall:
args[3] arch args[3] arch
""" """
ver = GetFromInstalled(args[1]).version() ver = GetFromInstalled(args[1]).version()
print(" {0}{1}{2}{3} {4}{5} {6}{7}{8}{9}{10}{11:>11}{12}".format( print(f" {args[0]}{args[1] + ver}{self.endc} "
args[0], args[1] + ver, self.meta.color["ENDC"], f"{' ' * (23-len(args[1] + ver))}{args[2]}"
" " * (23-len(args[1] + ver)), args[2], f"{' ' * (18-len(args[2]))} {args[3]}"
" " * (18-len(args[2])), args[3], f"{' ' * (15-len(args[3]))}{''}"
" " * (15-len(args[3])), "", f"{''}SBo{''}{'':>11}{''}")
"", "SBo", "", "").rstrip())
def tag(self, sbo): def tag(self, sbo):
"""Tag with color green if package already installed, """Tag with color green if package already installed,
@ -337,9 +335,7 @@ class SBoInstall:
self.msg.template(78) self.msg.template(78)
elif self.unst[0] in src_link or self.unst[1] in src_link: elif self.unst[0] in src_link or self.unst[1] in src_link:
self.msg.template(78) self.msg.template(78)
print("| Package {0} {1}{2}{3}".format( print(f"| Package {prgnam} {self.red}{''.join(src_link)}{self.endc}")
prgnam, self.meta.color["RED"], "".join(src_link),
self.meta.color["ENDC"]))
self.msg.template(78) self.msg.template(78)
else: else:
sbo_url = sbo_search_pkg(pkg) sbo_url = sbo_search_pkg(pkg)
@ -358,14 +354,10 @@ class SBoInstall:
binary = slack_package(prgnam) binary = slack_package(prgnam)
if os.path.isfile("".join(binary)): if os.path.isfile("".join(binary)):
if GetFromInstalled(pkg).name() == pkg: if GetFromInstalled(pkg).name() == pkg:
print("[ {0}Upgrading{1} ] --> {2}".format( print(f"[ {self.yellow}Upgrading{self.endc} ] --> {prgnam}")
self.meta.color["YELLOW"],
self.meta.color["ENDC"], prgnam))
upgraded.append(prgnam) upgraded.append(prgnam)
else: else:
print("[ {0}Installing{1} ] --> {2}".format( print(f"[ {self.green}Installing{self.endc} ] --> {prgnam}")
self.meta.color["GREEN"],
self.meta.color["ENDC"], prgnam))
installs.append(prgnam) installs.append(prgnam)
if ("--rebuild" in self.flag and if ("--rebuild" in self.flag and
GetFromInstalled(pkg).name() == pkg): GetFromInstalled(pkg).name() == pkg):
@ -384,8 +376,8 @@ class SBoInstall:
ins_ver = "0" ins_ver = "0"
if parse_version(sbo_ver) < parse_version(ins_ver): if parse_version(sbo_ver) < parse_version(ins_ver):
self.msg.template(78) self.msg.template(78)
print("| Package {0} don't downgrade, " print(f"| Package {name} don't downgrade, "
"setting by user".format(name)) f"setting by user")
self.msg.template(78) self.msg.template(78)
return True return True
@ -393,9 +385,8 @@ class SBoInstall:
"""Alternative repository for sbo sources""" """Alternative repository for sbo sources"""
sources = [] sources = []
name = "-".join(prgnam.split("-")[:-1]) name = "-".join(prgnam.split("-")[:-1])
category = "{0}/{1}/".format(sbo_link.split("/")[-2], name) category = f"{sbo_link.split('/')[-2]}/{name}/"
for link in src_link: for link in src_link:
source = link.split("/")[-1] source = link.split("/")[-1]
sources.append("{0}{1}{2}".format(self.meta.sbosrcarch_link, sources.append(f"{self.meta.sbosrcarch_link}{category}{source}")
category, source))
return sources return sources