|
|
@ -29,6 +29,7 @@ from calculate.lib.utils.colortext.palette import TextState
|
|
|
|
from calculate.lib.utils.colortext import get_color_print
|
|
|
|
from calculate.lib.utils.colortext import get_color_print
|
|
|
|
from calculate.update.emerge_parser import RevdepPercentBlock
|
|
|
|
from calculate.update.emerge_parser import RevdepPercentBlock
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
from collections import MutableSet
|
|
|
|
|
|
|
|
|
|
|
|
from package_tools import Git, Layman,\
|
|
|
|
from package_tools import Git, Layman,\
|
|
|
|
EmergeLogNamedTask, EmergeLog, GitError, \
|
|
|
|
EmergeLogNamedTask, EmergeLog, GitError, \
|
|
|
@ -51,6 +52,47 @@ __ = getLazyLocalTranslate(_)
|
|
|
|
class UpdateError(AddonError):
|
|
|
|
class UpdateError(AddonError):
|
|
|
|
"""Update Error"""
|
|
|
|
"""Update Error"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OverlayOwnCache(MutableSet):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Сет оверлеев с интегрированным кэшем
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, initvalue=()):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __get_overlays(self):
|
|
|
|
|
|
|
|
own_cache_value = SystemIni().getVar('update', 'own_cache') or ""
|
|
|
|
|
|
|
|
return [x.strip() for x in own_cache_value.split(',') if x.strip()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __write_overlays(self, overlays):
|
|
|
|
|
|
|
|
if not overlays:
|
|
|
|
|
|
|
|
SystemIni().delVar('update', 'own_cache')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
SystemIni().setVar('update', {'own_cache': ",".join(overlays)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __contains__(self, item):
|
|
|
|
|
|
|
|
return item in self.__get_overlays()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
|
|
|
return iter(self.__get_overlays())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
|
|
|
|
return len(self.__get_overlays())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __append_value(self, overlays, value):
|
|
|
|
|
|
|
|
if value not in overlays:
|
|
|
|
|
|
|
|
overlays.append(value)
|
|
|
|
|
|
|
|
self.__write_overlays(overlays)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add(self, value):
|
|
|
|
|
|
|
|
overlays = self.__get_overlays()
|
|
|
|
|
|
|
|
self.__append_value(overlays, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def discard(self, value):
|
|
|
|
|
|
|
|
overlays = self.__get_overlays()
|
|
|
|
|
|
|
|
if value in overlays:
|
|
|
|
|
|
|
|
overlays.remove(value)
|
|
|
|
|
|
|
|
self.__write_overlays(overlays)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Update:
|
|
|
|
class Update:
|
|
|
|
"""Основной объект для выполнения действий связанных с обновлением системы
|
|
|
|
"""Основной объект для выполнения действий связанных с обновлением системы
|
|
|
@ -78,40 +120,44 @@ class Update:
|
|
|
|
dv = self.clVars
|
|
|
|
dv = self.clVars
|
|
|
|
git = Git()
|
|
|
|
git = Git()
|
|
|
|
needMeta = False
|
|
|
|
needMeta = False
|
|
|
|
if not git.checkExistsRep(rpath):
|
|
|
|
try:
|
|
|
|
if revision == "last":
|
|
|
|
self.stash_cache(rpath, name)
|
|
|
|
git.cloneRepository(url, rpath, branch,
|
|
|
|
if not git.checkExistsRep(rpath):
|
|
|
|
cb_progress=cb_progress)
|
|
|
|
if revision == "last":
|
|
|
|
else:
|
|
|
|
git.cloneRepository(url, rpath, branch,
|
|
|
|
git.cloneRevRepository(url, rpath, branch, revision,
|
|
|
|
cb_progress=cb_progress)
|
|
|
|
cb_progress=cb_progress)
|
|
|
|
else:
|
|
|
|
needMeta = True
|
|
|
|
git.cloneRevRepository(url, rpath, branch, revision,
|
|
|
|
else:
|
|
|
|
cb_progress=cb_progress)
|
|
|
|
# если нужно обновиться до конкретной ревизии
|
|
|
|
|
|
|
|
if revision != "last":
|
|
|
|
|
|
|
|
if revision == git.getCurrentCommit(rpath):
|
|
|
|
|
|
|
|
if git.getBranch(rpath) == branch:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
# получить изменения из удаленного репозитория
|
|
|
|
|
|
|
|
git.fetchRepository(rpath, cb_progress=cb_progress)
|
|
|
|
|
|
|
|
# если текущая ветка не соответствует нужной
|
|
|
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
|
|
|
if repInfo['branch'] != branch:
|
|
|
|
|
|
|
|
# меняем ветку
|
|
|
|
|
|
|
|
needMeta = True
|
|
|
|
needMeta = True
|
|
|
|
git.checkoutBranch(rpath, branch)
|
|
|
|
|
|
|
|
if revision == "last":
|
|
|
|
|
|
|
|
if git.resetRepository(rpath, to_origin=True):
|
|
|
|
|
|
|
|
# если не удалось сбросить
|
|
|
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
|
|
|
if repInfo.get("files", False):
|
|
|
|
|
|
|
|
raise GitError("Failed to reset git")
|
|
|
|
|
|
|
|
needMeta = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
git.resetRepository(rpath, to_rev=revision)
|
|
|
|
# если нужно обновиться до конкретной ревизии
|
|
|
|
needMeta = True
|
|
|
|
if revision != "last":
|
|
|
|
if needMeta:
|
|
|
|
if revision == git.getCurrentCommit(rpath):
|
|
|
|
dv.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
if git.getBranch(rpath) == branch:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
# получить изменения из удаленного репозитория
|
|
|
|
|
|
|
|
git.fetchRepository(rpath, cb_progress=cb_progress)
|
|
|
|
|
|
|
|
# если текущая ветка не соответствует нужной
|
|
|
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
|
|
|
if repInfo['branch'] != branch:
|
|
|
|
|
|
|
|
# меняем ветку
|
|
|
|
|
|
|
|
needMeta = True
|
|
|
|
|
|
|
|
git.checkoutBranch(rpath, branch)
|
|
|
|
|
|
|
|
if revision == "last":
|
|
|
|
|
|
|
|
if git.resetRepository(rpath, to_origin=True):
|
|
|
|
|
|
|
|
# если не удалось сбросить
|
|
|
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
|
|
|
if repInfo.get("files", False):
|
|
|
|
|
|
|
|
raise GitError("Failed to reset git")
|
|
|
|
|
|
|
|
needMeta = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
git.resetRepository(rpath, to_rev=revision)
|
|
|
|
|
|
|
|
needMeta = True
|
|
|
|
|
|
|
|
if needMeta:
|
|
|
|
|
|
|
|
dv.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
self.unstash_cache(rpath, name)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def setAutocheckParams(self, status, interval):
|
|
|
|
def setAutocheckParams(self, status, interval):
|
|
|
@ -245,6 +291,61 @@ class Update:
|
|
|
|
layman.add(repname, url, rpath)
|
|
|
|
layman.add(repname, url, rpath)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
metadata_cache_names = ("metadata/md5-cache", "metadata/cache")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stash_cache(self, rpath, name):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Спрятать кэш
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if name in ("portage",):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if not name in OverlayOwnCache():
|
|
|
|
|
|
|
|
for cachename in self.metadata_cache_names:
|
|
|
|
|
|
|
|
cachedir = path.join(rpath, cachename)
|
|
|
|
|
|
|
|
if path.exists(cachedir):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
cachedir_s = path.join(path.dirname(rpath),
|
|
|
|
|
|
|
|
path.basename(
|
|
|
|
|
|
|
|
cachename) + ".stash")
|
|
|
|
|
|
|
|
if path.exists(cachedir_s):
|
|
|
|
|
|
|
|
removeDir(cachedir_s)
|
|
|
|
|
|
|
|
os.rename(cachedir, cachedir_s)
|
|
|
|
|
|
|
|
except BaseException as e:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def unstash_cache(self, rpath, name):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Извлеч кэш
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if name in ("portage",):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
cachenames = self.metadata_cache_names
|
|
|
|
|
|
|
|
if not name in OverlayOwnCache():
|
|
|
|
|
|
|
|
if any(path.exists(path.join(rpath, x)) for x in cachenames):
|
|
|
|
|
|
|
|
for cachename in cachenames:
|
|
|
|
|
|
|
|
cachedir_s = path.join(path.dirname(rpath),
|
|
|
|
|
|
|
|
path.basename(cachename)+".stash")
|
|
|
|
|
|
|
|
if path.exists(cachedir_s):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
removeDir(cachedir_s)
|
|
|
|
|
|
|
|
except BaseException as e:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
OverlayOwnCache().add(name)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
for cachename in cachenames:
|
|
|
|
|
|
|
|
cachedir = path.join(rpath, cachename)
|
|
|
|
|
|
|
|
cachedir_s = path.join(path.dirname(rpath),
|
|
|
|
|
|
|
|
path.basename(cachename)+".stash")
|
|
|
|
|
|
|
|
if path.exists(cachedir_s):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.rename(cachedir_s, cachedir)
|
|
|
|
|
|
|
|
except BaseException as e:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if all(not path.exists(path.join(rpath, x)) for x in cachenames):
|
|
|
|
|
|
|
|
OverlayOwnCache().discard(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def syncLaymanRepository(self, repname):
|
|
|
|
def syncLaymanRepository(self, repname):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Обновить репозиторий через layman
|
|
|
|
Обновить репозиторий через layman
|
|
|
@ -256,17 +357,21 @@ class Update:
|
|
|
|
where='cl_update_other_rep_name', eq=repname,
|
|
|
|
where='cl_update_other_rep_name', eq=repname,
|
|
|
|
limit=1)
|
|
|
|
limit=1)
|
|
|
|
laymanname = path.basename(rpath)
|
|
|
|
laymanname = path.basename(rpath)
|
|
|
|
if Git.is_git(rpath):
|
|
|
|
self.stash_cache(rpath, laymanname)
|
|
|
|
self.addProgress()
|
|
|
|
try:
|
|
|
|
p = PercentProgress(layman, "-s", laymanname, part=1, atty=True)
|
|
|
|
if Git.is_git(rpath):
|
|
|
|
for perc in p.progress():
|
|
|
|
self.addProgress()
|
|
|
|
self.setProgress(perc)
|
|
|
|
p = PercentProgress(layman, "-s", laymanname, part=1, atty=True)
|
|
|
|
else:
|
|
|
|
for perc in p.progress():
|
|
|
|
p = process(layman, "-s", repname, stderr=STDOUT)
|
|
|
|
self.setProgress(perc)
|
|
|
|
if p.failed():
|
|
|
|
else:
|
|
|
|
raise UpdateError(
|
|
|
|
p = process(layman, "-s", repname, stderr=STDOUT)
|
|
|
|
_("Failed to update the {rname} repository").format(rname=repname),
|
|
|
|
if p.failed():
|
|
|
|
addon=p.read())
|
|
|
|
raise UpdateError(
|
|
|
|
|
|
|
|
_("Failed to update the {rname} repository").format(rname=repname),
|
|
|
|
|
|
|
|
addon=p.read())
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
self.unstash_cache(rpath, laymanname)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def regenCache(self, repname):
|
|
|
|
def regenCache(self, repname):
|
|
|
@ -281,7 +386,7 @@ class Update:
|
|
|
|
where='cl_update_rep_name',
|
|
|
|
where='cl_update_rep_name',
|
|
|
|
eq=repname, limit=1)
|
|
|
|
eq=repname, limit=1)
|
|
|
|
repo_name = readFile(
|
|
|
|
repo_name = readFile(
|
|
|
|
path.join(path_rep,"profiles/repo_name")).strip()
|
|
|
|
path.join(path_rep, "profiles/repo_name")).strip()
|
|
|
|
if repo_name != repname:
|
|
|
|
if repo_name != repname:
|
|
|
|
self.printWARNING(
|
|
|
|
self.printWARNING(
|
|
|
|
_("Repository '{repo_name}' called '{repname}'"
|
|
|
|
_("Repository '{repo_name}' called '{repname}'"
|
|
|
@ -290,12 +395,18 @@ class Update:
|
|
|
|
raise UpdateError(_("Failed to update the cache of the {rname} "
|
|
|
|
raise UpdateError(_("Failed to update the cache of the {rname} "
|
|
|
|
"repository").format(rname=repname))
|
|
|
|
"repository").format(rname=repname))
|
|
|
|
cpu_num = self.clVars.Get('hr_cpu_num')
|
|
|
|
cpu_num = self.clVars.Get('hr_cpu_num')
|
|
|
|
p = process(egenCache, "--repo=%s" % repname, "--update",
|
|
|
|
if repname in OverlayOwnCache():
|
|
|
|
"--jobs=%s" % cpu_num, stderr=STDOUT)
|
|
|
|
self.printWARNING(
|
|
|
|
if p.failed():
|
|
|
|
_("Repository %s has own cache") % repname.capitalize())
|
|
|
|
raise UpdateError(_("Failed to update the cache of the {rname} "
|
|
|
|
else:
|
|
|
|
"repository").format(rname=repname),
|
|
|
|
self.startTask(_("Updating the %s repository cache") %
|
|
|
|
addon=p.read())
|
|
|
|
repname.capitalize())
|
|
|
|
|
|
|
|
p = process(egenCache, "--repo=%s" % repname, "--update",
|
|
|
|
|
|
|
|
"--jobs=%s" % cpu_num, stderr=STDOUT)
|
|
|
|
|
|
|
|
if p.failed():
|
|
|
|
|
|
|
|
raise UpdateError(_("Failed to update the cache of the {rname} "
|
|
|
|
|
|
|
|
"repository").format(rname=repname),
|
|
|
|
|
|
|
|
addon=p.read())
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def emergeMetadata(self):
|
|
|
|
def emergeMetadata(self):
|
|
|
|