From 98bbebd1f65c6f5f5699637cba839db8d0a7632f Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Nov 2022 17:29:49 +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 | 116 ++++++++++++++++++++++----------- pym/update/variables/update.py | 50 +++++++++++++- pym/update/wsdl_update.py | 3 +- 3 files changed, 130 insertions(+), 39 deletions(-) diff --git a/pym/update/update.py b/pym/update/update.py index 1e06d2f..59f8127 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -385,17 +385,42 @@ class Update(MethodsInterface): """ dv = self.clVars check_status = dv.GetBool('update.cl_update_check_rep_set') - url, rpath, revision = ( - dv.Select(["cl_update_rep_url", "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")) git = self.getGit() - if not git.checkUrl(url): - raise UpdateError(_("Git %s is unavailable") % url) + working_host = '' + if 'cl_update_rep_list' in dv.allVars and dv.Get('cl_update_rep_list'): + # Берем первый доступный хостинг из списка + 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: + raise UpdateError(_("Git is unavailable")) + dv.Write('cl_update_rep_hosting', working_host) + + #--------------DEPRECATED--------------# + else: + url, rpath, revision = ( + dv.Select(["cl_update_rep_url", "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")) + git = self.getGit() + if not git.checkUrl(url): + raise UpdateError(_("Git %s is unavailable") % url) + # --------------DEPRECATED--------------# + chroot_path = path.normpath(self.clVars.Get('cl_chroot_path')) if chroot_path == '/': rpath_orig = rpath @@ -452,6 +477,7 @@ 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: @@ -1315,7 +1341,8 @@ class Update(MethodsInterface): if hosts[0] != self.clVars.Get('update.cl_update_binhost'): self.refresh_binhost = True self.clVars.Set('cl_update_package_cache_set', 'on') - self.clVars.Write('cl_update_binhost', hosts[0], location="system") + if not self.clVars.GetBool('cl_update_binhost_set'): + self.clVars.Write('cl_update_binhost', hosts[0], location="system") new_ts = self.clVars.Get("update.cl_update_binhost_timestamp") if new_ts: new_ts = new_ts[0] @@ -1371,28 +1398,29 @@ class Update(MethodsInterface): return True def delete_binhost(self): - self.clVars.Delete('cl_update_binhost', location="system") - try: - bin_cache_fn = self.get_bin_cache_filename() - if path.exists(bin_cache_fn): - os.unlink(bin_cache_fn) - except OSError: - raise UpdateError( - _("Failed to remove cached ini.env of binary repository")) - try: - for varname in ('update.cl_update_package_cache', - 'update.cl_update_package_cache_sign'): - fn = self.clVars.Get(varname) - if path.exists(fn): - os.unlink(fn) - except OSError: - raise UpdateError( - _("Failed to remove cached Package index")) - # удалить binhost - binhost_fn = self.inchroot( - self.clVars.Get("update.cl_update_portage_binhost_path")) - if path.exists(binhost_fn): - os.unlink(binhost_fn) + if not self.clVars.GetBool('cl_update_binhost_set'): + self.clVars.Write('cl_update_binhost', ' ', location="system") + try: + bin_cache_fn = self.get_bin_cache_filename() + if path.exists(bin_cache_fn): + os.unlink(bin_cache_fn) + except OSError: + raise UpdateError( + _("Failed to remove cached ini.env of binary repository")) + try: + for varname in ('update.cl_update_package_cache', + 'update.cl_update_package_cache_sign'): + fn = self.clVars.Get(varname) + if path.exists(fn): + os.unlink(fn) + except OSError: + raise UpdateError( + _("Failed to remove cached Package index")) + # удалить binhost + binhost_fn = self.inchroot( + self.clVars.Get("update.cl_update_portage_binhost_path")) + if path.exists(binhost_fn): + os.unlink(binhost_fn) return False def update_binhost_list(self, dv=None): @@ -1420,7 +1448,7 @@ class Update(MethodsInterface): if not changes: return False - self.create_binhost_data() + self.create_binhost_data(a) return True def drop_binhosts(self, dv): @@ -1546,10 +1574,24 @@ class Update(MethodsInterface): def create_binhost_data(self): dv = self.clVars last_ts = dv.Get('cl_update_last_timestamp') - if dv.GetBool('cl_update_binhost_stable_opt_set'): - binhost_list = dv.Get('cl_update_binhost_list') + a = dv.Get('cl_update_binhost') + c = self.clVars.getIniVar('cl_update_binhost') + d = dv.Get('cl_update_binhost_choice') + b = dv.GetBool('cl_update_binhost_set') + if (not dv.Get('cl_update_binhost_choice') and not dv.GetBool('cl_update_binhost_set')) \ + or dv.Get('cl_update_binhost_choice') == 'auto': + if dv.Get('cl_update_binhost_stable_opt_set'): + binhost_list = dv.Get('cl_update_binhost_list') + else: + binhost_list = dv.Get('cl_update_binhost_unstable_list') + dv.Write('cl_update_binhost_set', "off") else: - binhost_list = dv.Get('cl_update_binhost_unstable_list') + if dv.Get('cl_update_binhost_choice'): + dv.Write('cl_update_binhost', dv.Get('cl_update_binhost_choice')) + dv.Write('cl_update_binhost_set', "on") + binhost_list = [dv.Get('cl_update_binhost')] + + #dv.Write('cl_update_binhost_set', "off") self.binhosts_data = Binhosts( # значение малозначимо, поэтому берётся из собирающей системы dv.GetInteger('cl_update_binhost_timeout'), diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index bedce9e..624f139 100644 --- a/pym/update/variables/update.py +++ b/pym/update/variables/update.py @@ -165,6 +165,35 @@ class VariableClUpdateRepUrl(Variable): value = [] +class VariableClUpdateRepList(Variable): + """ + Список путей до репозиториев + """ + type = "list" + value = [] + + +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: + 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 + + +class VariableClUpdateRepHosting(Variable): + value = '' + + class VariableClUpdateLaymanStorage(Variable): """ Путь к репозиториям @@ -288,6 +317,12 @@ class VariableClUpdateBranchRep(ReadonlyVariable): def get(self): return self.Get('cl_update_rep_name') + +class VariableClUpdateBinhostSet(Variable): + type = "bool" + value = 'off' + + class VariableClUpdateBinhostsInfo(ReadonlyVariable): """ Объект для получения информации о серверах обновлений @@ -372,6 +407,7 @@ class VariableClUpdateBinhostTime(FieldValue, Variable): source_variable = "cl_update_binhost_data" column = 3 + class VariableClUpdateBinhostLevel(FieldValue, Variable): """ Список имен прочих репозиториев @@ -1622,11 +1658,23 @@ class VariableClUpdateBinhostStableOptSet(Variable): return self.Get('cl_update_binhost_stable_set') +class VariableClUpdateBinhostChoice(Variable): + type = "choiceedit" + value = '' + opt = ["--binhost"] + + def init(self): + self.label = _("Mirror url") + + def choice(self): + return self.Get("cl_update_binhost_list") + + class VariableClUpdateBinhost(Variable): """ Хост с бинарными обновлениями """ - value = "" + value = '' class VariableClUpdateBinhostRevisionPath(Variable): diff --git a/pym/update/wsdl_update.py b/pym/update/wsdl_update.py index 7d61579..bf71974 100644 --- a/pym/update/wsdl_update.py +++ b/pym/update/wsdl_update.py @@ -68,7 +68,8 @@ class Wsdl(WsdlBase): normal=( 'cl_update_binhost_stable_opt_set', 'cl_update_binhost_recheck_set', - 'cl_update_with_bdeps_opt_set' + 'cl_update_with_bdeps_opt_set', + 'cl_update_binhost_choice' ), expert=( 'cl_update_sync_only_set',