Добавлена чистка архивов и бинарных пакетов

master3.3
Mike Khiretskiy 10 years ago
parent ec254483f3
commit 732d4cccaf

@ -13,14 +13,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from itertools import ifilter
import random import random
import sys import sys
from os import path from os import path
import os import os
import time 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.cl_template import SystemIni
from calculate.lib.datavars import DataVarsError 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.emerge_parser import RevdepPercentBlock
from calculate.update.datavars import DataVarsUpdate from calculate.update.datavars import DataVarsUpdate
from calculate.update.update_info import UpdateInfo from calculate.update.update_info import UpdateInfo
from calculate.lib.cl_log import log
import re import re
from itertools import chain
from collections import MutableSet from collections import MutableSet
from calculate.lib.utils.portage import Git, Layman,\ from calculate.lib.utils.portage import (Git, Layman, EmergeLog, GitError,
EmergeLogNamedTask, EmergeLog, GitError, \ EmergeLogNamedTask, PackageList,
PackageInformation, PackageList, EmergePackage PackageInformation,
get_packages_files_directory,
get_manifest_files_directory,
get_remove_list)
Colors = TextState.Colors Colors = TextState.Colors
from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir, from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir,
PercentProgress, process, getRunCommands, PercentProgress, process, getRunCommands,
readFile, listDirectory) readFile)
import emerge_parser import emerge_parser
import logging import logging
from emerge_parser import EmergeParser, EmergeCommand, EmergeError, EmergeCache from emerge_parser import EmergeParser, EmergeCommand, EmergeError, EmergeCache
@ -96,7 +100,7 @@ class OverlayOwnCache(MutableSet):
self.__write_overlays(overlays) self.__write_overlays(overlays)
class Update: class Update(object):
"""Основной объект для выполнения действий связанных с обновлением системы """Основной объект для выполнения действий связанных с обновлением системы
""" """
@ -121,7 +125,7 @@ class Update:
""" """
dv = self.clVars dv = self.clVars
git = Git() git = Git()
needMeta = False info_outdate = False
try: try:
self.stash_cache(rpath, name) self.stash_cache(rpath, name)
if not git.checkExistsRep(rpath): if not git.checkExistsRep(rpath):
@ -131,7 +135,7 @@ class Update:
else: else:
git.cloneRevRepository(url, rpath, branch, revision, git.cloneRevRepository(url, rpath, branch, revision,
cb_progress=cb_progress) cb_progress=cb_progress)
needMeta = True info_outdate = True
else: else:
# если нужно обновиться до конкретной ревизии # если нужно обновиться до конкретной ревизии
if revision != "last": if revision != "last":
@ -144,7 +148,7 @@ class Update:
repInfo = git.getStatusInfo(rpath) repInfo = git.getStatusInfo(rpath)
if repInfo['branch'] != branch: if repInfo['branch'] != branch:
# меняем ветку # меняем ветку
needMeta = True info_outdate = True
git.checkoutBranch(rpath, branch) git.checkoutBranch(rpath, branch)
if revision == "last": if revision == "last":
if git.resetRepository(rpath, to_origin=True): if git.resetRepository(rpath, to_origin=True):
@ -152,23 +156,25 @@ class Update:
repInfo = git.getStatusInfo(rpath) repInfo = git.getStatusInfo(rpath)
if repInfo.get("files", False): if repInfo.get("files", False):
raise GitError("Failed to reset git") raise GitError("Failed to reset git")
needMeta = True info_outdate = True
else: else:
git.resetRepository(rpath, to_rev=revision) git.resetRepository(rpath, to_rev=revision)
needMeta = True info_outdate = True
if needMeta: if info_outdate:
dv.Set('cl_update_outdate_set', 'on', force=True) dv.Set('cl_update_outdate_set', 'on', force=True)
finally: finally:
self.unstash_cache(rpath, name) self.unstash_cache(rpath, name)
return True return True
def setAutocheckParams(self, status, interval): def setAutocheckParams(self, status, interval, update_other, cleanpkg):
""" """
Настроить параметры автопроверки обновлений Настроить параметры автопроверки обновлений
""" """
status = "on" if status else "off" onoff = lambda x: "on" if x else "off"
self.clVars.Write('cl_update_autocheck_set', status, True) self.clVars.Write('cl_update_autocheck_set', onoff(status), True)
self.clVars.Write('cl_update_autocheck_interval', interval, 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 return True
def checkSchedule(self, interval, status): def checkSchedule(self, interval, status):
@ -949,21 +955,20 @@ class Update:
for copyvar in ("cl_dispatch_conf", "cl_verbose_set"): for copyvar in ("cl_dispatch_conf", "cl_verbose_set"):
dv.Set(copyvar,self.clVars.Get(copyvar),True) dv.Set(copyvar,self.clVars.Get(copyvar),True)
# определение каталогов содержащих шаблоны # определение каталогов содержащих шаблоны
dirs_list, files_list = ([],[])
useClt = useClt in ("on",True) useClt = useClt in ("on",True)
self.addProgress() self.addProgress()
nullProgress = lambda *args,**kw:None nullProgress = lambda *args,**kw:None
dispatch = self.dispatchConf if useDispatch else None dispatch = self.dispatchConf if useDispatch else None
clTempl = ProgressTemplate(nullProgress,dv, clTempl = ProgressTemplate(nullProgress, dv,
cltObj=useClt, cltObj=useClt,
cltFilter=cltFilter, cltFilter=cltFilter,
printSUCCESS=self.printSUCCESS, printSUCCESS=self.printSUCCESS,
printWARNING=self.printWARNING, printWARNING=self.printWARNING,
askConfirm=self.askConfirm, askConfirm=self.askConfirm,
dispatchConf=dispatch, dispatchConf=dispatch,
printERROR=self.printERROR) printERROR=self.printERROR)
try: try:
dirsFiles = clTempl.applyTemplates() clTempl.applyTemplates()
if clTempl.hasError(): if clTempl.hasError():
if clTempl.getError(): if clTempl.getError():
raise TemplatesError(clTempl.getError()) raise TemplatesError(clTempl.getError())
@ -975,3 +980,42 @@ class Update:
finally: finally:
dv.close() dv.close()
return True 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

@ -41,5 +41,7 @@ class ClSetupUpdateAction(Action):
tasks = [ tasks = [
{'name': 'set_variables', {'name': 'set_variables',
'method': 'Update.setAutocheckParams(cl_update_autocheck_set,' 'method': 'Update.setAutocheckParams(cl_update_autocheck_set,'
'cl_update_autocheck_interval)'} 'cl_update_autocheck_interval,'
'cl_update_other_set,'
'cl_update_cleanpkg_set)'}
] ]

@ -181,9 +181,10 @@ class ClUpdateAction(Action):
'cl_update_autocheck_set)', 'cl_update_autocheck_set)',
'condition': lambda Get: ( 'condition': lambda Get: (
Get('cl_update_autocheck_schedule_set') == 'on'), Get('cl_update_autocheck_schedule_set') == 'on'),
}, },
{'name': 'check_run', {'name': 'check_run',
'method': 'Update.checkRun(cl_update_wait_another_set)'}, 'method': 'Update.checkRun(cl_update_wait_another_set)'
},
{'name': 'reps_synchronization', {'name': 'reps_synchronization',
'group': __("Repositories synchronization"), 'group': __("Repositories synchronization"),
'tasks': [ 'tasks': [
@ -229,6 +230,13 @@ class ClUpdateAction(Action):
Get('cl_update_eixupdate_force') != 'skip' or Get('cl_update_eixupdate_force') != 'skip' or
Get('cl_update_eixupdate_force') == 'force')) Get('cl_update_eixupdate_force') == 'force'))
}, },
{'name': 'sync_reps:cleanpkg',
'message': __("Removing obsolete distfiles and binary packages"),
'method': 'Update.cleanpkg()',
'condition': (lambda Get: Get('cl_update_cleanpkg_set') == 'on' and
Get('cl_update_outdate_set') == 'on'),
'essential': False
},
# сообщение удачного завершения при обновлении репозиториев # сообщение удачного завершения при обновлении репозиториев
{'name': 'success_syncrep', {'name': 'success_syncrep',
'message': __("Synchronization finished"), 'message': __("Synchronization finished"),

@ -282,7 +282,6 @@ class VariableClUpdateOutdateSet(ReadonlyVariable):
Если обновляются прочие оверлеи - данные считаются что устарели Если обновляются прочие оверлеи - данные считаются что устарели
""" """
type = "bool" type = "bool"
value = "off"
def get(self): def get(self):
return self.Get('cl_update_other_set') return self.Get('cl_update_other_set')
@ -1042,6 +1041,7 @@ class VariableClUpdateKernelSrcPath(ReadonlyVariable):
if path.exists(module_build_path): if path.exists(module_build_path):
return os.readlink(module_build_path) return os.readlink(module_build_path)
class VariableClUpdateKernelPkg(ReadonlyVariable): class VariableClUpdateKernelPkg(ReadonlyVariable):
""" """
Пакет текущего ядра Пакет текущего ядра
@ -1054,6 +1054,7 @@ class VariableClUpdateKernelPkg(ReadonlyVariable):
else: else:
return "" return ""
class VariableClUpdateLinesLimit(Variable): class VariableClUpdateLinesLimit(Variable):
""" """
Количество выводимых строк при ошибке Количество выводимых строк при ошибке
@ -1061,6 +1062,7 @@ class VariableClUpdateLinesLimit(Variable):
type = "int" type = "int"
value = "30" value = "30"
class VariableClUpdateSkipSetupSet(Variable): class VariableClUpdateSkipSetupSet(Variable):
""" """
Пропустить выполнение cl-setup-system в cl-update-profile Пропустить выполнение cl-setup-system в cl-update-profile
@ -1072,3 +1074,16 @@ class VariableClUpdateSkipSetupSet(Variable):
def init(self): def init(self):
self.label = _("Skip the system setup") self.label = _("Skip the system setup")
self.help = _("skip the system setup") self.help = _("skip the system setup")
class VariableClUpdateCleanpkgSet(Variable):
"""
Пропустить выполнение cl-setup-system в cl-update-profile
"""
type = "bool"
value = "off"
opt = ["--clean-pkg"]
def init(self):
self.label = _("Clean obsolete programs archives")
self.help = _("clean obsolete programs archives")

@ -69,6 +69,7 @@ class Wsdl(WsdlBase):
'cl_update_other_set', 'cl_update_other_set',
'cl_update_pretend_set', 'cl_update_pretend_set',
'cl_update_sync_rep', 'cl_update_sync_rep',
'cl_update_cleanpkg_set',
'cl_update_emergelist_set', 'cl_update_emergelist_set',
'cl_update_world', 'cl_update_world',
'cl_update_egencache_force', 'cl_update_egencache_force',
@ -164,6 +165,8 @@ class Wsdl(WsdlBase):
'groups': [ 'groups': [
lambda group: group(_("Updates autocheck settings"), lambda group: group(_("Updates autocheck settings"),
normal=('cl_update_autocheck_set', normal=('cl_update_autocheck_set',
'cl_update_autocheck_interval'), 'cl_update_autocheck_interval',
'cl_update_cleanpkg_set',
'cl_update_other_set'),
next_label=_("Save"))]}, next_label=_("Save"))]},
] ]

Loading…
Cancel
Save