Improving code for Python 3

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-01-13 18:57:47 +01:00
parent 40f06a0075
commit 9edec1f999
11 changed files with 52 additions and 90 deletions

View file

@ -140,5 +140,4 @@ Keys: SPACE select or deselect the highlighted repositories,
print(f"| {total_enabled}")
self.msg.template(78)
print(f"{self.grey}Total {len(self.selected)}/{len(self.enabled + self.disabled)} "
f"repositories enabled.{self.endc}\n")
#.format(self.meta.color["GREY"], len(self.selected), len(self.enabled + self.disabled), self.meta.color["ENDC"]))
f"repositories enabled.{self.endc}\n")

View file

@ -35,6 +35,9 @@ class RepoInfo:
"""Repository information
"""
def __init__(self):
self.green = _meta_.color["GREEN"]
self.red = _meta_.color["RED"]
self.endc = _meta_.color["ENDC"]
self.form = {
"Last updated:": "",
"Number of packages:": "",
@ -55,17 +58,14 @@ class RepoInfo:
"""
View repository information
"""
status = "{0}disabled{1}".format(self.meta.color["RED"],
self.meta.color["ENDC"])
status = f"{self.red}disabled{self.endc}"
self.form["Status:"] = status
self.form["Default:"] = "no"
if repo in self.meta.default_repositories:
self.form["Default:"] = "yes"
if (repo in self.meta.repositories and
os.path.isfile(self.meta.lib_path + "{0}_repo/PACKAGES."
"TXT".format(repo))):
status = "{0}enabled{1}".format(self.meta.color["GREEN"],
self.meta.color["ENDC"])
os.path.isfile(self.meta.lib_path + f"{repo}_repo/PACKAGES.TXT")):
status = f"{self.green}enabled{self.endc}"
if repo != "sbo":
data = self.repository_data(repo)
size = units(data[1], data[2])

View file

@ -68,6 +68,5 @@ class AutoBuild:
raise SystemExit()
for src in self.sources:
if not os.path.isfile(self.path + src):
print("\nslpkg: Error: Source file '{0}' not found\n".format(
src))
print(f"\nslpkg: Error: Source file '{src}' not found\n")
raise SystemExit()

View file

@ -40,11 +40,9 @@ class BuildNumber:
def get(self):
num = "NO_BUILD"
if self.sbo_url:
SlackBuild = URL("{0}{1}.SlackBuild".format(
self.sbo_url, self.pkg)).reading()
SlackBuild = URL(f"{self.sbo_url}{self.pkg}.SlackBuild").reading()
else:
SlackBuild = Utils().read_file("{0}{1}/{2}.SlackBuild".format(
self.meta.build_path, self.pkg, self.pkg))
SlackBuild = Utils().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

@ -47,8 +47,8 @@ def sbo_upgrade(skip, flag):
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 = ("{0}-{1}".format(name, SBoGrep(name).version()))
package = ("{0}-{1}".format(name, ver))
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()

View file

@ -36,11 +36,11 @@ class SBoGrep:
self.line_name = "SLACKBUILD NAME: "
self.line_files = "SLACKBUILD FILES: "
self.line_down = "SLACKBUILD DOWNLOAD: "
self.line_down_64 = "SLACKBUILD DOWNLOAD_{0}: ".format(arch64)
self.line_down_64 = f"SLACKBUILD DOWNLOAD_{arch64}: "
self.line_req = "SLACKBUILD REQUIRES: "
self.line_ver = "SLACKBUILD VERSION: "
self.line_md5 = "SLACKBUILD MD5SUM: "
self.line_md5_64 = "SLACKBUILD MD5SUM_{0}: ".format(arch64)
self.line_md5_64 = f"SLACKBUILD MD5SUM_{arch64}: "
self.line_des = "SLACKBUILD SHORT DESCRIPTION: "
self.sbo_txt = self.meta.lib_path + "sbo_repo/SLACKBUILDS.TXT"
self.answer = ["y", "Y"]

View file

