From 91d05b39e9683f6f93e987d6c663865a65b5ebde Mon Sep 17 00:00:00 2001 From: root Date: Wed, 9 Nov 2022 11:46:03 +0300 Subject: [PATCH] =?UTF-8?q?=09=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE:=20=20=20=20=20=20pym/update/update.py=20=09=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE:=20=20=20=20=20=20pym/upda?= =?UTF-8?q?te/variables/update.py=20=09=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE:=20=20=20=20=20=20pym/update/wsdl=5Fupdate.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/update/update.py | 63 ++++++++++++++++++++++------------ pym/update/variables/update.py | 33 ++++++++++-------- pym/update/wsdl_update.py | 4 +-- 3 files changed, 62 insertions(+), 38 deletions(-) diff --git a/pym/update/update.py b/pym/update/update.py index febfe14..469ed74 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -377,6 +377,19 @@ class Update(MethodsInterface): self.endTask(True) return True + + def checkUrl(self, host, host_urls, repname, dv, git): + url, rpath, revision = ( + dv.Select([host_urls, "cl_update_rep_path", + "cl_update_rep_rev"], + where="cl_update_rep_name", eq=repname, limit=1)) + if git.checkUrl(url): + working_host = host + return working_host, url, rpath, revision + self.printWARNING(_("Git %s is unavailable, scaning next host") % url) + return None, url, rpath, revision + + @variable_module("update") def syncRepositories(self, repname, fallback_sync=False, clean_on_error=True): @@ -386,30 +399,39 @@ class Update(MethodsInterface): dv = self.clVars check_status = dv.GetBool('update.cl_update_check_rep_set') git = self.getGit() + saved_host = dv.Get('cl_update_rep_hosting') if 'cl_update_rep_hosting' in dv.allVars else '' working_host = '' # проверка необходимости синхронизации других оверлеев - a = self.clVars.Get("cl_update_inner_other_set") - if self.clVars.Get("cl_update_inner_other_set") != '': - self.clVars.Write("cl_update_other_set", self.clVars.Get("cl_update_inner_other_set"), header="update") + if dv.Get("cl_update_inner_other_set") != 'auto': + dv.Write("cl_update_other_set", dv.Get("cl_update_inner_other_set"), header="update") + dv.Set("cl_update_other_set", dv.Get("cl_update_inner_other_set")) if 'cl_update_rep_list' in dv.allVars and dv.Get('cl_update_rep_list'): - #if dv.Get("cl_update_rep_hosting_choice"): + chosen_hosting = dv.Get("cl_update_rep_hosting_choice") + if chosen_hosting: + for host_urls, host in dv.Get('cl_update_inner_rep_list'): + if host == chosen_hosting: + working_host, url, rpath, revision = self.checkUrl(host, host_urls, repname, dv, git) + if working_host: + break + elif saved_host: + for host_urls, host in dv.Get('cl_update_inner_rep_list'): + if host == saved_host: + working_host, url, rpath, revision = self.checkUrl(host, host_urls, repname, dv, git) + if working_host: + break # Берем первый доступный хостинг из списка - for host_urls, host in dv.Get('cl_update_inner_rep_list'): - url, rpath, revision = ( - dv.Select([host_urls, "cl_update_rep_path", - "cl_update_rep_rev"], - where="cl_update_rep_name", eq=repname, limit=1)) - if not url or not rpath: - raise UpdateError(_("Configuration variables for repositories " - "are not setup for %s") % host) - if git.checkUrl(url): - working_host = host - break - else: - self.printWARNING(_("Git %s is unavailable, scaning next host") % url) if not working_host: + for host_urls, host in dv.Get('cl_update_inner_rep_list'): + if chosen_hosting == host: + continue + working_host, url, rpath, revision = self.checkUrl(host, host_urls, repname, dv, git) + if working_host: + break + if not working_host: + dv.Write('cl_update_rep_hosting', ' ') raise UpdateError(_("Git is unavailable")) - dv.Write('cl_update_rep_hosting', working_host) + if working_host: + dv.Write('cl_update_rep_hosting', working_host) #--------------DEPRECATED--------------# else: @@ -482,7 +504,6 @@ class Update(MethodsInterface): "{repname} repository").format( repname=repname) + _(": ") + str(e)) finally: - self.clVars.Write('cl_update_rep_hosting', val='', header='update') if path.exists(rpath_new): removeDir(rpath_new) else: @@ -572,8 +593,6 @@ class Update(MethodsInterface): for perc in p.progress(): self.setProgress(perc) else: - p = process(emerge, "--sync", repname, stderr=STDOUT) - if p.failed(): rpath_old = f"{rpath}_old" makeDirectory(rpath_old) for root, dirs, files in os.walk(rpath): @@ -582,6 +601,8 @@ class Update(MethodsInterface): for d in dirs: shutil.move(os.path.join(rpath, d), os.path.join(rpath_old, d)) clearDirectory(rpath) + p = process(emerge, "--sync", repname, stderr=STDOUT) + if p.failed(): for root, dirs, files in os.walk(rpath_old): for f in files: os.replace(os.path.join(rpath_old, d), os.path.join(rpath, f)) diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index 5107483..2243016 100644 --- a/pym/update/variables/update.py +++ b/pym/update/variables/update.py @@ -177,17 +177,19 @@ class VariableClUpdateInnerRepList(Variable): value = [] def get(self): - val = self.Get('cl_update_rep_list') - prev_host = self.Get('cl_update_rep_hosting') - if prev_host: + def gen(): + val = self.Get('cl_update_rep_list') + prev_host = self.Get('cl_update_rep_hosting') + if prev_host: + for dct in val: + for key, value in dct.items(): + if key == prev_host: + yield value, key.lower() for dct in val: for key, value in dct.items(): - if key == prev_host: - yield value, key - for dct in val: - for key, value in dct.items(): - if key != prev_host: - yield value, key + if key != prev_host: + yield value, key.lower() + return [x for x in gen()] class VariableClUpdateRepHosting(Variable): @@ -197,13 +199,16 @@ class VariableClUpdateRepHosting(Variable): class VariableClUpdateRepHostingChoice(Variable): type = "choice" value = '' + opt = ["--hosting"] def init(self): self.label = (_("Hosting name")) self.help = (_("Hosting to download from")) def choice(self): - return [x[1] for x in self.Get('cl_update_inner_rep_list')] or ["Calculate"] + a = [x[1] for x in self.Get('cl_update_inner_rep_list')] + b = self.Get('cl_update_inner_rep_list') + return [x[1] for x in self.Get('cl_update_inner_rep_list')] class VariableClUpdateLaymanStorage(Variable): @@ -633,17 +638,17 @@ class VariableClUpdateOtherSet(Variable): Обновить остальные оверлеи """ type = "bool" - value = "" + value = "on" def get(self): - if self.Get('cl_update_inner_other_set'): + if self.Get('cl_update_inner_other_set') != 'auto': return self.Get('cl_update_inner_other_set') return self.value class VariableClUpdateInnerOtherSet(Variable): - type = "bool" - value = 'on' + type = "bool3" + value = Variable.Auto metavalue = 'ON/OFF' opt = ["-o", "--update-other"] diff --git a/pym/update/wsdl_update.py b/pym/update/wsdl_update.py index 6b19f4d..c4d7491 100644 --- a/pym/update/wsdl_update.py +++ b/pym/update/wsdl_update.py @@ -69,11 +69,9 @@ class Wsdl(WsdlBase): 'cl_update_binhost_stable_opt_set', 'cl_update_binhost_recheck_set', 'cl_update_with_bdeps_opt_set', - - 'cl_update_inner_other_set' - ), expert=( + 'cl_update_inner_other_set', 'cl_update_sync_only_set', 'cl_update_pretend_set', 'cl_update_binhost_choice',