mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Improving code for Python 3
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
parent
a3605544f6
commit
be3025797e
4 changed files with 24 additions and 29 deletions
|
@ -40,7 +40,7 @@ def update_repositories(repositories, conf_path):
|
||||||
"""
|
"""
|
||||||
Upadate with user custom repositories
|
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):
|
if os.path.isfile(repo_file):
|
||||||
f = open(repo_file, "r")
|
f = open(repo_file, "r")
|
||||||
repositories_list = f.read()
|
repositories_list = f.read()
|
||||||
|
@ -90,11 +90,11 @@ class MetaData:
|
||||||
slack_rel = "stable"
|
slack_rel = "stable"
|
||||||
|
|
||||||
# Configuration path
|
# Configuration path
|
||||||
conf_path = "/etc/{0}/".format(__all__)
|
conf_path = f"/etc/{__all__}/"
|
||||||
|
|
||||||
# tmp paths
|
# tmp paths
|
||||||
tmp = "/tmp/"
|
tmp = "/tmp/"
|
||||||
tmp_path = "{0}{1}/".format(tmp, __all__)
|
tmp_path = f"{tmp}{__all__}/"
|
||||||
|
|
||||||
# Default configuration values
|
# Default configuration values
|
||||||
_conf_slpkg = {
|
_conf_slpkg = {
|
||||||
|
@ -138,8 +138,8 @@ class MetaData:
|
||||||
# read value from configuration file
|
# read value from configuration file
|
||||||
repositories = []
|
repositories = []
|
||||||
for files in ["slpkg.conf", "repositories.conf"]:
|
for files in ["slpkg.conf", "repositories.conf"]:
|
||||||
if os.path.isfile("%s%s" % (conf_path, files)):
|
if os.path.isfile(f"{conf_path}{files}"):
|
||||||
f = open("%s%s" % (conf_path, files), "r")
|
f = open(f"{conf_path}{files}", "r")
|
||||||
conf = f.read()
|
conf = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
for line in conf.splitlines():
|
for line in conf.splitlines():
|
||||||
|
@ -217,8 +217,8 @@ class MetaData:
|
||||||
"ENDC": ""
|
"ENDC": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECKSUMS_link = ("https://gitlab.com/{0}/{1}/raw/"
|
CHECKSUMS_link = (f"https://gitlab.com/{__author__}/{__all__}/raw/"
|
||||||
"master/CHECKSUMS.md5".format(__author__, __all__))
|
"master/CHECKSUMS.md5")
|
||||||
|
|
||||||
# file spacer
|
# file spacer
|
||||||
sp = "-"
|
sp = "-"
|
||||||
|
|
|
@ -30,8 +30,7 @@ from slpkg.slack.slack_version import slack_ver
|
||||||
|
|
||||||
def header():
|
def header():
|
||||||
"""help header message"""
|
"""help header message"""
|
||||||
print("\nslpkg - version {0} | Slackware release: {1} - {2}\n".format(
|
print(f"\nslpkg - version {_meta_.__version__} | Slackware release: {_meta_.slack_rel} - {slack_ver()}\n")
|
||||||
_meta_.__version__, _meta_.slack_rel, slack_ver()))
|
|
||||||
|
|
||||||
|
|
||||||
def options():
|
def options():
|
||||||
|
@ -220,11 +219,11 @@ def usage(repo):
|
||||||
all_repos = RepoList().all_repos.keys()
|
all_repos = RepoList().all_repos.keys()
|
||||||
del RepoList().all_repos
|
del RepoList().all_repos
|
||||||
if repo in all_repos:
|
if repo in all_repos:
|
||||||
error_repo = ("slpkg: Error: Repository '{0}' is not activated"
|
error_repo = (f"slpkg: Error: Repository '{repo}' is not activated"
|
||||||
"\n".format(repo))
|
"\n")
|
||||||
else:
|
else:
|
||||||
error_repo = ("slpkg: Error: Repository '{0}' does not exist"
|
error_repo = (f"slpkg: Error: Repository '{repo}' does not exist"
|
||||||
"\n".format(repo))
|
"\n")
|
||||||
print("\n" + error_repo)
|
print("\n" + error_repo)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
print(usage.__doc__)
|
print(usage.__doc__)
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from slpkg.messages import Msg
|
from slpkg.messages import Msg
|
||||||
from slpkg.__metadata__ import MetaData as _meta_
|
from slpkg.__metadata__ import MetaData as _meta_
|
||||||
|
|
||||||
|
@ -36,6 +34,10 @@ class Auto:
|
||||||
def __init__(self, packages):
|
def __init__(self, packages):
|
||||||
self.packages = packages
|
self.packages = packages
|
||||||
self.meta = _meta_
|
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.msg = Msg()
|
||||||
self.commands = {
|
self.commands = {
|
||||||
"i": "installpkg",
|
"i": "installpkg",
|
||||||
|
@ -54,10 +56,7 @@ class Auto:
|
||||||
print("| Choose a Slackware command:")
|
print("| Choose a Slackware command:")
|
||||||
self.msg.template(78)
|
self.msg.template(78)
|
||||||
for com in sorted(self.commands):
|
for com in sorted(self.commands):
|
||||||
print("| {0}{1}{2}) {3}{4}{5}".format(
|
print(f"| {self.red}{com}{self.endc}) {self.green}{self.commands[com]}{self.endc}")
|
||||||
self.meta.color["RED"], com, self.meta.color["ENDC"],
|
|
||||||
self.meta.color["GREEN"], self.commands[com],
|
|
||||||
self.meta.color["ENDC"]))
|
|
||||||
self.msg.template(78)
|
self.msg.template(78)
|
||||||
try:
|
try:
|
||||||
self.choice = input(" > ")
|
self.choice = input(" > ")
|
||||||
|
@ -65,9 +64,7 @@ class Auto:
|
||||||
print()
|
print()
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
if self.choice in self.commands.keys():
|
if self.choice in self.commands.keys():
|
||||||
print(" \x1b[1A{0}{1}{2}\n\n".format(
|
print(f" \x1b[1A{self.cyan}{self.commands[self.choice]}{self.endc}", end="\n\n")
|
||||||
self.meta.color["CYAN"], self.commands[self.choice],
|
|
||||||
self.meta.color["ENDC"]), end="")
|
|
||||||
print(end="", flush=True)
|
print(end="", flush=True)
|
||||||
self.execute()
|
self.execute()
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,10 @@ class BlackList:
|
||||||
"""Blacklist class to add, remove or listed packages
|
"""Blacklist class to add, remove or listed packages
|
||||||
in blacklist file."""
|
in blacklist file."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.meta = _meta_
|
|
||||||
self.quit = False
|
self.quit = False
|
||||||
|
self.green = _meta_.color["GREEN"]
|
||||||
|
self.red = _meta_.color["RED"]
|
||||||
|
self.endc = _meta_.color["ENDC"]
|
||||||
self.blackfile = "/etc/slpkg/blacklist"
|
self.blackfile = "/etc/slpkg/blacklist"
|
||||||
self.black_conf = ""
|
self.black_conf = ""
|
||||||
if os.path.isfile(self.blackfile):
|
if os.path.isfile(self.blackfile):
|
||||||
|
@ -56,8 +58,7 @@ class BlackList:
|
||||||
print("\nPackages in the blacklist:\n")
|
print("\nPackages in the blacklist:\n")
|
||||||
for black in self.get_black():
|
for black in self.get_black():
|
||||||
if black:
|
if black:
|
||||||
print("{0}{1}{2}".format(self.meta.color["GREEN"], black,
|
print(f"{self.green}{black}{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
|
||||||
|
@ -71,8 +72,7 @@ class BlackList:
|
||||||
with open(self.blackfile, "a") as black_conf:
|
with open(self.blackfile, "a") as black_conf:
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
if pkg not in blacklist:
|
if pkg not in blacklist:
|
||||||
print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
|
print(f"{self.green}{pkg}{self.endc}")
|
||||||
self.meta.color["ENDC"]))
|
|
||||||
black_conf.write(pkg + "\n")
|
black_conf.write(pkg + "\n")
|
||||||
self.quit = True
|
self.quit = True
|
||||||
black_conf.close()
|
black_conf.close()
|
||||||
|
@ -88,8 +88,7 @@ class BlackList:
|
||||||
if line not in pkgs:
|
if line not in pkgs:
|
||||||
remove.write(line + "\n")
|
remove.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
|
||||||
remove.close()
|
remove.close()
|
||||||
if self.quit:
|
if self.quit:
|
||||||
|
|
Loading…
Reference in a new issue