Updated update and upgrade functions

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2020-02-15 16:49:20 +01:00
parent 12d00c4a0c
commit 837dbe9de2
2 changed files with 50 additions and 34 deletions

View file

@ -527,7 +527,7 @@ class Initialization:
version = self.meta.msb_sub_repo[1:-1] version = self.meta.msb_sub_repo[1:-1]
if self.meta.slack_rel == "current": if self.meta.slack_rel == "current":
ver_slack = self.meta.slack_rel ver_slack = self.meta.slack_rel
PACKAGES_TXT = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}" PACKAGES_TXT = f"{repo}{ver_slack}/{version}/{ar}/{lib_file}"
FILELIST_TXT = "" FILELIST_TXT = ""
CHECKSUMS_MD5 = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}" CHECKSUMS_MD5 = f"{repo}{ver_slack}/{version}/{ar}/{md5_file}"
ChangeLog_txt = f"{repo}{log_file}" ChangeLog_txt = f"{repo}{log_file}"
@ -709,30 +709,42 @@ class Initialization:
return True return True
return False return False
def upgrade(self, only):
"""Remove all package lists with changelog and checksums files class Upgrade:
and create lists again"""
def __init__(self):
self.meta = _meta_
self.log_path = self.meta.log_path
self.lib_path = self.meta.lib_path
def run(self, repos):
"""Removing and creating the packages lists
"""
repositories = self.meta.repositories repositories = self.meta.repositories
if only:
repositories = only # Replace the enabled repositories from user defined
if repos:
repositories = repos
for repo in repositories: for repo in repositories:
changelogs = f"{self.log_path}{repo}/ChangeLog.txt" changelogs = f"{self.log_path}{repo}/ChangeLog.txt"
if os.path.isfile(changelogs): if os.path.isfile(changelogs):
os.remove(changelogs) os.remove(changelogs)
if os.path.isdir(self.lib_path + f"{repo}_repo/"):
for f in (os.listdir(self.lib_path + f"{repo}_repo/")): if os.path.isdir(f"{self.lib_path}{repo}_repo/"):
for f in os.listdir(f"{self.lib_path}{repo}_repo/"):
files = f"{self.lib_path}{repo}_repo/{f}" files = f"{self.lib_path}{repo}_repo/{f}"
if os.path.isfile(files): if os.path.isfile(files):
os.remove(files) os.remove(files)
elif os.path.isdir(files): elif os.path.isdir(files):
shutil.rmtree(files) shutil.rmtree(files)
Update().repository(only) update = Update()
update.run(repos)
class Update: class Update:
def __init__(self): def __init__(self):
self.initialization = globals()['Initialization'](False)
self.meta = _meta_ self.meta = _meta_
self.grey = _meta_.color["GREY"] self.grey = _meta_.color["GREY"]
self.red = _meta_.color["RED"] self.red = _meta_.color["RED"]
@ -741,21 +753,23 @@ class Update:
self.done = f"{self.grey}Done{self.endc}\n" self.done = f"{self.grey}Done{self.endc}\n"
self.error = f"{self.red}Error{self.endc}\n" self.error = f"{self.red}Error{self.endc}\n"
def repository(self, only): def run(self, repos):
"""Update repositories lists """Update repositories lists
""" """
print("\nCheck and update repositories:\n") print("\nCheck and update repositories:\n")
default = self.meta.default_repositories default = self.meta.default_repositories
enabled = self.meta.repositories enabled = self.meta.repositories
if only:
enabled = only # Replace the enabled repositories from user defined
if repos:
enabled = repos
for repo in enabled: for repo in enabled:
if check_for_local_repos(repo) is True: if check_for_local_repos(repo) is True:
continue continue
print(f"{self.grey}Check repository [{self.cyan}{repo}{self.grey}] ... {self.endc}", end="", flush=True) print(f"{self.grey}Check repository [{self.cyan}{repo}{self.grey}] ... {self.endc}", end="", flush=True)
if repo in default: if repo in default:
update = getattr(self.initialization, repo) getattr(Initialization(False), repo)()
update()
print(self.done, end="") print(self.done, end="")
elif repo in enabled: elif repo in enabled:
Initialization(False).custom(repo) Initialization(False).custom(repo)
@ -776,7 +790,6 @@ def check_exists_repositories(repo):
pkg_list = "PACKAGES.TXT" pkg_list = "PACKAGES.TXT"
return "" return ""
if not os.path.isfile(f"{_meta_.lib_path}{repo}_repo/{pkg_list}"): if not os.path.isfile(f"{_meta_.lib_path}{repo}_repo/{pkg_list}"):
# .format(_meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
return repo return repo
return "" return ""
@ -788,4 +801,4 @@ def check_for_local_repos(repo):
if repo in repos_dict: if repo in repos_dict:
repo_url = repos_dict[repo] repo_url = repos_dict[repo]
if repo_url.startswith("file:///"): if repo_url.startswith("file:///"):
return True return True

View file

@ -48,6 +48,7 @@ from slpkg.status_deps import DependenciesStatus
from slpkg.init import ( from slpkg.init import (
Update, Update,
Upgrade,
Initialization, Initialization,
check_exists_repositories check_exists_repositories
) )
@ -121,15 +122,32 @@ class ArgParse:
def command_update(self): def command_update(self):
"""Update package lists repositories """Update package lists repositories
""" """
update = Update()
if len(self.args) == 1 and self.args[0] == "update": if len(self.args) == 1 and self.args[0] == "update":
Update().repository(only="") update.run(repos="")
elif (len(self.args) == 2 and self.args[0] == "update" and elif (len(self.args) == 2 and self.args[0] == "update" and
self.args[1].startswith("--repositories=")): self.args[1].startswith("--repositories=")):
repos = self.args[1].split("=")[-1].split(",") repos = self.args[1].split("=")[-1].split(",")
for rp in repos: for rp in repos:
if rp not in self.meta.repositories: if rp not in self.meta.repositories:
repos.remove(rp) repos.remove(rp)
Update().repository(repos) update.run(repos)
else:
usage("")
def command_upgrade(self):
"""Recreate repositories package lists
"""
upgrade = Upgrade()
if len(self.args) == 1 and self.args[0] == "upgrade":
upgrade.run(repos="")
elif (len(self.args) == 2 and self.args[0] == "upgrade" and
self.args[1].startswith("--repositories=")):
repos = self.args[1].split("=")[-1].split(",")
for rp in repos:
if rp not in self.meta.repositories:
repos.remove(rp)
upgrade.run(repos)
else: else:
usage("") usage("")
@ -174,21 +192,6 @@ class ArgParse:
else: else:
usage("") usage("")
def command_upgrade(self):
"""Recreate repositories package lists
"""
if len(self.args) == 1 and self.args[0] == "upgrade":
Initialization(False).upgrade(only="")
elif (len(self.args) == 2 and self.args[0] == "upgrade" and
self.args[1].startswith("--repositories=")):
repos = self.args[1].split("=")[-1].split(",")
for rp in repos:
if rp not in self.meta.repositories:
repos.remove(rp)
Initialization(False).upgrade(repos)
else:
usage("")
def command_repo_info(self): def command_repo_info(self):
"""Repositories informations """Repositories informations
""" """