From b3ca8fed9c2c6fc2f188cbb14b4123a9ead30d59 Mon Sep 17 00:00:00 2001 From: Mike Khiretskiy Date: Thu, 8 Oct 2015 09:13:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/update/datavars.py | 11 +- pym/update/emerge_parser.py | 154 ++++++++++++-------------- pym/update/profile.py | 29 +++-- pym/update/update.py | 25 ++--- pym/update/update_info.py | 3 +- pym/update/update_tasks.py | 2 +- pym/update/utils/cl_setup_update.py | 16 +-- pym/update/utils/cl_update.py | 98 ++++++++-------- pym/update/utils/cl_update_profile.py | 72 ++++++------ pym/update/variables/action.py | 8 +- pym/update/variables/update.py | 21 ++-- pym/update/wsdl_update.py | 13 ++- 12 files changed, 223 insertions(+), 229 deletions(-) diff --git a/pym/update/datavars.py b/pym/update/datavars.py index fb0f660..c43fc0a 100644 --- a/pym/update/datavars.py +++ b/pym/update/datavars.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2012-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2012-2015 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. @@ -14,14 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. __app__ = 'calculate-update' -__version__ = '3.1.8' +__version__ = '3.4.1' -import os import sys from calculate.lib.datavars import DataVars from calculate.lib.cl_lang import setLocalTranslate -setLocalTranslate('cl_update3',sys.modules[__name__]) + +setLocalTranslate('cl_update3', sys.modules[__name__]) class DataVarsUpdate(DataVars): """Variable class for desktop package""" @@ -31,4 +31,3 @@ class DataVarsUpdate(DataVars): self.importVariables() self.importVariables('calculate.update.variables') self.defaultModule = "update" - diff --git a/pym/update/emerge_parser.py b/pym/update/emerge_parser.py index 16ed990..d5efebd 100644 --- a/pym/update/emerge_parser.py +++ b/pym/update/emerge_parser.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2015 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. @@ -13,6 +13,7 @@ # 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. + import hashlib import os @@ -22,13 +23,15 @@ import re import sys from calculate.lib.utils.colortext.palette import TextState from calculate.lib.utils.tools import ignore -from calculate.lib.utils.portage import EmergePackage, PackageList, EmergeUpdateInfo, \ - EmergeRemoveInfo, Git, GitError +from calculate.lib.utils.portage import (EmergePackage, PackageList, + EmergeUpdateInfo, + EmergeRemoveInfo, Git, GitError) Colors = TextState.Colors import pexpect -from calculate.lib.utils.files import getProgPath, readLinesFile, listDirectory, \ - writeFile, readFile +from calculate.lib.utils.files import (getProgPath, readLinesFile, + listDirectory, + writeFile, readFile) from calculate.lib.utils.colortext.output import XmlOutput from calculate.lib.utils.colortext.converter import (ConsoleCodes256Converter, XmlConverter) @@ -39,7 +42,7 @@ from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _ setLocalTranslate('cl_update3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) -linux_term_env = {'TERM':'linux'} +linux_term_env = {'TERM': 'linux'} class EmergeError(Exception): """ @@ -98,20 +101,6 @@ class CommandExecutor(object): if self.child: self.child.send(s) -class ChrootCommandExecutor(CommandExecutor): - """ - Команда запускаемая в chroot - """ - def __init__(self, chroot_path, cmd, params, env=None, cwd=None, - logfile=None): - self.chroot_path = chroot_path - super(ChrootCommandExecutor, self).__init__(cmd, params, env=env, - cwd=cwd, logfile=logfile) - - def get_command(self): - chrootCmd = '/usr/bin/chroot' - return [chrootCmd, self.chroot_path, self.cmd] + self.params - class EmergeCommand(CommandExecutor): """ @@ -119,54 +108,29 @@ class EmergeCommand(CommandExecutor): """ # параметры по умолчанию default_params = ["-av", "--color=y", "--nospinner"] - cmd = getProgPath("/usr/bin/emerge") + emerge_cmd = getProgPath("/usr/bin/emerge") def __init__(self, packages, extra_params=None, env=None, cwd=None, logfile=None, emerge_default_opts=None, use=""): extra_params = extra_params or [] - self.child = None - self.packages = packages - self.params = self.default_params + extra_params - if emerge_default_opts is None: - default_env = {'CLEAN_DELAY': '0'} - else: - default_env = { - 'CLEAN_DELAY': '0', - 'EMERGE_DEFAULT_OPTS': re.sub(r'(?:^|\s)(--columns)(?=\s|$)','', - emerge_default_opts) - } - if use: - default_env["USE"] = use - default_env.update(os.environ) - self.env = env or default_env - self.env.update(linux_term_env) - self.cwd = cwd - if logfile: - self.logfile = logfile - - def get_command(self): - return [self.cmd] + self.params + self.packages - + if env is None: + if emerge_default_opts is None: + env = {'CLEAN_DELAY': '0'} + else: + env = { + 'CLEAN_DELAY': '0', + 'EMERGE_DEFAULT_OPTS': re.sub( + r'(?:^|\s)(--columns)(?=\s|$)', '', + emerge_default_opts) + } + if use: + env["USE"] = use + env.update(os.environ) -class ChrootEmergeCommand(EmergeCommand): - def __init__(self, chroot_path, *args, **kw): - self.chroot_path = chroot_path + params = self.default_params + extra_params + packages + super(EmergeCommand, self).__init__(self.emerge_cmd, params=params, + env=env, cwd=cwd, logfile=logfile) - super(ChrootEmergeCommand, self).__init__(*args, **kw) - - def get_command(self): - chrootCmd = '/usr/bin/chroot' - bashCmd = '/bin/bash' - bash_command = ( - "env-update &>/dev/null;" - "source /etc/profile &>/dev/null;" - "{emerge_command} {params} {packages}".format( - emerge_command=self.cmd, - params=" ".join(self.params), - packages=" ".join(self.packages) - )) - return [chrootCmd, self.chroot_path, bashCmd, "-c", - bash_command] def Chroot(chroot_path, obj): """ @@ -203,19 +167,36 @@ def Linux32(obj): return obj -class EmergeInformationBlock(object): +class InfoBlockInterface(object): + """ + Интерфейс для информационного блока + """ + action = None + token = None + result = None + text_converter = ConsoleCodes256Converter(XmlOutput()) + + def get_block(self, child): + pass + + def add_element(self, element): + """ + :type element: InfoBlockInterface + """ + pass + + +class EmergeInformationBlock(InfoBlockInterface): _color_block = "(?:\033\[[^m]+?m)?" _new_line = "(?:\r*\n)" - token = None end_token = ["\n"] re_block = None - action = None re_match_type = type(re.match("", "")) re_type = type(re.compile("")) def __init__(self, parent): """ - :type parent: EmergeParser + :type parent: InfoBlockInterface """ self.result = None self.text_converter = parent.text_converter @@ -224,6 +205,9 @@ class EmergeInformationBlock(object): self.children = [] def add_element(self, element): + """ + :type element: InfoBlockInterface + """ self.children.append(element) def __str__(self): @@ -308,7 +292,7 @@ class UninstallPackagesBlock(EmergeInformationBlock): _new_line = EmergeInformationBlock._new_line _color_block = EmergeInformationBlock._color_block token = ["Calculating removal order", - "These are the packages that would be unmerged",] + "These are the packages that would be unmerged"] end_token = re.compile("All selected packages:.*\n") re_block = re.compile( r"(?:{token}).*?{nl}(.*){nl}All selected packages: (.*?){nl}". @@ -326,6 +310,7 @@ class UninstallPackagesBlock(EmergeInformationBlock): list_block = XmlConverter().transform(self.result).split() self.list = PackageList(map(EmergePackage, list_block)) + class GroupEmergeInformationBlock(EmergeInformationBlock): """ Группа блоков @@ -456,7 +441,6 @@ class QuestionGroup(GroupEmergeInformationBlock): child.expect_exact(self.end_token) match = child.match data = token + child.before + match - #self.get_data(before + data) child.before = before for block in self.children: child.match = re.search(block.token, data) @@ -668,13 +652,12 @@ class RevdepPercentBlock(NotifierInformationBlock): except pexpect.EOF: self.result = "" -class EmergeParser(object): +class EmergeParser(InfoBlockInterface): """ Парсер вывода emerge """ def __init__(self, command, run=False): - self.text_converter = ConsoleCodes256Converter(XmlOutput()) self.command = command self.elements = {} @@ -710,6 +693,9 @@ class EmergeParser(object): self.fetching.action = lambda child: None def add_element(self, element): + """ + :type element: InfoBlockInterface + """ if element.token: if type(element.token) == list: for token in element.token: @@ -765,6 +751,7 @@ class Md5Checkvalue(MtimeCheckvalue): def value_func(self, fn): return hashlib.md5(readFile(fn)).hexdigest() + class GitCheckvalue(object): def __init__(self, rpath): self.rpath = rpath @@ -783,10 +770,10 @@ class EmergeCache(object): cache_file = '/var/lib/calculate/calculate-update/world.cache' # список файлов проверяемый по mtime на изменения check_list = [MtimeCheckvalue('/etc/make.conf', - '/etc/portage', - '/etc/make.profile'), + '/etc/portage', + '/etc/make.profile'), Md5Checkvalue('/var/lib/portage/world', - '/var/lib/portage/world_sets')] + '/var/lib/portage/world_sets')] logger = log("emerge-cache", filename="/var/log/calculate/emerge-cache.log", formatter="%(asctime)s - %(levelname)s - %(message)s") @@ -804,16 +791,16 @@ class EmergeCache(object): f.write("{fn}={val}\n".format(fn=fn, val=val)) f.write('\n') for pkg in package_list: - f.write("%s\n"% str(pkg)) - self.logger.info("Setting cache (%d packages)"%len(package_list)) + f.write("%s\n" % str(pkg)) + self.logger.info("Setting cache (%d packages)" % len(package_list)) def drop_cache(self, reason=None): if path.exists(self.cache_file): with ignore(OSError): os.unlink(self.cache_file) - self.logger.info("Droping cache. Reason: %s"%reason) + self.logger.info("Droping cache. Reason: %s" % reason) else: - self.logger.info("Droping empty cache. Reason: %s"%reason) + self.logger.info("Droping empty cache. Reason: %s" % reason) def get_cached_package_list(self): self.read_cache() @@ -833,10 +820,10 @@ class EmergeCache(object): return True else: reason = "Unknown" - for k,v in self.get_control_values().items(): + for k, v in self.get_control_values().items(): if k in self.files_control_values: if v != self.files_control_values[k]: - reason = "%s was modified"%k + reason = "%s was modified" % k else: reason = "Checksum of file %s is not exist" % k self.logger.info("Failed to get cache. Reason: %s" % reason) @@ -846,7 +833,7 @@ class EmergeCache(object): self.files_control_values = {} cache_file_lines = readLinesFile(self.cache_file) for line in cache_file_lines: - if not "=" in line: + if "=" not in line: break k, v = line.split('=') self.files_control_values[k] = v.strip() @@ -855,6 +842,7 @@ class EmergeCache(object): def get_control_values(self): def generate(): for obj in self.check_list: - for checkvalue in obj.checkvalues(): - yield checkvalue + for check_value in obj.checkvalues(): + yield check_value + return dict(generate()) diff --git a/pym/update/profile.py b/pym/update/profile.py index 2a14eaf..08d786e 100644 --- a/pym/update/profile.py +++ b/pym/update/profile.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2014-2015 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. @@ -13,12 +13,12 @@ # 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. + import sys from os import path import shutil -import os -from calculate.lib.utils.files import listDirectory, readFile, readLinesFile, \ - makeDirectory, removeDir +from calculate.lib.utils.files import (listDirectory, readFile, readLinesFile, + makeDirectory, removeDir) from calculate.lib.utils.git import Git from update import UpdateError @@ -27,8 +27,17 @@ setLocalTranslate('cl_update3', sys.modules[__name__]) DEFAULT_BRANCH = Git.Reference.Master +class RepositoryStorageInterface(object): + def __iter__(self): + raise StopIteration + + def get_profiles(self, url, branch=DEFAULT_BRANCH): + return [] + + def get_repository(self, url, branch=DEFAULT_BRANCH): + return None -class RepositoryStorage(object): +class RepositoryStorage(RepositoryStorageInterface): directory = '/tmp' def __init__(self, directory): @@ -44,6 +53,10 @@ class RepositoryStorage(object): def get_profiles(self, url, branch=DEFAULT_BRANCH): return [] + def get_repository(self, url, branch=DEFAULT_BRANCH): + return None + + class ProfileStorage(RepositoryStorage): def get_profiles(self, url, branch=DEFAULT_BRANCH): rep = self.get_repository(url, branch) @@ -54,6 +67,7 @@ class ProfileStorage(RepositoryStorage): def get_repository(self, url, branch=DEFAULT_BRANCH): return None + class LocalStorage(ProfileStorage): """ Локальное хранилище репозиториев, при запросе по урлу смотрит, доступные @@ -64,7 +78,6 @@ class LocalStorage(ProfileStorage): if rep.is_like(url, branch): return rep - class CacheStorage(ProfileStorage): """ Хранилище репозиториев, при запросе по урлу смотрит, доступные @@ -78,7 +91,7 @@ class CacheStorage(ProfileStorage): else: return ProfileRepository.clone(url, self, branch) -class RepositoryStorageSet(RepositoryStorage): +class RepositoryStorageSet(RepositoryStorageInterface): """ Набор хранилищ репозиториев """ diff --git a/pym/update/update.py b/pym/update/update.py index bbd3232..7cd039c 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2014-2015 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. @@ -13,7 +13,7 @@ # 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 functools import wraps, partial +from functools import wraps import random import sys @@ -52,7 +52,7 @@ from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir, import emerge_parser import logging from emerge_parser import (EmergeParser, EmergeCommand, EmergeError, - EmergeCache, ChrootEmergeCommand) + EmergeCache, Chroot) from calculate.lib.cl_lang import (setLocalTranslate, getLazyLocalTranslate, RegexpLocalization, _) @@ -141,8 +141,7 @@ class Update(MethodsInterface): self.update_map = {} self.refresh_binhost = False - @staticmethod - def get_prog_path(program_name): + def get_prog_path(self, program_name): return getProgPath(program_name) def _syncRepository(self, name, url, rpath, revision, @@ -850,11 +849,6 @@ class Update(MethodsInterface): """ Выполнить сборку пакета """ - if self.clVars.Get('cl_chroot_path') != '/': - command_class = partial(ChrootEmergeCommand, - self.clVars.Get('cl_chroot_path')) - else: - command_class = EmergeCommand deo = self.clVars.Get('cl_emerge_default_opts') if not packages: packages = [param] @@ -864,9 +858,14 @@ class Update(MethodsInterface): if not packages: return True extra_params = [param] - with EmergeParser(command_class(list(packages), emerge_default_opts=deo, - extra_params=extra_params, - use=use)) as emerge: + + command = EmergeCommand(list(packages), emerge_default_opts=deo, + extra_params=extra_params, + use=use) + if self.clVars.Get('cl_chroot_path') != '/': + command = Chroot(self.clVars.Get('cl_chroot_path'), command) + + with EmergeParser(command) as emerge: try: emerge.question.action = lambda x: False emerge.run() diff --git a/pym/update/update_info.py b/pym/update/update_info.py index 622ba35..bdcb096 100644 --- a/pym/update/update_info.py +++ b/pym/update/update_info.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2012-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2012-2015 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. @@ -22,7 +22,6 @@ 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, readFile, writeFile -import time class UpdateInfo(object): diff --git a/pym/update/update_tasks.py b/pym/update/update_tasks.py index 8ed978f..cd6db3c 100644 --- a/pym/update/update_tasks.py +++ b/pym/update/update_tasks.py @@ -1,4 +1,4 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Copyright 2015 Calculate Ltd. http://www.calculate-linux.org # diff --git a/pym/update/utils/cl_setup_update.py b/pym/update/utils/cl_setup_update.py index 31a26e7..ec22b70 100644 --- a/pym/update/utils/cl_setup_update.py +++ b/pym/update/utils/cl_setup_update.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2010-2015 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. @@ -15,12 +15,13 @@ # limitations under the License. import sys -from calculate.core.server.func import Action, Tasks +from calculate.core.server.func import Action from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate from calculate.lib.utils.files import FilesError from calculate.update.update import UpdateError from calculate.lib.utils.portage import GitError +_ = lambda x: x setLocalTranslate('cl_update3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) @@ -36,12 +37,11 @@ class ClSetupUpdateAction(Action): failedMessage = __("Failed to configure the updates autocheck procedure!") interruptMessage = __("Configuration manually interrupted") - # список задач для действия tasks = [ {'name': 'set_variables', 'method': 'Update.setAutocheckParams(cl_update_autocheck_set,' - 'cl_update_autocheck_interval,' - 'cl_update_other_set,' - 'cl_update_cleanpkg_set)'} - ] + 'cl_update_autocheck_interval,' + 'cl_update_other_set,' + 'cl_update_cleanpkg_set)'} + ] diff --git a/pym/update/utils/cl_update.py b/pym/update/utils/cl_update.py index adab3e1..bbeb50e 100644 --- a/pym/update/utils/cl_update.py +++ b/pym/update/utils/cl_update.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2010-2015 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. @@ -18,37 +18,27 @@ import sys from calculate.core.server.func import Action, Tasks from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate from calculate.lib.cl_template import TemplatesError -from calculate.lib.utils.colortext import get_color_print, Colors from calculate.lib.utils.files import FilesError from calculate.update.update import UpdateError from calculate.update.emerge_parser import EmergeError -from calculate.lib.utils.portage import GitError, Eix, EmergeLog, \ - EmergeLogNamedTask, PackageList -from ..update_tasks import EmergeMark +from calculate.lib.utils.portage import (GitError, EmergeLog, + EmergeLogNamedTask, PackageList) +from calculate.update.update_tasks import EmergeMark +_ = lambda x: x setLocalTranslate('cl_update3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) -class ClUpdateAction(Action): - """ - Действие обновление конфигурационных файлов - """ - # ошибки, которые отображаются без подробностей - native_error = (FilesError, UpdateError, - TemplatesError, - GitError, EmergeError) - - successMessage = None - failedMessage = None - interruptMessage = __("Update manually interrupted") - +class UpdateConditions(object): + @staticmethod def was_installed(pkg, task_name): def func(): task = EmergeLog(EmergeLogNamedTask(task_name)) return bool(PackageList(task.list)[pkg]) return func + @staticmethod def need_depclean(pkg, task_name): def func(Get): task = EmergeLog(EmergeLogNamedTask(task_name)) @@ -56,14 +46,19 @@ class ClUpdateAction(Action): or Get('cl_update_outdated_kernel_set') == 'on') return func - def need_upgrade(pkg): - # TODO: возможно функция не работает - def func(): - return bool(Eix(pkg, Eix.Option.Upgrade).get_packages()) - return func - def pkg_color(text): - return text +class ClUpdateAction(Action): + """ + Действие обновление конфигурационных файлов + """ + # ошибки, которые отображаются без подробностей + native_error = (FilesError, UpdateError, + TemplatesError, + GitError, EmergeError) + + successMessage = None + failedMessage = None + interruptMessage = __("Update manually interrupted") emerge_tasks = [ {'name': 'premerge_group', @@ -74,24 +69,24 @@ class ClUpdateAction(Action): 'method': 'Update.premerge("-uDN","--with-bdeps=y","@world")', 'condition': lambda Get:Get('cl_update_sync_only_set') == 'off' }], - }, + }, {'name': 'premerge:update', 'condition': lambda Get:Get('cl_update_pretend_set') == 'off', 'depend': Tasks.result("premerge", eq='yes') - }, + }, {'name': 'update_other', 'condition': lambda Get: ( Get('cl_update_pretend_set') == 'off' and Get('cl_update_sync_only_set') == 'off') - }, + }, {'name': 'update:update_world', 'group': __("Updating packages"), 'tasks': [ {'name': 'update:update_world', 'message': __("Calculating dependencies"), 'method': 'Update.emerge("","-uDN","--with-bdeps=y","@world")', - } + } ] - }, + }, {'name': 'update:update_python', 'group': __("Updating Python"), 'tasks': [ @@ -99,11 +94,11 @@ class ClUpdateAction(Action): 'message': __('Find & rebuild packages broken due ' 'to a Python upgrade'), 'method': 'Update.emergelike("python-updater")', - 'condition': was_installed('dev-lang/python$', - EmergeMark.PythonUpdater), + 'condition': UpdateConditions.was_installed( + 'dev-lang/python$', EmergeMark.PythonUpdater), 'decoration': 'Update.update_task("%s")' % EmergeMark.PythonUpdater - }, + }, ] }, {'name': 'update:update_perl', @@ -113,8 +108,8 @@ class ClUpdateAction(Action): 'message': __('Find & rebuild packages and Perl header files ' 'broken due to a perl upgrade'), 'method': 'Update.emergelike("perl-cleaner", "all")', - 'condition': was_installed('dev-lang/perl$', - EmergeMark.PerlCleaner), + 'condition': UpdateConditions.was_installed( + 'dev-lang/perl$', EmergeMark.PerlCleaner), 'decoration': 'Update.update_task("%s")' % EmergeMark.PerlCleaner }, ] @@ -125,7 +120,8 @@ class ClUpdateAction(Action): {'name': 'update_other:update_depclean', 'message': __("Calculating dependencies"), 'method': 'Update.depclean()', - 'condition': need_depclean('.*', EmergeMark.Depclean), + 'condition': UpdateConditions.need_depclean( + '.*', EmergeMark.Depclean), 'decoration': 'Update.update_task("%s")' % EmergeMark.Depclean }, ] @@ -136,38 +132,40 @@ class ClUpdateAction(Action): {'name': 'update_other:module_rebuild', 'message': __('Updating Kernel modules'), 'method': 'Update.emerge("","@module-rebuild")', - 'condition': was_installed('sys-kernel/.*source', - EmergeMark.KernelModules), + 'condition': UpdateConditions.was_installed( + 'sys-kernel/.*source', EmergeMark.KernelModules), 'decoration': 'Update.update_task("%s")' % EmergeMark.KernelModules }, {'name': 'update_other:x11_module_rebuild', 'message': __('Updating X.Org server modules'), 'method': 'Update.emerge("","@x11-module-rebuild")', - 'condition': was_installed('x11-base/xorg-server', - EmergeMark.XorgModules), + 'condition': UpdateConditions.was_installed( + 'x11-base/xorg-server', EmergeMark.XorgModules), 'decoration': 'Update.update_task("%s")' % EmergeMark.XorgModules }, {'name': 'update_other:preserved_rebuild', 'message': __('Updating preserved libraries'), 'method': 'Update.emerge("","@preserved-rebuild")', - 'condition': was_installed('.*', EmergeMark.PreservedLibs), + 'condition': UpdateConditions.was_installed( + '.*', EmergeMark.PreservedLibs), 'decoration': 'Update.update_task("%s")' % EmergeMark.PreservedLibs }, {'name': 'update_other:revdev_rebuild', 'message': __('Checking reverse dependencies'), 'method': 'Update.revdep_rebuild("revdep-rebuild")', - 'condition': lambda Get:(Get('cl_update_skip_rb_set') == 'off' - and ClUpdateAction.was_installed('.*', - EmergeMark.RevdepRebuild)()), + 'condition': lambda Get: (Get( + 'cl_update_skip_rb_set') == 'off' and + UpdateConditions.was_installed( + '.*', EmergeMark.RevdepRebuild)()), 'decoration': 'Update.update_task("%s")' % EmergeMark.RevdepRebuild }, {'name': 'update_other:dispatch_conf_end', 'message': __("Updating configuration files"), - 'method':'Update.dispatchConf()', + 'method': 'Update.dispatchConf()', 'condition': lambda Get: (Get('cl_dispatch_conf') != 'skip' and Get('cl_update_pretend_set') == 'off') }, @@ -305,18 +303,16 @@ class ClUpdateAction(Action): Tasks.success_all("check_schedule")))}, {'name': 'failed', 'depend': Tasks.failed_all("check_schedule") - }, + }, # сообщение удачного завершения при обновлении ревизии {'name': 'success_rev', 'message': __("System update finished!"), 'condition': lambda Get: (Get('cl_update_rev_set') == 'on' and Get('cl_update_pretend_set') == 'off') - }, + }, # сообщение удачного завершения при пересоздании world {'name': 'success_world', 'message': __("World rebuild finished!"), 'condition': lambda Get: Get('cl_rebuild_world_set') == 'on' - }, + }, ] - - was_installed = staticmethod(was_installed) diff --git a/pym/update/utils/cl_update_profile.py b/pym/update/utils/cl_update_profile.py index f881a27..c60432b 100644 --- a/pym/update/utils/cl_update_profile.py +++ b/pym/update/utils/cl_update_profile.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2010-2015 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. @@ -22,6 +22,7 @@ from calculate.lib.utils.files import FilesError from calculate.update.update import UpdateError from calculate.lib.utils.portage import GitError +_ = lambda x: x setLocalTranslate('cl_update3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) @@ -39,7 +40,6 @@ class ClUpdateProfileAction(Action): failedMessage = __("Failed to update the profile") interruptMessage = __("Profile update manually interrupted") - # список задач для действия tasks = [ {'name': 'migrate_repository', @@ -51,18 +51,18 @@ class ClUpdateProfileAction(Action): Get('cl_update_profile_storage').is_local( Get('cl_update_profile_url'), Get('cl_update_profile_branch'))) - }, + }, {'name': 'reconfigure_vars1', 'method': 'Update.invalidateVariables("cl_update_profile_storage")', 'depend': Tasks.has('migrate_repository') - }, + }, {'name': 'drop_binhosts', 'method': 'Update.drop_binhosts(update.cl_update_profile_datavars)' }, {'name': 'reconfigure_vars', 'method': 'Update.reconfigureProfileVars(cl_update_profile_datavars,' 'cl_chroot_path)' - }, + }, {'name': 'reps_synchronization', 'group': __("Repositories synchronization"), 'tasks': [ @@ -70,8 +70,9 @@ class ClUpdateProfileAction(Action): 'foreach': 'cl_update_profile_sync_rep', 'message': __("Syncing the {eachvar:capitalize} repository"), 'method': 'Update.syncRepositories(eachvar)', - #'condition': lambda Get: Get('cl_update_profile_sync_rep') - }, + # TODO: неиспользуемое условие + # 'condition': lambda Get: Get('cl_update_profile_sync_rep') + }, {'name': 'sync_reps:regen_cache', 'foreach': 'cl_update_sync_overlay_rep', 'message': __("Updating the {eachvar:capitalize} repository cache"), @@ -81,7 +82,7 @@ class ClUpdateProfileAction(Action): lambda Get: (Get('cl_update_outdate_set') == 'on' and Get('cl_update_metadata_force') != 'skip' or Get('cl_update_metadata_force') == 'force')) - }, + }, {'name': 'emerge_metadata', 'message': __("Metadata transfer"), 'method': 'Update.emergeMetadata()', @@ -89,7 +90,7 @@ class ClUpdateProfileAction(Action): lambda Get: (Get('cl_update_outdate_set') == 'on' and Get('cl_update_metadata_force') != 'skip' or Get('cl_update_metadata_force') == 'force')) - }, + }, {'name': 'eix_update', 'message': __("Updating the eix cache"), 'method': 'Update.eixUpdate(cl_repository_name)', @@ -97,7 +98,7 @@ class ClUpdateProfileAction(Action): lambda Get: (Get('cl_update_outdate_set') == 'on' and Get('cl_update_eixupdate_force') != 'skip' or Get('cl_update_eixupdate_force') == 'force')) - }, + }, # сообщение удачного завершения при обновлении репозиториев {'name': 'success_syncrep', 'message': __("Synchronization finished"), @@ -107,32 +108,33 @@ class ClUpdateProfileAction(Action): "eix_update")), } ] - }, + }, {'name': 'reps_synchronization', 'group': __("Setting up the profile"), 'tasks': [ - {'name': 'set_profile', - 'message': __("Switching to profile {cl_update_profile_system}"), - 'method': 'Update.setProfile(cl_update_profile_system)' - }, - {'name': 'revision', - 'message': __("Fixing the settings"), - 'method': 'Update.applyProfileTemplates(cl_template_clt_set,' - 'True,False,"update_profile")', - 'condition': lambda Get: Get('cl_templates_locate') - }, - {'name': 'reconfigure', - 'message': __("The system is being configured"), - 'method': 'Update.applyProfileTemplates(cl_template_clt_set,' - 'True,False,"merge")', - 'condition': lambda Get: (Get('cl_update_templates_locate') and - Get('cl_update_skip_setup_set') == 'off') - }, - {'name': 'dispatch_conf', - 'message': __("Updating configuration files"), - 'method':'Update.dispatchConf()', - 'condition': lambda Get: Get('cl_dispatch_conf') != 'skip' - }, + {'name': 'set_profile', + 'message': __("Switching to profile {cl_update_profile_system}"), + 'method': 'Update.setProfile(cl_update_profile_system)' + }, + {'name': 'revision', + 'message': __("Fixing the settings"), + 'method': 'Update.applyProfileTemplates(cl_template_clt_set,' + 'True,False,"update_profile")', + 'condition': lambda Get: Get('cl_templates_locate') + }, + {'name': 'reconfigure', + 'message': __("The system is being configured"), + 'method': 'Update.applyProfileTemplates(cl_template_clt_set,' + 'True,False,"merge")', + 'condition': lambda Get: ( + Get('cl_update_templates_locate') and + Get('cl_update_skip_setup_set') == 'off') + }, + {'name': 'dispatch_conf', + 'message': __("Updating configuration files"), + 'method': 'Update.dispatchConf()', + 'condition': lambda Get: Get('cl_dispatch_conf') != 'skip' + }, ] - } + } ] diff --git a/pym/update/variables/action.py b/pym/update/variables/action.py index 799b1f3..8858f8d 100644 --- a/pym/update/variables/action.py +++ b/pym/update/variables/action.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2013-2015 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. @@ -14,10 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import sys -from os import path -from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable +from calculate.lib.datavars import ReadonlyVariable from calculate.lib.cl_lang import setLocalTranslate setLocalTranslate('cl_update3',sys.modules[__name__]) diff --git a/pym/update/variables/update.py b/pym/update/variables/update.py index 40c41b1..819315b 100644 --- a/pym/update/variables/update.py +++ b/pym/update/variables/update.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2013-2015 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. @@ -19,18 +19,17 @@ import sys import re from os import path from calculate.lib.datavars import (Variable, VariableError, - ReadonlyVariable, ReadonlyTableVariable, TableVariable, FieldValue, - SimpleDataVars, DataVarsError) -from calculate.lib.utils.files import readFile, \ - listDirectory, process, pathJoin -from calculate.lib.utils.git import Git + ReadonlyVariable, ReadonlyTableVariable, + TableVariable, FieldValue, + SimpleDataVars, DataVarsError) +from calculate.lib.utils.files import readFile, listDirectory, process, pathJoin from calculate.lib.configparser import ConfigParser from calculate.lib.cl_lang import setLocalTranslate from calculate.lib.utils.text import simplify_profiles from calculate.lib.utils.portage import Git, GitError, Layman -from ..profile import RepositoryStorageSet, DEFAULT_BRANCH, \ - LocalStorage, ProfileRepository, CacheStorage +from ..profile import (RepositoryStorageSet, DEFAULT_BRANCH, + LocalStorage, ProfileRepository, CacheStorage) from calculate.lib.variables import linux as lib_linux from calculate.lib.variables import env @@ -38,7 +37,7 @@ from calculate.update.update_info import UpdateInfo import urllib2 import time -_ = lambda x:x +_ = lambda x: x setLocalTranslate('cl_update3', sys.modules[__name__]) @@ -552,7 +551,7 @@ class VariableClUpdateOtherRepData(ReadonlyTableVariable): if rname in layman_overlays and rname not in repNames: yield (rname, rpath) - def get(self): + def get(self, hr=False): return list(self.generator()) class VariableClUpdateOtherRepName(FieldValue,ReadonlyVariable): diff --git a/pym/update/wsdl_update.py b/pym/update/wsdl_update.py index bf83d2c..4565574 100644 --- a/pym/update/wsdl_update.py +++ b/pym/update/wsdl_update.py @@ -1,6 +1,6 @@ -#-*- coding: utf-8 -*- +# -*- coding: utf-8 -*- -# Copyright 2010-2013 Calculate Ltd. http://www.calculate-linux.org +# Copyright 2010-2015 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. @@ -16,17 +16,18 @@ import sys -from calculate.lib.datavars import VariableError,DataVarsError,DataVars +from calculate.lib.datavars import VariableError,DataVarsError from calculate.core.server.func import WsdlBase from calculate.install.install import InstallError -from calculate.update.update import Update,UpdateError +from calculate.update.update import Update, UpdateError from calculate.lib.utils.portage import GitError from utils.cl_update import ClUpdateAction from utils.cl_update_profile import ClUpdateProfileAction from utils.cl_setup_update import ClSetupUpdateAction -from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate -setLocalTranslate('cl_update3',sys.modules[__name__]) +from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _ + +setLocalTranslate('cl_update3', sys.modules[__name__]) __ = getLazyLocalTranslate(_)