|
|
|
@ -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())
|
|
|
|
|