From 27d4ba541922c92d86a5ff24d498d1de6ca375fe Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 15 Jan 2020 23:23:06 +0100 Subject: [PATCH] Improving code for Python 3 Signed-off-by: Dimitris Zlatanidis --- slpkg/binary/search.py | 3 +-- slpkg/init.py | 31 ++++++++++++++++++++++--------- slpkg/slack/mirrors.py | 12 ++++++------ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/slpkg/binary/search.py b/slpkg/binary/search.py index a5526bc1..a0a012e1 100644 --- a/slpkg/binary/search.py +++ b/slpkg/binary/search.py @@ -33,8 +33,7 @@ def search_pkg(name, repo): """Search if package exists in PACKAGES.TXT file and return the name. """ - PACKAGES_TXT = Utils().read_file(_meta_.lib_path + "{0}_repo/" - "PACKAGES.TXT".format(repo)) + PACKAGES_TXT = Utils().read_file(_meta_.lib_path + f"{repo}_repo/PACKAGES.TXT") names = Utils().package_name(PACKAGES_TXT) blacklist = BlackList().packages(pkgs=names, repo=repo) for line in PACKAGES_TXT.splitlines(): diff --git a/slpkg/init.py b/slpkg/init.py index 2f0e1afa..a746f742 100644 --- a/slpkg/init.py +++ b/slpkg/init.py @@ -137,14 +137,17 @@ class Initialization: self.down(log, ChangeLog_txt, repo_name) self.remote(log, ChangeLog_txt, lib, PACKAGES_TXT, CHECKSUMS_MD5, FILELIST_TXT, repo_name) - self.merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT", - "extra/PACKAGES.TXT", - "pasture/PACKAGES.TXT", - "patches/PACKAGES.TXT"]) - self.merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5", - "extra/CHECKSUMS.md5", - "pasture/CHECKSUMS.md5", - "patches/CHECKSUMS_md5"]) + merge = self.merge_stable + if self.meta.slack_rel == "current": + merge = self.merge_current + merge(lib, "PACKAGES.TXT", ["core/PACKAGES.TXT", + "extra/PACKAGES.TXT", + "pasture/PACKAGES.TXT", + "patches/PACKAGES.TXT"]) + merge(lib, "CHECKSUMS.md5", ["core/CHECKSUMS.md5", + "extra/CHECKSUMS.md5", + "pasture/CHECKSUMS.md5", + "patches/CHECKSUMS_md5"]) def sbo(self): """Creating sbo local library @@ -682,7 +685,17 @@ class Initialization: self.down(lib_path, FILELIST_TXT, repo) self.down(log_path, ChangeLog_txt, repo) - def merge(self, path, outfile, infiles): + def merge_stable(self, path, outfile, infiles): + """Merge files + """ + with open(path + outfile, 'w') as out_f: + for i in infiles: + if os.path.isfile(f"{path}{i}"): + with open(path + i, "r") as in_f: + for line in in_f: + out_f.write(line) + + def merge_current(self, path, outfile, infiles): """Merge files """ code = "utf-8" diff --git a/slpkg/slack/mirrors.py b/slpkg/slack/mirrors.py index 3de98493..50af32a8 100644 --- a/slpkg/slack/mirrors.py +++ b/slpkg/slack/mirrors.py @@ -38,17 +38,17 @@ def mirrors(name, location): repo = Repo().slack() if _meta_.arch == "x86_64": if rel == "stable": - http = repo + "slackware64-{0}/{1}{2}".format(ver, location, name) + http = f"{repo}slackware64-{ver}/{location}{name}" else: - http = repo + "slackware64-{0}/{1}{2}".format(rel, location, name) + http = f"{repo}slackware64-{rel}/{location}{name}" elif _meta_.arch.startswith("arm"): if rel == "stable": - http = repo + "slackwarearm-{0}/{1}{2}".format(ver, location, name) + http = f"{repo}slackwarearm-{ver}/{location}{name}" else: - http = repo + "slackwarearm-{0}/{1}{2}".format(rel, location, name) + http = f"{repo}slackwarearm-{rel}/{location}{name}" else: if rel == "stable": - http = repo + "slackware-{0}/{1}{2}".format(ver, location, name) + http = f"{repo}slackware-{ver}/{location}{name}" else: - http = repo + "slackware-{0}/{1}{2}".format(rel, location, name) + http = f"{repo}slackware-{rel}/{location}{name}" return http