|
|
|
@ -29,6 +29,7 @@ from calculate.lib.utils.colortext.palette import TextState
|
|
|
|
|
from calculate.lib.utils.colortext import get_color_print
|
|
|
|
|
from calculate.update.emerge_parser import RevdepPercentBlock
|
|
|
|
|
import re
|
|
|
|
|
from collections import MutableSet
|
|
|
|
|
|
|
|
|
|
from package_tools import Git, Layman,\
|
|
|
|
|
EmergeLogNamedTask, EmergeLog, GitError, \
|
|
|
|
@ -51,6 +52,47 @@ __ = getLazyLocalTranslate(_)
|
|
|
|
|
class UpdateError(AddonError):
|
|
|
|
|
"""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:
|
|
|
|
|
"""Основной объект для выполнения действий связанных с обновлением системы
|
|
|
|
@ -78,6 +120,8 @@ class Update:
|
|
|
|
|
dv = self.clVars
|
|
|
|
|
git = Git()
|
|
|
|
|
needMeta = False
|
|
|
|
|
try:
|
|
|
|
|
self.stash_cache(rpath, name)
|
|
|
|
|
if not git.checkExistsRep(rpath):
|
|
|
|
|
if revision == "last":
|
|
|
|
|
git.cloneRepository(url, rpath, branch,
|
|
|
|
@ -112,6 +156,8 @@ class Update:
|
|
|
|
|
needMeta = True
|
|
|
|
|
if needMeta:
|
|
|
|
|
dv.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
|
finally:
|
|
|
|
|
self.unstash_cache(rpath, name)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def setAutocheckParams(self, status, interval):
|
|
|
|
@ -245,6 +291,61 @@ class Update:
|
|
|
|
|
layman.add(repname, url, rpath)
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
Обновить репозиторий через layman
|
|
|
|
@ -256,6 +357,8 @@ class Update:
|
|
|
|
|
where='cl_update_other_rep_name', eq=repname,
|
|
|
|
|
limit=1)
|
|
|
|
|
laymanname = path.basename(rpath)
|
|
|
|
|
self.stash_cache(rpath, laymanname)
|
|
|
|
|
try:
|
|
|
|
|
if Git.is_git(rpath):
|
|
|
|
|
self.addProgress()
|
|
|
|
|
p = PercentProgress(layman, "-s", laymanname, part=1, atty=True)
|
|
|
|
@ -267,6 +370,8 @@ class Update:
|
|
|
|
|
raise UpdateError(
|
|
|
|
|
_("Failed to update the {rname} repository").format(rname=repname),
|
|
|
|
|
addon=p.read())
|
|
|
|
|
finally:
|
|
|
|
|
self.unstash_cache(rpath, laymanname)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def regenCache(self, repname):
|
|
|
|
@ -290,6 +395,12 @@ class Update:
|
|
|
|
|
raise UpdateError(_("Failed to update the cache of the {rname} "
|
|
|
|
|
"repository").format(rname=repname))
|
|
|
|
|
cpu_num = self.clVars.Get('hr_cpu_num')
|
|
|
|
|
if repname in OverlayOwnCache():
|
|
|
|
|
self.printWARNING(
|
|
|
|
|
_("Repository %s has own cache") % repname.capitalize())
|
|
|
|
|
else:
|
|
|
|
|
self.startTask(_("Updating the %s repository cache") %
|
|
|
|
|
repname.capitalize())
|
|
|
|
|
p = process(egenCache, "--repo=%s" % repname, "--update",
|
|
|
|
|
"--jobs=%s" % cpu_num, stderr=STDOUT)
|
|
|
|
|
if p.failed():
|
|
|
|
|