@ -94,7 +94,7 @@ class SBoNetwork:
from slackbuilds.org
"""
if self.sbo_url and self.name not in self.blacklist:
self.prgnam = ("{0}-{1}".format(self.name, self.sbo_version))
self.prgnam = f"{self.name}-{self.sbo_version}"
self.view_sbo()
while True:
self.read_choice()
@ -147,10 +147,10 @@ class SBoNetwork:
commands = {
"r": "README",
"R": "README",
"s": "{0}.SlackBuild".format(self.name),
"S": "{0}.SlackBuild".format(self.name),
"f": "{0}.info".format(self.name),
"F": "{0}.info".format(self.name),
"s": f"{self.name}.SlackBuild",
"S": f"{self.name}.SlackBuild",
"f": f"{self.name}.info",
"F": f"{self.name}.info",
"o": "doinst.sh",
"O": "doinst.sh",
"d": "download",
@ -171,8 +171,7 @@ class SBoNetwork:
}
try:
message = " Choose an option > "
self.choice = input("{0}{1}{2}".format(self.grey, message,
self.endc))
self.choice = input(f"{self.grey}{message}{self.endc}")
except EOFError:
print()
raise SystemExit()
@ -263,49 +262,27 @@ class SBoNetwork:
fix_sp = ""
print() # new line at start
self.msg.template(78)
print("| {0}{1}SlackBuilds Repository{2}".format(" " * 28, self.grey,
self.endc))
print(f"| {' ' * 28}{self.grey}SlackBuilds Repository{self.endc}")
self.msg.template(78)
print("| {0} > {1} > {2}{3}{4}".format(slack_ver(),
sbo_url.split("/")[-3].title(),
self.cyan, self.name,
self.endc))
print(f"| {slack_ver()} > {sbo_url.split('/')[-3].title()} > {self.cyan}{self.name}{self.endc}")
self.msg.template(78)
print("| {0}Package url{1}: {2}".format(self.green, self.endc,
sbo_url))
print(f"| {self.green}Package url{self.endc}: {sbo_url}")
self.msg.template(78)
print("| {0}Description: {1}{2}".format(self.green,
self.endc, self.sbo_desc))
print("| {0}SlackBuild: {1}{2}".format(self.green, self.endc,
self.sbo_dwn.split("/")[-1]))
print("| {0}Sources: {1}{2}".format(
self.green, self.endc,
(", ".join([src.split("/")[-1] for src in self.source_dwn]))))
print("| {0}Requirements: {1}{2}".format(self.yellow,
self.endc,
", ".join(self.sbo_req)))
print(f"| {self.green}Description: {self.endc}{self.sbo_desc}")
print(f"| {self.green}SlackBuild: {self.endc}{self.sbo_dwn.split('/')[-1]}")
print(f"| {self.green}Sources: {self.endc}{', '.join([src.split('/')[-1] for src in self.source_dwn])}")
print(f"| {self.yellow}Requirements: {self.endc}{', '.join(self.sbo_req)}")
self.msg.template(78)
print("| {0}R{1}{2}EADME View the README file".format(
self.red, self.endc, br2))
print("| {0}S{1}{2}lackBuild View the .SlackBuild "
"file".format(self.red, self.endc, br2))
print("| In{0}{1}f{2}{3}o{4} View the .info "
"file".format(br1, self.red, self.endc, br2, fix_sp))
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("| D{0}{1}o{2}{3}inst.sh{4} View the doinst.sh "
"file".format(br1, self.red, self.endc, br2, fix_sp))
print("| {0}D{1}{2}ownload Download this package".format(
self.red, self.endc, br2))
print("| {0}B{1}{2}uild Download and build".format(
self.red, self.endc, br2))
print("| {0}I{1}{2}nstall Download/Build/Install".format(
self.red, self.endc, br2))
print("| {0}C{1}{2}lear Clear screen".format(self.red,
self.endc,
br2))
print("| {0}Q{1}{2}uit Quit".format(self.red,
self.endc, br2))
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")
print(f"| {self.red}C{self.endc}{br2}lear Clear screen")
print(f"| {self.red}Q{self.endc}{br2}uit Quit")
self.msg.template(78)
def with_checklist(self):
@ -321,7 +298,7 @@ class SBoNetwork:
if data:
text = "Press 'spacebar' to choose SlackBuild for view"
title = " SlackBuilds.org "
backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__)
backtitle = f"{_meta_.__all__} {_meta_.__version__}"
status = False
pkg = DialogUtil(data, text, title, backtitle, status).checklist()
if pkg and len(pkg) > 1:
@ -367,8 +344,7 @@ class SBoNetwork:
if self.FAULT:
print()
self.msg.template(78)
print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red,
self.FAULT, self.endc))
print(f"| Package {self.prgnam} {self.red} {self.FAULT} {self.endc}")
self.msg.template(78)
else:
sources = []
@ -391,6 +367,5 @@ class SBoNetwork:
"""Install SBo package found in /tmp directory.
"""
binary = slack_package(self.prgnam)
print("[ {0}Installing{1} ] --> {2}".format(self.green, self.endc,
self.name))
print(f"[ {self.green}Installing{self.endc} ] --> {self.name}")
PackageManager(binary).upgrade(flag="--install-new")

View file

@ -34,7 +34,6 @@ def status(sec):
if _meta_.prg_bar in ["on", "ON"]:
syms = ["|", "/", "-", "\\"]
for sym in syms:
print("\b{0}{1}{2}".format(_meta_.color["GREY"], sym,
_meta_.color["ENDC"]), end="")
print(f"\b{_meta_.color['GREY']}{sym}{_meta_.color['ENDC']}", end="")
print(end="", flush=True)
time.sleep(float(sec))

View file

@ -81,20 +81,16 @@ class TrackingDeps:
pkg_len = len(self.name) + 24
print() # new line at start
self.msg.template(pkg_len)
print("| Package {0}{1}{2} dependencies :".format(
self.cyan, self.name, self.endc))
print(f"| Package {self.cyan}{self.name}{self.endc} dependencies :")
self.msg.template(pkg_len)
print("\\")
print(" +---{0}[ Tree of dependencies ]{1}".format(self.yellow,
self.endc))
print(f" +---{self.yellow}[ Tree of dependencies ]{self.endc}")
index = 0
for pkg in self.dependencies:
if "--check-deps" in self.flag:
used = self.check_used(pkg)
self.deps_used(pkg, used)
used = "{0} {1}{2}{3}".format(
"is dependence on -->", self.cyan,
", ".join(used), self.endc)
used = f"is dependence on --> {self.cyan}{', '.join(used)}{self.endc}"
else:
used = ""
index += 1
@ -103,14 +99,10 @@ class TrackingDeps:
if self.meta.use_colors in ["off", "OFF"]:
installed = "* "
print(" |")
print(" {0}{1}: {2}{3}{4} {5}{6}".format(
"+--", index, self.green, pkg,
self.endc, installed, used))
print(f" +--{index}: {self.green}{pkg}{self.endc} {installed}{used}")
else:
print(" |")
print(" {0}{1}: {2}{3}{4} {5}".format(
"+--", index, self.red, pkg,
self.endc, installed))
print(f" +--{index}: {self.red}{pkg}{self.endc} {installed}")
if self.meta.use_colors in ["off", "OFF"]:
print("\n * = Installed\n")
else:
@ -132,7 +124,7 @@ class TrackingDeps:
self.dependencies_list = Requires(self.flag).sbo(self.name)
else:
PACKAGES_TXT = Utils().read_file(
self.meta.lib_path + "{0}_repo/PACKAGES.TXT".format(self.repo))
self.meta.lib_path + f"{self.repo}_repo/PACKAGES.TXT")
self.names = Utils().package_name(PACKAGES_TXT)
self.bin_case_insensitive()
self.find_pkg = search_pkg(self.name, self.repo)

View file

@ -31,19 +31,19 @@ from slpkg.pkg.installed import GetFromInstalled
def choose_upg(packages):
"""Create checklist to choose packages for upgrade
"""Creating checklist to choose packages for upgrade
"""
selected_packages, data = [], []
if packages:
for pkg in packages:
name = GetFromInstalled(pkg).name()
ver = GetFromInstalled(pkg).version()
binary = "{0}{1}".format(name, ver)
binary = f"{name}{ver}"
installed = find_package(binary + _meta_.sp, _meta_.pkg_path)[0]
data.append(installed)
text = "Press 'spacebar' to unchoose packages from upgrade"
title = " Upgrade "
backtitle = "{0} {1}".format(_meta_.__all__, _meta_.__version__)
backtitle = f"{_meta_.__all__} {_meta_.__version__}"
status = True
pkgs = DialogUtil(data, text, title, backtitle,
status).checklist()

View file

@ -33,6 +33,8 @@ class URL:
def __init__(self, link):
self.link = link
self.meta = _meta_
self.red = _meta_.color["RED"]
self.endc = _meta_.color["ENDC"]
self.http = urllib3.PoolManager()
def reading(self):
@ -42,7 +44,5 @@ class URL:
f = self.http.request('GET', self.link)
return f.data.decode("utf-8", "ignore")
except urllib3.exceptions.NewConnectionError:
print("\n{0}Can't read the file '{1}'{2}".format(
self.meta.color["RED"], self.link.split("/")[-1],
self.meta.color["ENDC"]))
print(f"\n{self.red}Can't read the file '{self.link.split('/')[-1]}'{self.endc}")
return " "