diff --git a/pym/update/update.py b/pym/update/update.py index 2300a5a..5b785ba 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -1380,20 +1380,12 @@ class Update(MethodsInterface): "appropriate updates")) else: with writeFile(self.get_bin_cache_filename()) as f: - f.write(datas[0].strip()+"\n") + f.write(datas[0].strip() + "\n") if write_binhost: if hosts[0] != self.clVars.Get('update.cl_update_binhost'): self.refresh_binhost = True self.clVars.Set('cl_update_package_cache_set', 'on') - if self.clVars.GetBool('update.cl_update_binhost_recheck_set'): - self.clVars.Write('cl_update_binhost', hosts[0], location="system") - self.clVars.Write('cl_update_binhost_set', Variable.Off, location="system") - elif self.clVars.Get('cl_update_binhost_choice') and self.clVars.Get('cl_update_binhost_choice') != 'auto': - self.clVars.Write('cl_update_binhost', self.clVars.Get('cl_update_binhost_choice'), location="system") - self.clVars.Write('cl_update_binhost_set', Variable.On, location="system") - elif not self.clVars.GetBool('update.cl_update_binhost_set'): - self.clVars.Write('cl_update_binhost', hosts[0], location="system") - self.clVars.Write('cl_update_binhost_set', Variable.Off, location="system") + 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] @@ -1410,6 +1402,54 @@ class Update(MethodsInterface): location="system") return True + # def update_local_info_binhost(self, write_binhost=True): + # """ + # Проверить, что доступен хотя бы один из binhost'ов + # :return: + # """ + # hosts = self.clVars.Get("update.cl_update_binhost_host") + # datas = self.clVars.Get("update.cl_update_binhost_revisions") + # if not hosts: + # self.delete_binhost() + # raise UpdateError(_("Failed to find the server with " + # "appropriate updates")) + # else: + # with writeFile(self.get_bin_cache_filename()) as f: + # f.write(datas[0].strip()+"\n") + # if write_binhost: + # if hosts[0] != self.clVars.Get('update.cl_update_binhost'): + # self.refresh_binhost = True + # self.clVars.Set('cl_update_package_cache_set', 'on') + # if self.clVars.GetBool('update.cl_update_binhost_recheck_set'): + # self.clVars.Write('cl_update_binhost', hosts[0], location="system") + # self.clVars.Write('cl_update_binhost_set', Variable.Off, location="system") + # elif self.clVars.Get('cl_update_binhost_choice') and self.clVars.Get('cl_update_binhost_choice') != 'auto': + # cur_binhost = self.clVars.Get('cl_update_binhost_choice') + # if not cur_binhost.startswith("http://") \ + # and not cur_binhost.startswith("ftp://")\ + # and not cur_binhost.startswith("https://"): + # cur_binhost = f"https://{cur_binhost}" + # self.clVars.Write('cl_update_binhost', cur_binhost, location="system") + # self.clVars.Write('cl_update_binhost_set', Variable.On, location="system") + # elif not self.clVars.GetBool('update.cl_update_binhost_set'): + # self.clVars.Write('cl_update_binhost', hosts[0], location="system") + # self.clVars.Write('cl_update_binhost_set', Variable.Off, location="system") + # new_ts = self.clVars.Get("update.cl_update_binhost_timestamp") + # if new_ts: + # new_ts = new_ts[0] + # if new_ts.isdigit(): + # ini = SystemIni(self.clVars) + # ini.setVar('system', {'last_update': new_ts}) + # if self.is_update_action(self.clVars.Get("cl_action")): + # value = self.clVars.GetBool('update.cl_update_binhost_stable_set') + # new_value = self.clVars.GetBool('update.cl_update_binhost_stable_opt_set') + # if value != new_value: + # self.clVars.Write( + # 'cl_update_binhost_stable_set', + # self.clVars.Get('update.cl_update_binhost_stable_opt_set'), + # location="system") + # return True + def is_update_action(self, action): return action == 'sync' @@ -1452,6 +1492,7 @@ class Update(MethodsInterface): if not self.clVars.GetBool('update.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) @@ -1630,8 +1671,9 @@ class Update(MethodsInterface): def create_binhost_data(self): dv = self.clVars last_ts = dv.Get('cl_update_last_timestamp') - if dv.Get('update.cl_update_binhost_choice') == 'auto'\ - or not dv.Get('update.cl_update_binhost') and not dv.Get('update.cl_update_binhost_choice'): + if dv.Get('update.cl_update_binhost_choice') == 'auto' \ + or (not dv.Get('update.cl_update_binhost') and not dv.Get('update.cl_update_binhost_choice'))\ + or dv.GetBool('update.cl_update_binhost_recheck_set'): dv.Write('cl_update_binhost_set', "off") dv.Set('cl_update_binhost_set', 'off') @@ -1766,7 +1808,7 @@ class Update(MethodsInterface): self.set_migration_mode(True) return True - def check_current_binhost(self, binhost_url): + def check_current_binhost(self, binhost_url, rewrite_binhost=True): """ Проверка текущего сервера обновлений на валидность """ @@ -1816,12 +1858,7 @@ class Update(MethodsInterface): Binhosts.check_packages_signature( None, pi.get_value(), self.binhosts_data.gpg, sign=packages_sign) - if self.clVars.Get('cl_update_binhost_choice') and self.clVars.Get( - 'cl_update_binhost_choice') != 'auto': - self.clVars.Write('cl_update_binhost_set', 'on') - self.clVars.Write('cl_update_binhost', self.clVars.Get('cl_update_binhost_choice')) - # else: - # self.clVars.Write('cl_update_binhost', self.) + return True except BinhostSignError: for fn in (packages_fn, packages_sign_fn): @@ -1834,12 +1871,22 @@ class Update(MethodsInterface): raise UpdateError( _("Current binhost {} has wrong signature").format( binhost_url)) - self.clVars.Write('cl_update_binhost', binhost_url) - if self.clVars.Get('cl_update_binhost_choice') and self.clVars.Get('cl_update_binhost_choice') != 'auto': - self.clVars.Write('cl_update_binhost_set', 'on') - self.clVars.Write('cl_update_binhost', self.clVars.Get('cl_update_binhost_choice')) + if rewrite_binhost: + self.clVars.Write('cl_update_binhost', binhost_url) return True + def check_chosen_binhost(self, binhost): + if not binhost.startswith('https://') and not binhost.startswith('ftp://') and not binhost.startswith( + 'http://'): + binhost = f"https://{binhost}" + res = self.check_current_binhost(binhost, rewrite_binhost=False) + if binhost != self.clVars.Get('update.cl_update_binhost'): + self.refresh_binhost = True + self.clVars.Write('cl_update_binhost_set', 'on') + self.clVars.Write('cl_update_binhost', binhost) + return True + + def get_migration_mirror_url(self, host, level): level_required = int(level) + 1 return f"{host}level{level_required}" diff --git a/pym/update/utils/cl_update.py b/pym/update/utils/cl_update.py index 4d07afe..a768618 100644 --- a/pym/update/utils/cl_update.py +++ b/pym/update/utils/cl_update.py @@ -56,9 +56,10 @@ def get_synchronization_tasks(object_name): {'name': 'check_current_binhost', 'message': __("Checking current binhost"), 'essential': False, - 'method': Object('check_current_binhost(update.cl_update_new_binhost)'), + 'method': Object('check_current_binhost(update.cl_update_binhost)'), 'condition': lambda GetBool, Get: ( not GetBool('update.cl_update_binhost_recheck_set') and + not (Get('update.cl_update_binhost_choice') and Get('update.cl_update_binhost_choice') != 'auto') and Get('update.cl_update_sync_rep') and Get('update.cl_update_binhost') and Get('update.cl_update_use_migration_host') == 'off') @@ -68,6 +69,14 @@ def get_synchronization_tasks(object_name): 'method': Object("delete_binhost()"), 'depend': AllTasks.failed_all("check_current_binhost") }, + {'name': 'check_chosen_binhost', + 'message': __("Checking chosen binhost"), + 'method': Object('check_chosen_binhost(update.cl_update_binhost_choice)'), + 'condition': lambda GetBool, Get: ( + not GetBool('update.cl_update_binhost_recheck_set') and + Get('update.cl_update_binhost_choice') and + Get('update.cl_update_binhost_choice') != 'auto'), + 'depend': AllTasks.hasnot("check_current_binhost")}, {'name': 'group_find_binhost', 'group': '', 'while': (~AllTasks.has_any("detect_best_binhost") & @@ -84,9 +93,8 @@ def get_synchronization_tasks(object_name): 'depend': (Tasks.success() & ~AllTasks.has_any("not_use_search") & (~AllTasks.success_one_of("check_current_binhost") | AllTasks.success_all("sync_reps"))), - 'condition': lambda Get: Get('update.cl_update_use_migration_host') == 'off'# or - #(not Get("update.cl_update_binhost_recheck_set") and (not Get("update.cl_update_binhost_choice") != 'auto' - #or not Get("update.cl_update_binhost_choice"))) + 'condition': lambda Get: Get('update.cl_update_use_migration_host') == 'off', + 'depend': AllTasks.hasnot("check_chosen_binhost"), }, {'name': 'interrupt_on_no_leveled_binhost', 'method': Object("interrupt_on_no_leveled_binhost()"), @@ -132,7 +140,8 @@ def get_synchronization_tasks(object_name): 'method': Object('update_local_info_binhost()'), 'condition': lambda Get: Get("update.cl_update_binhost_choice") == 'auto' or not Get("update.cl_update_binhost_choice") - or Get("update.cl_update_binhost_recheck_set") + or Get("update.cl_update_binhost_recheck_set"), + 'depend': AllTasks.hasnot('check_chosen_binhost') }, {'name': 'sync_reps:update_binhost_list', 'essential': False, diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index 7802802..d22b98a 100644 --- a/pym/update/variables/update.py +++ b/pym/update/variables/update.py @@ -1745,15 +1745,6 @@ class VariableClUpdateBinhostChoice(Variable): return ['auto'] + self.Get("cl_update_binhost_list") -class VariableClUpdateNewBinhost(Variable): - def get(self): - if self.Get('cl_update_binhost_choice'): - binhost = self.Get('cl_update_binhost_choice') - if binhost != 'auto': - return binhost - return self.Get('cl_update_binhost') - - class VariableClUpdateBinhost(Variable): """ Хост с бинарными обновлениями @@ -1844,14 +1835,8 @@ class VariableClUpdatePortageBinhost(ReadonlyVariable): """ Прописываемый в /etc/portage/make.conf/binhost репозиторий """ - #value_format = "{update.cl_update_binhost}/grp/{os_arch_machine}" + value_format = "{update.cl_update_binhost}/grp/{os_arch_machine}" - def get(self): - if not self.Get('update.cl_update_binhost_recheck_set') \ - and self.Get('update.cl_update_binhost_choice') \ - and self.Get('update.cl_update_binhost_choice') != 'auto': - return f"{self.Get('update.cl_update_binhost_choice')}/grp/{self.Get('os_arch_machine')}" - return f"{self.Get('update.cl_update_binhost')}/grp/{self.Get('os_arch_machine')}" class VariableClUpdatePackageCache(ReadonlyVariable): """