|
|
|
@ -15,6 +15,7 @@
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
from functools import wraps
|
|
|
|
|
import random
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from os import path
|
|
|
|
@ -29,6 +30,8 @@ from calculate.lib.datavars import DataVarsError, VariableError, Variable
|
|
|
|
|
from calculate.lib.utils.tools import AddonError
|
|
|
|
|
from calculate.lib.utils.colortext.palette import TextState
|
|
|
|
|
from calculate.lib.utils.colortext import get_color_print
|
|
|
|
|
|
|
|
|
|
from calculate.core.server.core_interfaces import RerunTrigger
|
|
|
|
|
from .emerge_parser import RevdepPercentBlock
|
|
|
|
|
from .datavars import DataVarsUpdate
|
|
|
|
|
from .update_info import UpdateInfo
|
|
|
|
@ -64,7 +67,7 @@ from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir,
|
|
|
|
|
PercentProgress, process, getRunCommands,
|
|
|
|
|
readFile, listDirectory, pathJoin,
|
|
|
|
|
find, FindFileType,quite_unlink,
|
|
|
|
|
writeFile, makeDirectory)
|
|
|
|
|
writeFile, makeDirectory, clearDirectory)
|
|
|
|
|
from . import emerge_parser
|
|
|
|
|
import logging
|
|
|
|
|
from .emerge_parser import (EmergeParser, EmergeCommand, EmergeError,
|
|
|
|
@ -230,6 +233,8 @@ class Update(MethodsInterface):
|
|
|
|
|
status = git.getStatusInfo(rpath)
|
|
|
|
|
if not status or status['files']:
|
|
|
|
|
need_update = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except GitError as e:
|
|
|
|
|
need_update = True
|
|
|
|
|
if need_update:
|
|
|
|
@ -246,7 +251,6 @@ class Update(MethodsInterface):
|
|
|
|
|
info_outdated = True
|
|
|
|
|
if info_outdated:
|
|
|
|
|
self.raiseOutdate()
|
|
|
|
|
dv.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
|
finally:
|
|
|
|
|
self.unstash_cache(rpath, name)
|
|
|
|
|
# TODO: debug1
|
|
|
|
@ -255,12 +259,21 @@ class Update(MethodsInterface):
|
|
|
|
|
|
|
|
|
|
def raiseOutdate(self):
|
|
|
|
|
self.clVars.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
|
if self.clVars.Get('cl_update_other_set') == 'auto':
|
|
|
|
|
self.clVars.Set('cl_update_other_set', 'on')
|
|
|
|
|
|
|
|
|
|
def setAutocheckParams(self, status, interval, update_other, cleanpkg):
|
|
|
|
|
"""
|
|
|
|
|
Настроить параметры автопроверки обновлений
|
|
|
|
|
"""
|
|
|
|
|
onoff = lambda x: "on" if x else "off"
|
|
|
|
|
def onoff(val):
|
|
|
|
|
if val and val not in ['off', 'auto']:
|
|
|
|
|
return 'on'
|
|
|
|
|
elif val == 'auto':
|
|
|
|
|
return 'auto'
|
|
|
|
|
else:
|
|
|
|
|
return 'off'
|
|
|
|
|
|
|
|
|
|
self.clVars.Write('cl_update_autocheck_set', onoff(status), True)
|
|
|
|
|
self.clVars.Write('cl_update_autocheck_interval', interval, True)
|
|
|
|
|
self.clVars.Write('cl_update_other_set', onoff(update_other), True)
|
|
|
|
@ -373,6 +386,32 @@ 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))
|
|
|
|
|
swap = {'main': 'master', 'master': 'main'}
|
|
|
|
|
if not git.checkUrl(url):
|
|
|
|
|
self.printWARNING(_("Git %s is unavailable, scaning next host") % url)
|
|
|
|
|
return None, url, rpath, revision
|
|
|
|
|
if revision in swap:
|
|
|
|
|
ini = SystemIni(dv)
|
|
|
|
|
cached_main_branch = ini.getVar("branch", repname)
|
|
|
|
|
revision = cached_main_branch if cached_main_branch else "main"
|
|
|
|
|
try:
|
|
|
|
|
dv.Get("cl_update_profile_storage").get_profiles(url, revision)
|
|
|
|
|
ini.setVar("branch", {repname: revision})
|
|
|
|
|
return host, url, rpath, revision
|
|
|
|
|
except GitError:
|
|
|
|
|
revision = swap[revision]
|
|
|
|
|
ini.setVar("branch", {repname: revision})
|
|
|
|
|
return host, url, rpath, revision
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@variable_module("update")
|
|
|
|
|
def syncRepositories(self, repname, fallback_sync=False,
|
|
|
|
|
clean_on_error=True):
|
|
|
|
@ -381,17 +420,55 @@ 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)
|
|
|
|
|
saved_host = dv.Get('cl_update_rep_hosting') if 'cl_update_rep_hosting' in dv.allVars else ''
|
|
|
|
|
working_host = ''
|
|
|
|
|
# проверка необходимости синхронизации других оверлеев
|
|
|
|
|
if 'cl_update_rep_list' in dv.allVars and dv.Get('cl_update_rep_list'):
|
|
|
|
|
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
|
|
|
|
|
# Берем первый доступный хостинг из списка
|
|
|
|
|
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"))
|
|
|
|
|
if working_host:
|
|
|
|
|
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--------------#
|
|
|
|
|
# check for readonly fs
|
|
|
|
|
if not os.access(rpath, os.W_OK):
|
|
|
|
|
return True
|
|
|
|
|
chroot_path = path.normpath(self.clVars.Get('cl_chroot_path'))
|
|
|
|
|
if chroot_path == '/':
|
|
|
|
|
rpath_orig = rpath
|
|
|
|
@ -405,15 +482,13 @@ class Update(MethodsInterface):
|
|
|
|
|
try:
|
|
|
|
|
if clean_on_error:
|
|
|
|
|
try:
|
|
|
|
|
repconf = ReposConf(dv.Get('cl_update_reposconf'),
|
|
|
|
|
dv.Get('cl_update_reposconf_dir'),
|
|
|
|
|
prefix=chroot_path)
|
|
|
|
|
repconf.add(repname, url, rpath_orig)
|
|
|
|
|
if not self._syncRepository(repname, url, rpath, revision,
|
|
|
|
|
cb_progress=self.setProgress,
|
|
|
|
|
clean=check_status,
|
|
|
|
|
notask=fallback_sync):
|
|
|
|
|
self.compare_repo_cache(repname, url, rpath_orig, chroot_path)
|
|
|
|
|
return "skip"
|
|
|
|
|
self.compare_repo_cache(repname, url, rpath_orig, chroot_path)
|
|
|
|
|
return True
|
|
|
|
|
except GitError as e:
|
|
|
|
|
if not isinstance(e, NotGitError):
|
|
|
|
@ -431,8 +506,18 @@ class Update(MethodsInterface):
|
|
|
|
|
cb_progress=self.setProgress,
|
|
|
|
|
clean=check_status,
|
|
|
|
|
notask=fallback_sync)
|
|
|
|
|
removeDir(rpath)
|
|
|
|
|
shutil.move(rpath_new, rpath)
|
|
|
|
|
if not isinstance(e, NotGitError):
|
|
|
|
|
removeDir(rpath)
|
|
|
|
|
shutil.move(rpath_new, rpath)
|
|
|
|
|
else:
|
|
|
|
|
#delete everything in rpath dir, but not rpath itself
|
|
|
|
|
for root, dirs, files in os.walk(rpath):
|
|
|
|
|
for f in files:
|
|
|
|
|
os.unlink(os.path.join(root, f))
|
|
|
|
|
for d in dirs:
|
|
|
|
|
shutil.rmtree(os.path.join(root, d))
|
|
|
|
|
for i in os.listdir(rpath_new):
|
|
|
|
|
shutil.move(os.path.join(rpath_new, i), rpath)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
raise UpdateError(_("Failed to modify the "
|
|
|
|
|
"{repname} repository").format(
|
|
|
|
@ -455,6 +540,24 @@ class Update(MethodsInterface):
|
|
|
|
|
|
|
|
|
|
metadata_cache_names = ("metadata/md5-cache", "metadata/cache")
|
|
|
|
|
|
|
|
|
|
def compare_repo_cache(self, repname, url, rpath_orig, chroot_path):
|
|
|
|
|
if not self.clVars.GetBool('cl_update_settings_changes_set'):
|
|
|
|
|
repconf = ReposConf(self.clVars.Get('cl_update_reposconf'),
|
|
|
|
|
self.clVars.Get('cl_update_reposconf_dir'),
|
|
|
|
|
prefix=chroot_path)
|
|
|
|
|
repconf.add(repname, url, rpath_orig)
|
|
|
|
|
ini = SystemIni(self.clVars)
|
|
|
|
|
ps = PortageState()
|
|
|
|
|
new_portage_state_hash = ps.get_state()
|
|
|
|
|
ini.setVar('system', {'portage_hash': new_portage_state_hash})
|
|
|
|
|
self.clVars.Set('cl_update_package_cache_set', Variable.Off, force=True)
|
|
|
|
|
else:
|
|
|
|
|
repconf = ReposConf(self.clVars.Get('cl_update_reposconf'),
|
|
|
|
|
self.clVars.Get('cl_update_reposconf_dir'),
|
|
|
|
|
prefix=chroot_path)
|
|
|
|
|
repconf.add(repname, url, rpath_orig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stash_cache(self, rpath, name):
|
|
|
|
|
"""
|
|
|
|
|
Спрятать кэш
|
|
|
|
@ -520,6 +623,8 @@ class Update(MethodsInterface):
|
|
|
|
|
limit=1)
|
|
|
|
|
repdirname = path.basename(rpath)
|
|
|
|
|
self.stash_cache(rpath, repdirname)
|
|
|
|
|
rpath_old = f"{rpath}_old"
|
|
|
|
|
makeDirectory(rpath_old)
|
|
|
|
|
try:
|
|
|
|
|
if Git.is_git(rpath):
|
|
|
|
|
self.addProgress()
|
|
|
|
@ -527,13 +632,27 @@ class Update(MethodsInterface):
|
|
|
|
|
for perc in p.progress():
|
|
|
|
|
self.setProgress(perc)
|
|
|
|
|
else:
|
|
|
|
|
for root, dirs, files in os.walk(rpath):
|
|
|
|
|
for f in files:
|
|
|
|
|
os.replace(os.path.join(rpath, f), os.path.join(rpath_old, f))
|
|
|
|
|
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, f), os.path.join(rpath, f))
|
|
|
|
|
for d in dirs:
|
|
|
|
|
shutil.move(os.path.join(rpath_old, d), os.path.join(rpath, d))
|
|
|
|
|
raise UpdateError(
|
|
|
|
|
_("Failed to update the {rname} repository").format(
|
|
|
|
|
rname=repname),
|
|
|
|
|
addon=p.read())
|
|
|
|
|
else:
|
|
|
|
|
self.clVars.Set('cl_update_outdate_set', Variable.On, force=True)
|
|
|
|
|
finally:
|
|
|
|
|
removeDir(rpath_old)
|
|
|
|
|
self.unstash_cache(rpath, repdirname)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
@ -546,12 +665,17 @@ class Update(MethodsInterface):
|
|
|
|
|
Обновить кэш метаданных репозитория
|
|
|
|
|
"""
|
|
|
|
|
egenCache = self.get_prog_path('/usr/bin/egencache')
|
|
|
|
|
chroot_path = self.clVars.Get('builder.cl_builder_path')
|
|
|
|
|
if not egenCache:
|
|
|
|
|
raise UpdateError(_("The Portage tool is not found"))
|
|
|
|
|
repconf = ReposConf(self.clVars.Get('cl_update_reposconf'),
|
|
|
|
|
self.clVars.Get('cl_update_reposconf_dir'),
|
|
|
|
|
chroot_path)
|
|
|
|
|
repos_path = {x[0]: x[1] for x in list(repconf.get_all_base_repositories()) + list(repconf.get_other_repositories())}
|
|
|
|
|
if repname in self.clVars.Get('cl_update_rep_name'):
|
|
|
|
|
path_rep = self.clVars.Select('cl_update_rep_path',
|
|
|
|
|
where='cl_update_rep_name',
|
|
|
|
|
eq=repname, limit=1)
|
|
|
|
|
path_rep = repos_path.get(repname)
|
|
|
|
|
if not path_rep:
|
|
|
|
|
return True
|
|
|
|
|
repo_name = readFile(
|
|
|
|
|
path.join(path_rep, "profiles/repo_name")).strip()
|
|
|
|
|
if repo_name != repname:
|
|
|
|
@ -928,7 +1052,7 @@ class Update(MethodsInterface):
|
|
|
|
|
self.set_need_update(False)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def _startEmerging(self, emerge):
|
|
|
|
|
def _startEmerging(self, emerge, start_msg=None):
|
|
|
|
|
"""
|
|
|
|
|
Настроить и выполнить emerge
|
|
|
|
|
"""
|
|
|
|
@ -939,6 +1063,8 @@ class Update(MethodsInterface):
|
|
|
|
|
self.update_map["{CATEGORY}/{PF}".format(**pkg)] = \
|
|
|
|
|
rv.partition(":")[0]
|
|
|
|
|
emerge.command.send("yes\n")
|
|
|
|
|
if start_msg is not None and isinstance(start_msg, str):
|
|
|
|
|
self.startTask(start_msg)
|
|
|
|
|
emerge.emerging.add_observer(self._printEmergePackage)
|
|
|
|
|
emerge.installing.add_observer(self._printInstallPackage)
|
|
|
|
|
emerge.uninstalling.add_observer(self._printUninstallPackage)
|
|
|
|
@ -1026,7 +1152,7 @@ class Update(MethodsInterface):
|
|
|
|
|
self._display_install_package(emerge, emergelike=True)
|
|
|
|
|
self._display_error(emerge.prepare_error)
|
|
|
|
|
raise
|
|
|
|
|
self._startEmerging(emerge)
|
|
|
|
|
self._startEmerging(emerge, _("Fetching..."))
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def depclean(self):
|
|
|
|
@ -1125,6 +1251,8 @@ class Update(MethodsInterface):
|
|
|
|
|
_("Failed to use the new profile. Try again."))
|
|
|
|
|
for var_name in ('cl_update_rep_path',
|
|
|
|
|
'cl_update_rep_url',
|
|
|
|
|
'cl_update_rep_list',
|
|
|
|
|
'cl_update_binhost_set',
|
|
|
|
|
'cl_update_rep_name',
|
|
|
|
|
'cl_update_branch',
|
|
|
|
|
'cl_update_binhost_list',
|
|
|
|
@ -1294,7 +1422,7 @@ 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
|
|
|
|
@ -1355,28 +1483,31 @@ 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('update.cl_update_binhost_set') or self.clVars.GetBool('cl_update_use_migration_host'):
|
|
|
|
|
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)
|
|
|
|
|
if self.clVars.GetBool('update.cl_update_binhost_set') and self.clVars.GetBool('cl_update_use_migration_host'):
|
|
|
|
|
self.clVars.Write('cl_update_binhost', self.clVars.Get('cl_update_save_cur_binhost') , location="system")
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def update_binhost_list(self, dv=None):
|
|
|
|
@ -1454,6 +1585,9 @@ class Update(MethodsInterface):
|
|
|
|
|
|
|
|
|
|
def download_packages(self, url_binhost, packages_fn, packages_sign_fn, gpg):
|
|
|
|
|
quite_unlink(packages_fn)
|
|
|
|
|
packages_ini = os.path.join(packages_sign_fn.split("/Packages.as")[0], 'ini.env')
|
|
|
|
|
quite_unlink(packages_ini)
|
|
|
|
|
orig_ini = Binhosts.packages_check_ini(url_binhost.split("/grp")[0]).decode('utf-8')
|
|
|
|
|
orig_packages = Binhosts.fetch_packages(url_binhost)
|
|
|
|
|
try:
|
|
|
|
|
with writeFile(packages_fn) as f:
|
|
|
|
@ -1461,6 +1595,8 @@ class Update(MethodsInterface):
|
|
|
|
|
pi["TTL"] = str(30 * DAYS)
|
|
|
|
|
pi["DOWNLOAD_TIMESTAMP"] = str(int(time.time()))
|
|
|
|
|
pi.write(f)
|
|
|
|
|
with open(packages_ini, 'w') as f:
|
|
|
|
|
f.write(orig_ini)
|
|
|
|
|
except (OSError, IOError):
|
|
|
|
|
raise UpdateError(_("Failed to save Packages"))
|
|
|
|
|
self.endTask(True)
|
|
|
|
@ -1476,11 +1612,7 @@ class Update(MethodsInterface):
|
|
|
|
|
f.write(Binhosts.fetch_packages_sign(url_binhost).decode("UTF-8"))
|
|
|
|
|
except BinhostSignError:
|
|
|
|
|
for fn in (packages_fn, packages_sign_fn):
|
|
|
|
|
if path.exists(fn):
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(fn)
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
quite_unlink(fn)
|
|
|
|
|
self.clVars.Set("update.cl_update_bad_sign_set", Variable.On)
|
|
|
|
|
self.clVars.Set('update.cl_update_binhost_recheck_set', Variable.On)
|
|
|
|
|
self.clVars.Set('cl_update_package_cache_set', Variable.Off, force=True)
|
|
|
|
@ -1498,9 +1630,7 @@ class Update(MethodsInterface):
|
|
|
|
|
BadEnv = 7
|
|
|
|
|
EnvNotFound = 8
|
|
|
|
|
SkipSlower = 9
|
|
|
|
|
UnknownError = 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UnknownError = 10
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def humanReadable(reason):
|
|
|
|
@ -1515,8 +1645,7 @@ class Update(MethodsInterface):
|
|
|
|
|
Update.Reason.Skip: "SKIP",
|
|
|
|
|
Update.Reason.SkipSlower: "",
|
|
|
|
|
Update.Reason.Success: "",
|
|
|
|
|
#TODO formulate better
|
|
|
|
|
Update.Reason.LevelWrong: "FAILED (binhost level is wrong)"
|
|
|
|
|
Update.Reason.LevelWrong: "FAILED (binhost level is low)"
|
|
|
|
|
}.get(reason,reason)
|
|
|
|
|
|
|
|
|
|
def _get_binhost_logger(self):
|
|
|
|
@ -1533,10 +1662,33 @@ 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')
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
if dv.GetBool('update.cl_update_binhost_recheck_set'):
|
|
|
|
|
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')
|
|
|
|
|
elif dv.Get('update.cl_update_binhost_choice') and dv.Get('update.cl_update_binhost_choice') != 'auto':
|
|
|
|
|
binhost = dv.Get('cl_update_binhost_choice')
|
|
|
|
|
if not binhost.startswith('https://') and not binhost.startswith('ftp://') and not binhost.startswith(
|
|
|
|
|
'http://'):
|
|
|
|
|
binhost = f"https://{binhost}"
|
|
|
|
|
binhost_list = [binhost]
|
|
|
|
|
elif dv.Get('update.cl_update_binhost') and dv.GetBool('update.cl_update_binhost_set') \
|
|
|
|
|
and dv.Get('update.cl_update_binhost_choice') != 'auto':
|
|
|
|
|
binhost = dv.Get('cl_update_binhost')
|
|
|
|
|
binhost_list = [binhost]
|
|
|
|
|
else:
|
|
|
|
|
binhost_list = dv.Get('cl_update_binhost_unstable_list')
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
self.binhosts_data = Binhosts(
|
|
|
|
|
# значение малозначимо, поэтому берётся из собирающей системы
|
|
|
|
|
dv.GetInteger('cl_update_binhost_timeout'),
|
|
|
|
@ -1545,6 +1697,7 @@ class Update(MethodsInterface):
|
|
|
|
|
last_ts, binhost_list,
|
|
|
|
|
self.get_arch_machine(),
|
|
|
|
|
gpg=dv.Get('update.cl_update_gpg'))
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
@variable_module("update")
|
|
|
|
@ -1558,8 +1711,7 @@ class Update(MethodsInterface):
|
|
|
|
|
retval = []
|
|
|
|
|
skip_check_status = False
|
|
|
|
|
actual_reason = self.Reason.UnknownError
|
|
|
|
|
# highest_level_found = int(self.clVars.Get('update.cl_update_level'))
|
|
|
|
|
for binhost in sorted(binhosts_data.get_binhosts(), reverse=True):
|
|
|
|
|
for binhost in sorted(asyncio.run(binhosts_data.get_asyncbinhosts()), reverse=True):
|
|
|
|
|
host = binhost.host
|
|
|
|
|
if not binhost.valid:
|
|
|
|
|
reason = self.Reason.WrongBinhost
|
|
|
|
@ -1579,14 +1731,11 @@ class Update(MethodsInterface):
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# SUCCESS
|
|
|
|
|
if not binhost.downgraded or stabilization:
|
|
|
|
|
if not ignore_level and not self.is_binhost_level_valid(binhost):
|
|
|
|
|
reason = self.Reason.LevelWrong
|
|
|
|
|
# if highest_level_found < binhost.level:
|
|
|
|
|
# highest_level_found = binhost.level
|
|
|
|
|
else:
|
|
|
|
|
host = "-> %s" % host
|
|
|
|
|
reason = self.Reason.Success
|
|
|
|
|
if not ignore_level and self.compare_update_level(binhost.level) < 0:
|
|
|
|
|
reason = self.Reason.LevelWrong
|
|
|
|
|
elif not binhost.downgraded or stabilization:
|
|
|
|
|
host = "-> %s" % host
|
|
|
|
|
reason = self.Reason.Success
|
|
|
|
|
else:
|
|
|
|
|
reason = self.Reason.Skip
|
|
|
|
|
elif binhost.downgraded:
|
|
|
|
@ -1607,43 +1756,60 @@ class Update(MethodsInterface):
|
|
|
|
|
timestamp=binhost.timestamp,
|
|
|
|
|
reason=Update.Reason.humanReadable(reason)))
|
|
|
|
|
if not retval:
|
|
|
|
|
if actual_reason is self.Reason.BadSign:
|
|
|
|
|
if actual_reason is self.Reason.LevelWrong:
|
|
|
|
|
raise UpdateError(_("Failed to find trusted server with current level"))
|
|
|
|
|
elif actual_reason is self.Reason.BadSign:
|
|
|
|
|
raise UpdateError(_("Failed to find the reliable server with appropriate updates"))
|
|
|
|
|
elif actual_reason in (self.Reason.Outdated,
|
|
|
|
|
self.Reason.Skip,
|
|
|
|
|
self.Reason.Updating):
|
|
|
|
|
raise UpdateError(_("Failed to find the server with appropriate updates"))
|
|
|
|
|
elif actual_reason is self.Reason.LevelWrong:
|
|
|
|
|
# self.clVars.Set('cl_update_max_level_found', highest_level_found)#TODO change to write
|
|
|
|
|
self.set_migration_mode(True)
|
|
|
|
|
#TODO add translation
|
|
|
|
|
raise UpdateError(_("Failed to find the server with appropriate level of updates"))
|
|
|
|
|
else:
|
|
|
|
|
raise UpdateError(_("Failed to find the working server with updates"))
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
|
|
def is_binhost_level_valid(self, binhost):
|
|
|
|
|
return self.compare_update_level(binhost) == 0
|
|
|
|
|
return self.compare_update_level(binhost.level) == 0
|
|
|
|
|
|
|
|
|
|
# @variable_module("update")
|
|
|
|
|
def compare_update_level(self, binhost):
|
|
|
|
|
def compare_update_level(self, level):
|
|
|
|
|
# < 0 binhost level low
|
|
|
|
|
# == 0 binhost level adequate
|
|
|
|
|
# > 0 binhost level high
|
|
|
|
|
if binhost.level is None:
|
|
|
|
|
local_lvl = self.clVars.Get("update.cl_update_level")
|
|
|
|
|
if level is None or local_lvl == "":
|
|
|
|
|
return None
|
|
|
|
|
return binhost.level - int(self.clVars.Get("update.cl_update_level"))
|
|
|
|
|
return level - int(local_lvl)
|
|
|
|
|
|
|
|
|
|
def check_current_binhost(self, binhost_url):
|
|
|
|
|
def is_branch_set(self):
|
|
|
|
|
#basically, if any of the branches are specified, we won't use migration
|
|
|
|
|
return any(x != "tag" for x in self.clVars.Get("cl_update_branch_name"))
|
|
|
|
|
|
|
|
|
|
def is_level_forced(self):
|
|
|
|
|
flvl = self.clVars.Get("cl_update_force_level")
|
|
|
|
|
return flvl.isdigit() and int(flvl) > 0
|
|
|
|
|
|
|
|
|
|
def perform_migration_system_pre_check(self):
|
|
|
|
|
branch_is_set_check = self.is_branch_set()
|
|
|
|
|
if branch_is_set_check:
|
|
|
|
|
self.clVars.Set("cl_update_ignore_level", Variable.On)
|
|
|
|
|
else:
|
|
|
|
|
if self.is_level_forced():
|
|
|
|
|
self.clVars.Set("cl_update_level", int(self.clVars.Get("cl_update_force_level")) - 1)
|
|
|
|
|
self.set_migration_mode(True)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def check_current_binhost(self, binhost_url, rewrite_binhost=True):
|
|
|
|
|
"""
|
|
|
|
|
Проверка текущего сервера обновлений на валидность
|
|
|
|
|
"""
|
|
|
|
|
if not binhost_url in self.binhosts_data.binhost_list:
|
|
|
|
|
raise UpdateError(_("Current binhost is absent in list of update servers"))
|
|
|
|
|
# if not binhost_url in self.binhosts_data.binhost_list:
|
|
|
|
|
# raise UpdateError(_("Current binhost is absent in list of update servers"))
|
|
|
|
|
binhost = self.binhosts_data.get_binhost(binhost_url)
|
|
|
|
|
|
|
|
|
|
ignore_level = self.clVars.Get("cl_update_ignore_level") == Variable.On
|
|
|
|
|
cur_level_valid = self.is_current_level_a_digit() if not ignore_level else None
|
|
|
|
|
if binhost.valid and not binhost.outdated and not binhost.downgraded \
|
|
|
|
|
and self.is_binhost_level_valid(binhost):
|
|
|
|
|
and (ignore_level or not cur_level_valid or self.is_binhost_level_valid(binhost)):
|
|
|
|
|
if binhost.status == self.binhosts_data.BinhostStatus.Success:
|
|
|
|
|
self.clVars.Set('update.cl_update_binhost_data',
|
|
|
|
|
[[binhost.host, binhost.data,
|
|
|
|
@ -1651,6 +1817,8 @@ class Update(MethodsInterface):
|
|
|
|
|
str(binhost.duration),
|
|
|
|
|
str(binhost.level)]],
|
|
|
|
|
force=True)
|
|
|
|
|
if not ignore_level and not cur_level_valid and not self.is_level_forced():
|
|
|
|
|
self.pull_level_from_binhost(binhost)
|
|
|
|
|
self.endTask()
|
|
|
|
|
else:
|
|
|
|
|
if not binhost.valid:
|
|
|
|
@ -1663,48 +1831,52 @@ class Update(MethodsInterface):
|
|
|
|
|
raise UpdateError(
|
|
|
|
|
_("Binary packages on the current binhost {} "
|
|
|
|
|
"are older than local").format(binhost_url))
|
|
|
|
|
elif self.check_current_level():
|
|
|
|
|
if not self.is_binhost_level_valid(binhost):
|
|
|
|
|
# self.stash_binhost(binhost_url)
|
|
|
|
|
elif not ignore_level and not self.is_binhost_level_valid(binhost):
|
|
|
|
|
if binhost.level and self.compare_update_level(binhost.level) > 0:
|
|
|
|
|
self.set_migration_mode(True)
|
|
|
|
|
#TODO translate
|
|
|
|
|
raise UpdateError(
|
|
|
|
|
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
|
|
|
|
|
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
|
|
|
|
|
else:
|
|
|
|
|
self.pull_level_from_binhost(binhost)
|
|
|
|
|
raise UpdateError((
|
|
|
|
|
_("Current binhost {} has wrong update level. Current level: {} Binhost level: {}").\
|
|
|
|
|
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level)))
|
|
|
|
|
|
|
|
|
|
if self.binhosts_data.gpg:
|
|
|
|
|
packages_fn = self.clVars.Get('update.cl_update_package_cache')
|
|
|
|
|
packages_sign_fn = self.clVars.Get('update.cl_update_package_cache_sign')
|
|
|
|
|
if path.exists(packages_fn) and path.exists(packages_sign_fn):
|
|
|
|
|
packages_sign = readFile(packages_sign_fn, binary=True)
|
|
|
|
|
pi = PackagesIndex(readFile(packages_fn))
|
|
|
|
|
pi.clean()
|
|
|
|
|
packages_ini = os.path.join(packages_sign_fn.split("/Packages.as")[0], 'ini.env')
|
|
|
|
|
if path.exists(packages_fn) and path.exists(packages_sign_fn) and path.exists(packages_ini):
|
|
|
|
|
local_ini = readFile(packages_ini, binary=True)
|
|
|
|
|
try:
|
|
|
|
|
Binhosts.check_packages_signature(
|
|
|
|
|
None, pi.get_value(), self.binhosts_data.gpg,
|
|
|
|
|
sign=packages_sign)
|
|
|
|
|
return True
|
|
|
|
|
except BinhostSignError:
|
|
|
|
|
for fn in (packages_fn, packages_sign_fn):
|
|
|
|
|
if path.exists(fn):
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(fn)
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
if binhost.bad_sign:
|
|
|
|
|
raise UpdateError(
|
|
|
|
|
_("Current binhost {} has wrong signature").format(
|
|
|
|
|
binhost_url))
|
|
|
|
|
orig_ini = Binhosts.packages_check_ini(binhost.host)
|
|
|
|
|
if not orig_ini == local_ini:
|
|
|
|
|
for fn in (packages_fn, packages_sign_fn, packages_ini):
|
|
|
|
|
quite_unlink(fn)
|
|
|
|
|
self.clVars.Set('cl_update_package_cache_set', Variable.On)
|
|
|
|
|
except BinhostError:
|
|
|
|
|
for fn in (packages_fn, packages_sign_fn, packages_ini):
|
|
|
|
|
quite_unlink(fn)
|
|
|
|
|
raise UpdateError(_("Failed to find ini.env on current binhost"))
|
|
|
|
|
|
|
|
|
|
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}"
|
|
|
|
|
|
|
|
|
|
@variable_module("update")
|
|
|
|
|
def detect_best_binhost(self):
|
|
|
|
|
def detect_best_binhost(self, ignore_level):
|
|
|
|
|
# выполняется переход с серверов unstable обновлении на stable
|
|
|
|
|
# в этом случае не важно, что бинари могут старее текущих
|
|
|
|
|
if (self.clVars.GetBool('cl_update_binhost_stable_opt_set') and
|
|
|
|
@ -1712,31 +1884,72 @@ class Update(MethodsInterface):
|
|
|
|
|
stabilization = True
|
|
|
|
|
else:
|
|
|
|
|
stabilization = False
|
|
|
|
|
current_level_is_valid = self.check_current_level()
|
|
|
|
|
#had to extract ignore level logic to cl_update because of variable module
|
|
|
|
|
current_level_is_valid = self.is_current_level_a_digit() if not ignore_level else False
|
|
|
|
|
self.startTask(_("Searching new binhost"))
|
|
|
|
|
|
|
|
|
|
#add try catch
|
|
|
|
|
|
|
|
|
|
retval = self._search_best_binhost(self.binhosts_data,
|
|
|
|
|
stabilization,
|
|
|
|
|
ignore_level = not current_level_is_valid)
|
|
|
|
|
stabilization, ignore_level or not current_level_is_valid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.clVars.Set('update.cl_update_binhost_data',
|
|
|
|
|
retval or Variable.EmptyTable, force=True)
|
|
|
|
|
|
|
|
|
|
if not current_level_is_valid:
|
|
|
|
|
level = int(self.clVars.Get("update.cl_update_binhost_level")[0])
|
|
|
|
|
self._set_update_level(level)
|
|
|
|
|
if not ignore_level:
|
|
|
|
|
best_binhost_level = int(self.clVars.Get("update.cl_update_binhost_level")[0])
|
|
|
|
|
#int(sorted(self.clVars.Get("update.cl_update_binhost_level"), key=int)[-1])
|
|
|
|
|
# int(self.clVars.Get("update.cl_update_binhost_level")[0])
|
|
|
|
|
|
|
|
|
|
if not current_level_is_valid:
|
|
|
|
|
self._set_update_level(best_binhost_level)
|
|
|
|
|
else:
|
|
|
|
|
cmpr = self.compare_update_level(best_binhost_level)
|
|
|
|
|
if cmpr is None:
|
|
|
|
|
self.printWARNING("Failed to find working binhost. As a temporary solution you can use "
|
|
|
|
|
"'cl-update --mirror-update https://mirror.calculate-linux.org/migrate' command")
|
|
|
|
|
elif cmpr > 0:
|
|
|
|
|
self.set_migration_mode(True)
|
|
|
|
|
raise UpdateError(_("Current level: {} Binhost level: {}").\
|
|
|
|
|
format(self.clVars.Get("update.cl_update_level"), best_binhost_level))
|
|
|
|
|
elif cmpr < 0:
|
|
|
|
|
self.delete_binhost()
|
|
|
|
|
raise UpdateError(_("Failed to find binhost with level equal or higher than local level"))
|
|
|
|
|
self.endTask()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
#нужен так как detect_best_binhost не essential, ошибка не останавливает
|
|
|
|
|
def interrupt_on_no_leveled_binhost(self):
|
|
|
|
|
# raise UpdateError(_("Failed to find binhost with level equal to or higher than local level"))
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def set_migration_mode(self, val=True):
|
|
|
|
|
val_to_write = Variable.On if val else Variable.Off
|
|
|
|
|
# self.clVars.Write("cl_update_use_migration_host", val_to_write, location="system")
|
|
|
|
|
self.clVars.Set("cl_update_use_migration_host", val_to_write)
|
|
|
|
|
self.clVars.Set("update.cl_update_use_migration_host", val_to_write)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cmp_rep_tag_to_current_calc_rep_tag(self):
|
|
|
|
|
#TODO value to Var
|
|
|
|
|
repname = 'calculate'
|
|
|
|
|
revision = (self.clVars.Select(["cl_update_rep_rev"],
|
|
|
|
|
where="cl_update_rep_name",
|
|
|
|
|
eq=repname, limit=1))[0]
|
|
|
|
|
saved_tag = self.get_current_saved_tag()
|
|
|
|
|
# git = self.getGit()
|
|
|
|
|
# rpath = '/var/db/repos/calculate'
|
|
|
|
|
# tggg = git.getCurrentTag(rpath)
|
|
|
|
|
if saved_tag is not None:
|
|
|
|
|
return int(revision) - saved_tag
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_saved_tag(self):
|
|
|
|
|
tg = self.clVars.Get("cl_update_saved_tag")
|
|
|
|
|
return int(tg) if tg else None
|
|
|
|
|
|
|
|
|
|
def set_migration_host(self):
|
|
|
|
|
#TODO translate
|
|
|
|
|
self.startTask(_("Setting up migration host"))
|
|
|
|
|
dv = self.clVars
|
|
|
|
|
last_ts = dv.Get('cl_update_last_timestamp')
|
|
|
|
@ -1759,9 +1972,17 @@ class Update(MethodsInterface):
|
|
|
|
|
str(level)]]
|
|
|
|
|
self.clVars.Set('update.cl_update_binhost_data',
|
|
|
|
|
migr_binhost_data or Variable.EmptyTable, force=True)
|
|
|
|
|
self.clVars.Set('cl_update_binhost', migration_host.host)
|
|
|
|
|
if not (migr_binhost_data):
|
|
|
|
|
#TODO translate
|
|
|
|
|
raise UpdateError(_("Failed to find the working migration server with appropriate level"))
|
|
|
|
|
raise UpdateError(_("Failed to find working migration host with current level"))
|
|
|
|
|
if not self.is_level_forced():
|
|
|
|
|
#tag_cmp = self.cmp_rep_tag_to_current_calc_rep_tag()
|
|
|
|
|
tag_cmp = 2
|
|
|
|
|
if tag_cmp <= 0:
|
|
|
|
|
self._update_increment_current_level()
|
|
|
|
|
self.delete_binhost()
|
|
|
|
|
self.set_migration_mode(False)
|
|
|
|
|
raise RerunTrigger(_("Raising level due to migration host being outdated"))
|
|
|
|
|
self.endTask()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
@ -1844,6 +2065,30 @@ class Update(MethodsInterface):
|
|
|
|
|
ini.delVar('system', 'portage_hash')
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def save_world_state_hash(self):
|
|
|
|
|
ini = SystemIni(self.clVars)
|
|
|
|
|
ps = PortageState()
|
|
|
|
|
ps.paths = ['/var/lib/portage/world']
|
|
|
|
|
new_world_state_hash = ps.get_state()
|
|
|
|
|
ini.setVar('system', {'world_hash': new_world_state_hash})
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def drop_world_state_hash(self):
|
|
|
|
|
"""
|
|
|
|
|
Сбросить состояние
|
|
|
|
|
"""
|
|
|
|
|
ini = SystemIni(self.clVars)
|
|
|
|
|
ini.delVar('system', 'world_hash')
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def drop_packages_cache(self):
|
|
|
|
|
packages_fn = self.clVars.Get('update.cl_update_package_cache')
|
|
|
|
|
packages_sign_fn = self.clVars.Get('update.cl_update_package_cache_sign')
|
|
|
|
|
packages_ini = os.path.join(packages_sign_fn.split("/Packages.as")[0], 'ini.env')
|
|
|
|
|
for fn in (packages_fn, packages_sign_fn, packages_ini):
|
|
|
|
|
quite_unlink(fn)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def update_fastlogin_domain_path(self):
|
|
|
|
|
try:
|
|
|
|
|
if not self.clVars.Get('client.cl_remote_host'):
|
|
|
|
@ -1864,51 +2109,77 @@ class Update(MethodsInterface):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def update_increment_current_level(self):
|
|
|
|
|
#TODO add translation
|
|
|
|
|
self.startTask(_("Increasing update level"))
|
|
|
|
|
self.startTask(_("Increasing local update level"))
|
|
|
|
|
self._update_increment_current_level()
|
|
|
|
|
self.set_migration_mode(False)
|
|
|
|
|
# self.unstash_binhost()
|
|
|
|
|
self.delete_binhost()
|
|
|
|
|
self.set_migration_mode(False)
|
|
|
|
|
self.endTask()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
#should not do when on a branch
|
|
|
|
|
def update_set_current_saved_tag(self):
|
|
|
|
|
#TODO add to var?
|
|
|
|
|
repname = "calculate"
|
|
|
|
|
git = self.getGit()
|
|
|
|
|
rpath, revision = (
|
|
|
|
|
self.clVars.Select(["cl_update_rep_path",
|
|
|
|
|
"cl_update_rep_rev"],
|
|
|
|
|
where="cl_update_rep_name",
|
|
|
|
|
eq=repname, limit=1))
|
|
|
|
|
try:
|
|
|
|
|
branch_name = self.clVars.Select(["cl_update_branch_name"],
|
|
|
|
|
where="cl_update_branch_rep", eq=repname, limit=1)[0]
|
|
|
|
|
tag = git.getCurrentTag(rpath)
|
|
|
|
|
if branch_name == Git.Reference.Tag and tag.isdigit():
|
|
|
|
|
self._set_saved_tag(tag)
|
|
|
|
|
return True
|
|
|
|
|
except (ValueError, FileNotFoundError) as e:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def _update_increment_current_level(self):
|
|
|
|
|
current_level = int(self.clVars.Get('cl_update_level'))
|
|
|
|
|
self.clVars.Write('cl_update_level',
|
|
|
|
|
str(current_level + 1), location="system")
|
|
|
|
|
self._set_update_level(str(current_level + 1))
|
|
|
|
|
|
|
|
|
|
def check_current_level(self):
|
|
|
|
|
def is_current_level_a_digit(self):
|
|
|
|
|
"""
|
|
|
|
|
Возвращает True если есть значение в calculate.env
|
|
|
|
|
Возвращает True если значение update_level это цифра >=0
|
|
|
|
|
"""
|
|
|
|
|
return int(self.clVars.Get('cl_update_level')) >= 0
|
|
|
|
|
|
|
|
|
|
# isdigit - True if it can be interp-ed as a number >=0
|
|
|
|
|
return self.clVars.Get('cl_update_level').isdigit()
|
|
|
|
|
|
|
|
|
|
def pull_level_from_binhost(self, binhost):
|
|
|
|
|
self._set_update_level(binhost.level)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def _set_update_level(self, level):
|
|
|
|
|
if level:
|
|
|
|
|
self.clVars.Write('cl_update_level',
|
|
|
|
|
str(level), location="system")
|
|
|
|
|
return True
|
|
|
|
|
self._set_val_in_system(level, 'cl_update_level')
|
|
|
|
|
|
|
|
|
|
def _set_saved_tag(self, tag):
|
|
|
|
|
self._set_val_in_system(tag, 'cl_update_saved_tag')
|
|
|
|
|
|
|
|
|
|
def _set_val_in_system(self, val, val_name):
|
|
|
|
|
"""
|
|
|
|
|
val should be int >= 0
|
|
|
|
|
"""
|
|
|
|
|
if isinstance(val, str):
|
|
|
|
|
val = val if val.isdigit() else 0
|
|
|
|
|
elif isinstance(val, int):
|
|
|
|
|
val = val if val >= 0 else 0
|
|
|
|
|
else:
|
|
|
|
|
self.clVars.Write('cl_update_level',
|
|
|
|
|
str(0), location="system")
|
|
|
|
|
return False
|
|
|
|
|
val = val if val else 0
|
|
|
|
|
self.clVars.Write(val_name, str(val), location="system")
|
|
|
|
|
|
|
|
|
|
# def stash_binhost(self, binhost_url):
|
|
|
|
|
# """
|
|
|
|
|
# Бекап адреса бинхоста
|
|
|
|
|
# """
|
|
|
|
|
# self.clVars.Write("cl_update_binhost_stash", binhost_url, location="system")
|
|
|
|
|
|
|
|
|
|
# def unstash_binhost(self):
|
|
|
|
|
# """
|
|
|
|
|
# Восстановление сохраненного бинхоста (если он есть)
|
|
|
|
|
# """
|
|
|
|
|
# val_to_write = self.clVars.Get("update.cl_update_binhost_stash")
|
|
|
|
|
# if val_to_write:
|
|
|
|
|
# self.clVars.Write('cl_update_binhost', val_to_write, location="system")
|
|
|
|
|
|
|
|
|
|
def check_if_migration(self):
|
|
|
|
|
"""
|
|
|
|
|
Проверка для переключения на миграционный хост при ошибке валидации выбранного бинхоста
|
|
|
|
|
"""
|
|
|
|
|
if self.clVars.GetBool("update.cl_update_use_migration_host"):
|
|
|
|
|
self.clVars.Set('cl_update_save_cur_binhost', self.clVars.Get('cl_update_binhost'))
|
|
|
|
|
return True
|
|
|
|
|
raise UpdateError(_("Something goes wrong while validating chosen binhost"))
|
|
|
|
|
|
|
|
|
|
def check_success_configure(self):
|
|
|
|
|
try:
|
|
|
|
|
return self.clVars.GetBool("cl_success_configure")
|
|
|
|
|
except:
|
|
|
|
|
return True
|
|
|
|
|