From e35caccf3b0ca36eb77c154555c9dbc28705cc5b Mon Sep 17 00:00:00 2001 From: Mike khiretskiy Date: Wed, 11 Jun 2014 17:01:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20dispatch-conf=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update/update.py | 27 +++++++++++++---- update/update_info.py | 63 +++++++++++++++++++++++++++++++++++++++ update/utils/cl_update.py | 11 +++++-- 3 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 update/update_info.py diff --git a/update/update.py b/update/update.py index 70de1f3..19a1fe2 100644 --- a/update/update.py +++ b/update/update.py @@ -21,6 +21,7 @@ from os import path import os import time from calculate.core.server.gen_pid import search_worked_process, ProcessStatus +from calculate.lib.cl_template import SystemIni from calculate.lib.utils.tools import AddonError from calculate.lib.utils.colortext.palette import TextState @@ -296,8 +297,8 @@ class Update: """ self.endTask() _print = self.color_print - one = _print.bold("{0}", num) - two = _print.bold("{0}", max_num) + one = _print("{0}", num) + two = _print("{0}", max_num) part = _(" ({current} of {maximum})").format(current=one, maximum=two) if self.is_binary_pkg(pkg,binary): @@ -336,15 +337,15 @@ class Update: """ self.endTask() _print = self.color_print - one = _print.bold("{0}", num) - two = _print.bold("{0}", max_num) + one = _print("{0}", num) + two = _print("{0}", max_num) part = _(" ({current} of {maximum})").format(current=one, maximum=two) - _print = _print.foreground(Colors.RED) + _print = _print.foreground(Colors.LIGHT_RED) self.startTask( _("Unmerging{part} {package}").format(part=part, - package=_print.bold(str(pkg)))) + package=_print(str(pkg)))) def emergelike(self, cmd, *params): """ @@ -485,6 +486,7 @@ class Update: if not packages: self.printSUCCESS(_("Installed packages are up to date")) + self.set_need_update(False) return True with EmergeParser(EmergeCommand(list(packages), extra_params=param)) as emerge: @@ -498,14 +500,19 @@ class Update: self.updateCache(emerge.install_packages.list) if not emerge.install_packages.list: self.printSUCCESS(_("The system is up to date")) + self.set_need_update(False) return True self._display_install_package(emerge) except EmergeError: + self.set_need_update(False) self.emerge_cache.drop_cache("Emerge error") self.printPre(self._emerge_translate(emerge.prepare_error)) raise if self.clVars.Get('cl_update_pretend_set') == 'on': + # установить кэш: есть обновления + self.set_need_update() return True + self.set_need_update(False) answer = self.askConfirm( _("Would you like to merge these packages?"), "yes") if answer == "no": @@ -513,6 +520,14 @@ class Update: return "yes" return True + def set_need_update(self, val=True): + """ + Установить флаг: есть обновления + """ + val = "on" if val else "off" + SystemIni().setVar('update', {'packages': val}) + return True + def _emerge_translate(self, s): """ Перевести текст из emerge diff --git a/update/update_info.py b/update/update_info.py new file mode 100644 index 0000000..b713b91 --- /dev/null +++ b/update/update_info.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +# Copyright 2012-2013 Calculate Ltd. http://www.calculate-linux.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 +from calculate.core.datavars import DataVarsCore +from calculate.core.server.gen_pid import search_worked_process +from calculate.lib.cl_template import SystemIni +from calculate.lib.utils.content import getCfgFiles +from calculate.lib.utils.files import getRunCommands + + +class UpdateInfo(object): + """ + Информационный объект о процессе обновления + """ + + def __init__(self, dv=None): + if dv is None: + self.dv = DataVarsCore() + self.dv.importCore() + else: + self.dv = dv + + def need_update(self): + return self.update_ready() or self.check_for_dispatch() + + def update_ready(self): + """ + Проверить есть ли обновления по ini.env + """ + return SystemIni().getVar('update', 'packages') == u'on' + + def check_for_dispatch(self): + """ + Есть ли в системе не примененные файлы для dispatch-conf + """ + return bool(getCfgFiles(self.dv.Get('cl_config_protect'), + prefix=self.dv.Get('cl_chroot_path'))) + + def is_console_gui_run(self): + """ + Проверить есть ли уже запущенная копия console-gui + """ + return any(ifilter(lambda x: "cl-console-gui" in x, getRunCommands())) + + def update_already_run(self): + """ + В системе уже есть работающий процесс обновления + """ + return search_worked_process("update", self.dv) diff --git a/update/utils/cl_update.py b/update/utils/cl_update.py index a58c827..d300ea0 100644 --- a/update/utils/cl_update.py +++ b/update/utils/cl_update.py @@ -266,17 +266,24 @@ class ClUpdateAction(Action): {'name': 'revision', 'message': __("Fixing the settings"), 'method': 'Update.applyTemplates(install.cl_source,' - 'cl_template_clt_set,True,None)', + 'cl_template_clt_set,True,None,False)', 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' or Get('cl_rebuild_world_set') == 'on') }, {'name': 'world', 'message': __("Updating the list of system packages"), 'method': 'Update.applyTemplates(install.cl_source,' - 'cl_template_clt_set,True,None)', + 'cl_template_clt_set,True,None,False)', 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' or Get('cl_rebuild_world_set') == 'on') }, + {'name': 'dispatch_conf', + 'message': __("Updating configuration files"), + 'method':'Update.dispatchConf()', + 'condition': lambda Get: ((Get('cl_update_rev_set') == 'on' or + Get('cl_rebuild_world_set') == 'on') and + Get('cl_update_pretend_set') == 'off') + }, ] } ] + emerge_tasks + [