|
|
|
@ -13,14 +13,13 @@
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
from itertools import ifilter
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from os import path
|
|
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
from calculate.core.server.gen_pid import search_worked_process, ProcessStatus
|
|
|
|
|
from calculate.core.server.gen_pid import search_worked_process
|
|
|
|
|
from calculate.lib.cl_template import SystemIni
|
|
|
|
|
from calculate.lib.datavars import DataVarsError
|
|
|
|
|
|
|
|
|
@ -30,17 +29,22 @@ from calculate.lib.utils.colortext import get_color_print
|
|
|
|
|
from calculate.update.emerge_parser import RevdepPercentBlock
|
|
|
|
|
from calculate.update.datavars import DataVarsUpdate
|
|
|
|
|
from calculate.update.update_info import UpdateInfo
|
|
|
|
|
from calculate.lib.cl_log import log
|
|
|
|
|
import re
|
|
|
|
|
from itertools import chain
|
|
|
|
|
from collections import MutableSet
|
|
|
|
|
|
|
|
|
|
from calculate.lib.utils.portage import Git, Layman,\
|
|
|
|
|
EmergeLogNamedTask, EmergeLog, GitError, \
|
|
|
|
|
PackageInformation, PackageList, EmergePackage
|
|
|
|
|
from calculate.lib.utils.portage import (Git, Layman, EmergeLog, GitError,
|
|
|
|
|
EmergeLogNamedTask, PackageList,
|
|
|
|
|
PackageInformation,
|
|
|
|
|
get_packages_files_directory,
|
|
|
|
|
get_manifest_files_directory,
|
|
|
|
|
get_remove_list)
|
|
|
|
|
|
|
|
|
|
Colors = TextState.Colors
|
|
|
|
|
from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir,
|
|
|
|
|
PercentProgress, process, getRunCommands,
|
|
|
|
|
readFile, listDirectory)
|
|
|
|
|
readFile)
|
|
|
|
|
import emerge_parser
|
|
|
|
|
import logging
|
|
|
|
|
from emerge_parser import EmergeParser, EmergeCommand, EmergeError, EmergeCache
|
|
|
|
@ -96,7 +100,7 @@ class OverlayOwnCache(MutableSet):
|
|
|
|
|
self.__write_overlays(overlays)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Update:
|
|
|
|
|
class Update(object):
|
|
|
|
|
"""Основной объект для выполнения действий связанных с обновлением системы
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
@ -121,7 +125,7 @@ class Update:
|
|
|
|
|
"""
|
|
|
|
|
dv = self.clVars
|
|
|
|
|
git = Git()
|
|
|
|
|
needMeta = False
|
|
|
|
|
info_outdate = False
|
|
|
|
|
try:
|
|
|
|
|
self.stash_cache(rpath, name)
|
|
|
|
|
if not git.checkExistsRep(rpath):
|
|
|
|
@ -131,7 +135,7 @@ class Update:
|
|
|
|
|
else:
|
|
|
|
|
git.cloneRevRepository(url, rpath, branch, revision,
|
|
|
|
|
cb_progress=cb_progress)
|
|
|
|
|
needMeta = True
|
|
|
|
|
info_outdate = True
|
|
|
|
|
else:
|
|
|
|
|
# если нужно обновиться до конкретной ревизии
|
|
|
|
|
if revision != "last":
|
|
|
|
@ -144,7 +148,7 @@ class Update:
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
if repInfo['branch'] != branch:
|
|
|
|
|
# меняем ветку
|
|
|
|
|
needMeta = True
|
|
|
|
|
info_outdate = True
|
|
|
|
|
git.checkoutBranch(rpath, branch)
|
|
|
|
|
if revision == "last":
|
|
|
|
|
if git.resetRepository(rpath, to_origin=True):
|
|
|
|
@ -152,23 +156,25 @@ class Update:
|
|
|
|
|
repInfo = git.getStatusInfo(rpath)
|
|
|
|
|
if repInfo.get("files", False):
|
|
|
|
|
raise GitError("Failed to reset git")
|
|
|
|
|
needMeta = True
|
|
|
|
|
info_outdate = True
|
|
|
|
|
else:
|
|
|
|
|
git.resetRepository(rpath, to_rev=revision)
|
|
|
|
|
needMeta = True
|
|
|
|
|
if needMeta:
|
|
|
|
|
info_outdate = True
|
|
|
|
|
if info_outdate:
|
|
|
|
|
dv.Set('cl_update_outdate_set', 'on', force=True)
|
|
|
|
|
finally:
|
|
|
|
|
self.unstash_cache(rpath, name)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def setAutocheckParams(self, status, interval):
|
|
|
|
|
def setAutocheckParams(self, status, interval, update_other, cleanpkg):
|
|
|
|
|
"""
|
|
|
|
|
Настроить параметры автопроверки обновлений
|
|
|
|
|
"""
|
|
|
|
|
status = "on" if status else "off"
|
|
|
|
|
self.clVars.Write('cl_update_autocheck_set', status, True)
|
|
|
|
|
onoff = lambda x: "on" if x else "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)
|
|
|
|
|
self.clVars.Write('cl_update_cleanpkg_set', onoff(cleanpkg), True)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def checkSchedule(self, interval, status):
|
|
|
|
@ -949,21 +955,20 @@ class Update:
|
|
|
|
|
for copyvar in ("cl_dispatch_conf", "cl_verbose_set"):
|
|
|
|
|
dv.Set(copyvar,self.clVars.Get(copyvar),True)
|
|
|
|
|
# определение каталогов содержащих шаблоны
|
|
|
|
|
dirs_list, files_list = ([],[])
|
|
|
|
|
useClt = useClt in ("on",True)
|
|
|
|
|
self.addProgress()
|
|
|
|
|
nullProgress = lambda *args,**kw:None
|
|
|
|
|
dispatch = self.dispatchConf if useDispatch else None
|
|
|
|
|
clTempl = ProgressTemplate(nullProgress,dv,
|
|
|
|
|
cltObj=useClt,
|
|
|
|
|
cltFilter=cltFilter,
|
|
|
|
|
printSUCCESS=self.printSUCCESS,
|
|
|
|
|
printWARNING=self.printWARNING,
|
|
|
|
|
askConfirm=self.askConfirm,
|
|
|
|
|
dispatchConf=dispatch,
|
|
|
|
|
printERROR=self.printERROR)
|
|
|
|
|
clTempl = ProgressTemplate(nullProgress, dv,
|
|
|
|
|
cltObj=useClt,
|
|
|
|
|
cltFilter=cltFilter,
|
|
|
|
|
printSUCCESS=self.printSUCCESS,
|
|
|
|
|
printWARNING=self.printWARNING,
|
|
|
|
|
askConfirm=self.askConfirm,
|
|
|
|
|
dispatchConf=dispatch,
|
|
|
|
|
printERROR=self.printERROR)
|
|
|
|
|
try:
|
|
|
|
|
dirsFiles = clTempl.applyTemplates()
|
|
|
|
|
clTempl.applyTemplates()
|
|
|
|
|
if clTempl.hasError():
|
|
|
|
|
if clTempl.getError():
|
|
|
|
|
raise TemplatesError(clTempl.getError())
|
|
|
|
@ -975,3 +980,42 @@ class Update:
|
|
|
|
|
finally:
|
|
|
|
|
dv.close()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def cleanpkg(self):
|
|
|
|
|
"""
|
|
|
|
|
Очистить distfiles и pkgdir от устаревших пакетов
|
|
|
|
|
"""
|
|
|
|
|
portdirs = ([self.clVars.Get('cl_portdir')] +
|
|
|
|
|
self.clVars.Get('cl_portdir_overlay'))
|
|
|
|
|
pkgfiles = get_packages_files_directory(*portdirs)
|
|
|
|
|
distdirfiles = get_manifest_files_directory(*portdirs)
|
|
|
|
|
distdir = self.clVars.Get('install.cl_distfiles_path')
|
|
|
|
|
pkgdir = self.clVars.Get('cl_pkgdir')
|
|
|
|
|
|
|
|
|
|
skip_files = ["/metadata.dtd", "/Packages"]
|
|
|
|
|
try:
|
|
|
|
|
if self.clVars.Get('client.os_remote_auth'):
|
|
|
|
|
skip_files += ['portage_lockfile']
|
|
|
|
|
except DataVarsError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
logger = log("update_cleanpkg.log",
|
|
|
|
|
filename="/var/log/calculate/update_cleanpkg.log",
|
|
|
|
|
formatter="%(asctime)s - %(clean)s - %(message)s")
|
|
|
|
|
|
|
|
|
|
for cleantype, filelist in (("packages",
|
|
|
|
|
get_remove_list(pkgdir, list(pkgfiles), depth=4)),
|
|
|
|
|
("distfiles",
|
|
|
|
|
get_remove_list(distdir, list(distdirfiles), depth=1))):
|
|
|
|
|
removelist = []
|
|
|
|
|
for fn in filelist:
|
|
|
|
|
try:
|
|
|
|
|
if not any(fn.endswith(x) for x in skip_files):
|
|
|
|
|
os.unlink(fn)
|
|
|
|
|
removelist.append(path.basename(fn))
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
removelist_str = ",".join(removelist)
|
|
|
|
|
if removelist_str:
|
|
|
|
|
logger.info(removelist_str, extra={'clean': cleantype})
|
|
|
|
|
return True
|
|
|
|
|