diff --git a/slpkg/__metadata__.py b/slpkg/__metadata__.py index 0b0bb668..fd8d3d71 100644 --- a/slpkg/__metadata__.py +++ b/slpkg/__metadata__.py @@ -40,7 +40,7 @@ def update_repositories(repositories, conf_path): """ Upadate with user custom repositories """ - repo_file = "{0}custom-repositories".format(conf_path) + repo_file = f"{conf_path}custom-repositories" if os.path.isfile(repo_file): f = open(repo_file, "r") repositories_list = f.read() @@ -90,11 +90,11 @@ class MetaData: slack_rel = "stable" # Configuration path - conf_path = "/etc/{0}/".format(__all__) + conf_path = f"/etc/{__all__}/" # tmp paths tmp = "/tmp/" - tmp_path = "{0}{1}/".format(tmp, __all__) + tmp_path = f"{tmp}{__all__}/" # Default configuration values _conf_slpkg = { @@ -138,8 +138,8 @@ class MetaData: # read value from configuration file repositories = [] for files in ["slpkg.conf", "repositories.conf"]: - if os.path.isfile("%s%s" % (conf_path, files)): - f = open("%s%s" % (conf_path, files), "r") + if os.path.isfile(f"{conf_path}{files}"): + f = open(f"{conf_path}{files}", "r") conf = f.read() f.close() for line in conf.splitlines(): @@ -217,8 +217,8 @@ class MetaData: "ENDC": "" } - CHECKSUMS_link = ("https://gitlab.com/{0}/{1}/raw/" - "master/CHECKSUMS.md5".format(__author__, __all__)) + CHECKSUMS_link = (f"https://gitlab.com/{__author__}/{__all__}/raw/" + "master/CHECKSUMS.md5") # file spacer sp = "-" diff --git a/slpkg/arguments.py b/slpkg/arguments.py index c88907bf..75e972fd 100644 --- a/slpkg/arguments.py +++ b/slpkg/arguments.py @@ -30,8 +30,7 @@ from slpkg.slack.slack_version import slack_ver def header(): """help header message""" - print("\nslpkg - version {0} | Slackware release: {1} - {2}\n".format( - _meta_.__version__, _meta_.slack_rel, slack_ver())) + print(f"\nslpkg - version {_meta_.__version__} | Slackware release: {_meta_.slack_rel} - {slack_ver()}\n") def options(): @@ -220,11 +219,11 @@ def usage(repo): all_repos = RepoList().all_repos.keys() del RepoList().all_repos if repo in all_repos: - error_repo = ("slpkg: Error: Repository '{0}' is not activated" - "\n".format(repo)) + error_repo = (f"slpkg: Error: Repository '{repo}' is not activated" + "\n") else: - error_repo = ("slpkg: Error: Repository '{0}' does not exist" - "\n".format(repo)) + error_repo = (f"slpkg: Error: Repository '{repo}' does not exist" + "\n") print("\n" + error_repo) raise SystemExit(1) print(usage.__doc__) diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py index 8aba4190..698dad61 100644 --- a/slpkg/auto_pkg.py +++ b/slpkg/auto_pkg.py @@ -22,8 +22,6 @@ # along with this program. If not, see . -import sys - from slpkg.messages import Msg from slpkg.__metadata__ import MetaData as _meta_ @@ -36,6 +34,10 @@ class Auto: def __init__(self, packages): self.packages = packages self.meta = _meta_ + self.green = _meta_.color["GREEN"] + self.red = _meta_.color["RED"] + self.cyan = _meta_.color["CYAN"] + self.endc = _meta_.color["ENDC"] self.msg = Msg() self.commands = { "i": "installpkg", @@ -54,10 +56,7 @@ class Auto: print("| Choose a Slackware command:") self.msg.template(78) for com in sorted(self.commands): - print("| {0}{1}{2}) {3}{4}{5}".format( - self.meta.color["RED"], com, self.meta.color["ENDC"], - self.meta.color["GREEN"], self.commands[com], - self.meta.color["ENDC"])) + print(f"| {self.red}{com}{self.endc}) {self.green}{self.commands[com]}{self.endc}") self.msg.template(78) try: self.choice = input(" > ") @@ -65,9 +64,7 @@ class Auto: print() raise SystemExit() if self.choice in self.commands.keys(): - print(" \x1b[1A{0}{1}{2}\n\n".format( - self.meta.color["CYAN"], self.commands[self.choice], - self.meta.color["ENDC"]), end="") + print(f" \x1b[1A{self.cyan}{self.commands[self.choice]}{self.endc}", end="\n\n") print(end="", flush=True) self.execute() diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index f6c6ff5b..59eb4058 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -33,8 +33,10 @@ class BlackList: """Blacklist class to add, remove or listed packages in blacklist file.""" def __init__(self): - self.meta = _meta_ self.quit = False + self.green = _meta_.color["GREEN"] + self.red = _meta_.color["RED"] + self.endc = _meta_.color["ENDC"] self.blackfile = "/etc/slpkg/blacklist" self.black_conf = "" if os.path.isfile(self.blackfile): @@ -56,8 +58,7 @@ class BlackList: print("\nPackages in the blacklist:\n") for black in self.get_black(): if black: - print("{0}{1}{2}".format(self.meta.color["GREEN"], black, - self.meta.color["ENDC"])) + print(f"{self.green}{black}{self.endc}") self.quit = True if self.quit: print() # new line at exit @@ -71,8 +72,7 @@ class BlackList: with open(self.blackfile, "a") as black_conf: for pkg in pkgs: if pkg not in blacklist: - print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg, - self.meta.color["ENDC"])) + print(f"{self.green}{pkg}{self.endc}") black_conf.write(pkg + "\n") self.quit = True black_conf.close() @@ -88,8 +88,7 @@ class BlackList: if line not in pkgs: remove.write(line + "\n") else: - print("{0}{1}{2}".format(self.meta.color["RED"], line, - self.meta.color["ENDC"])) + print(f"{self.red}{line}{self.endc}") self.quit = True remove.close() if self.quit: