Bladeren bron

Исправлена работа парсера emerge с использованием --ask.

Добавлен блок skipped packages
tags/3.4.0_beta3
Mike Khiretskiy 6 jaren geleden
bovenliggende
commit
23442e2747
2 gewijzigde bestanden met toevoegingen van 102 en 19 verwijderingen
  1. +100
    -19
      pym/update/emerge_parser.py
  2. +2
    -0
      pym/update/update.py

+ 100
- 19
pym/update/emerge_parser.py Bestand weergeven

@@ -326,8 +326,29 @@ class UninstallPackagesBlock(EmergeInformationBlock):
list_block = XmlConverter().transform(self.result).split()
self.list = PackageList(map(EmergePackage, list_block))

class GroupEmergeInformationBlock(EmergeInformationBlock):
"""
Группа блоков
"""
def get_block(self, child):
self.children_get_block(child)
self.result = True

def children_get_block(self, child):
for block in self.children:
block.get_block(child)

def children_action(self, child):
for block in (x for x in self.children if x.result and x.action):
if block.action(child) is False:
return False

def action(self, child):
self.children_action(child)
return False


class FinishEmergeGroup(EmergeInformationBlock):
class FinishEmergeGroup(GroupEmergeInformationBlock):
"""
Блок завершения команды
"""
@@ -350,19 +371,6 @@ class FinishEmergeGroup(EmergeInformationBlock):
else:
self.result = True

def children_get_block(self, child):
for block in self.children:
block.get_block(child)

def children_action(self, child):
for block in (x for x in self.children if x.result and x.action):
if block.action(child) is False:
break

def action(self, child):
self.children_action(child)
return False


class PrepareErrorBlock(EmergeInformationBlock):
"""
@@ -411,21 +419,89 @@ class DownloadSizeBlock(EmergeInformationBlock):
else:
return "0 kB"

class SkippedPackagesBlock(EmergeInformationBlock):
"""
Размер скачиваемых обновлений
"""
token = "The following update has been skipped"
end_token = ["For more information, see the MASKED"]

class QuestionBlock(EmergeInformationBlock):
re_block = re.compile(
r"(The following update has.*?)(?=For more information)", re.S)

def __str__(self):
if self.result:
return self.result
else:
return ""

class QuestionGroup(GroupEmergeInformationBlock):
"""
Блок вопроса
Группа блоков разбора вопросов от emerge
"""
default_answer = "yes"
_color_block = EmergeInformationBlock._color_block
token = "Would you like"
end_token = ["]", "\n"]
_color_block = EmergeInformationBlock._color_block
re_block = re.compile(
"(Would you.*)\[{c}Yes{c}/{c}No{c}".format(c=_color_block))

def get_block(self, child):
try:
before = child.before
token = child.match
if type(self.end_token) == self.re_type:
child.expect(self.end_token)
match = child.match.group()
else:
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)
block.get_block(child)
if block.result:
break
except pexpect.EOF:
child.buffer = "".join(
[x for x in (child.before, child.after, child.buffer)
if type(x) == str])

class QuestionChangeConfigBlock(GroupEmergeInformationBlock):
"""
Вопрос об изменении конфигурационных файлов
"""
token = "Would you like to add these changes to your config files"

def get_block(self, child):
if child.match:
self.result = self.token
self.children_get_block(child)

def action(self, child):
if self.result:
child.send("no\n")
if child.isalive():
child.wait()
self.children_action(child)


class QuestionBlock(EmergeInformationBlock):
"""
Блок вопроса
"""
default_answer = "yes"
token = "Would you"

def get_block(self, child):
if child.match:
self.result = self.token

def action(self, child):
if self.result:
child.send("%s\n" % self.default_answer)
return False


class NeedRootBlock(EmergeInformationBlock):
@@ -604,11 +680,16 @@ class EmergeParser(object):

self.install_packages = InstallPackagesBlock(self)
self.uninstall_packages = UninstallPackagesBlock(self)
self.question = QuestionBlock(self)
self.question_group = QuestionGroup(self)
self.change_config_question = QuestionChangeConfigBlock(
self.question_group)
self.question = QuestionBlock(self.question_group)
self.finish_block = FinishEmergeGroup(self)
self.need_root = NeedRootBlock(self)
self.prepare_error = PrepareErrorBlock(self.finish_block)
self.change_config_question.add_element(self.prepare_error)
self.download_size = DownloadSizeBlock(self)
self.skipped_packages = SkippedPackagesBlock(self)
self.emerging_error = EmergeingErrorBlock(self)

self.installing = InstallingPackage(self)


+ 2
- 0
pym/update/update.py Bestand weergeven

@@ -773,6 +773,8 @@ class Update(object):
return True
emergelike = self.clVars.Get('cl_update_emergelist_set') == 'on'
self._display_install_package(emerge, emergelike)
if str(emerge.skipped_packages):
self._display_error(emerge.skipped_packages)
except EmergeError:
self.set_need_update(False)
self.emerge_cache.drop_cache("Emerge error")


Laden…
Annuleren
Opslaan