Browse Source

Добавлено логгирование использования emerge кэша

master3.3
Mike khiretskiy 8 years ago
parent
commit
3f817eedfc
  1. 27
      update/emerge_parser.py
  2. 34
      update/update.py

27
update/emerge_parser.py

@ -32,6 +32,7 @@ from calculate.lib.utils.files import getProgPath, readLinesFile, listDirectory,
from calculate.lib.utils.colortext.output import XmlOutput
from calculate.lib.utils.colortext.converter import (ConsoleCodes256Converter,
XmlConverter)
from calculate.lib.cl_log import log
from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate, _
@ -587,6 +588,9 @@ class EmergeCache(object):
'/etc/make.profile'),
Md5Checkvalue('/var/lib/portage/world',
'/var/lib/portage/world_sets')]
logger = log("emerge-cache",
filename="/var/log/calculate/emerge-cache.log",
formatter="%(asctime)s - %(levelname)s - %(message)s")
def __init__(self):
self.files_control_values = {}
@ -602,14 +606,20 @@ class EmergeCache(object):
f.write('\n')
for pkg in package_list:
f.write("%s\n"% str(pkg))
self.logger.info("Setting cache (%d packages)"%len(package_list))
def drop_cache(self):
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)
else:
self.logger.info("Droping empty cache. Reason: %s"%reason)
def get_cached_package_list(self):
self.read_cache()
if not path.exists(self.cache_file):
self.logger.info("Requesting empty cache")
if self.check_actuality():
return self.pkg_list
return None
@ -618,7 +628,20 @@ class EmergeCache(object):
"""
Кэш считается актуальным если ни один из файлов не менялся
"""
return self.get_control_values() == self.files_control_values
if self.get_control_values() == self.files_control_values:
self.logger.info(
"Getting actuality cache (%d packages)" % len(self.pkg_list))
return True
else:
reason = "Unknown"
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
else:
reason = "Checksum of file %s is not exist" % k
self.logger.info("Failed to get cache. Reason: %s" % reason)
return False
def read_cache(self):
self.files_control_values = {}

34
update/update.py

@ -284,13 +284,10 @@ class Update:
"""
self.endTask()
_print = self.color_print
if max_num > 1:
one = _print.bold("{0}", num)
two = _print.bold("{0}", max_num)
part = _(" ({current} of {maximum})").format(current=one,
maximum=two)
else:
part = ""
one = _print.bold("{0}", num)
two = _print.bold("{0}", max_num)
part = _(" ({current} of {maximum})").format(current=one,
maximum=two)
if self.is_binary_pkg(pkg,binary):
_print = _print.foreground(Colors.PURPLE)
else:
@ -319,13 +316,10 @@ class Update:
"""
self.endTask()
_print = self.color_print
if max_num > 1:
one = _print.bold("{0}", num)
two = _print.bold("{0}", max_num)
part = _(" ({current} of {maximum})").format(current=one,
maximum=two)
else:
part = ""
one = _print.bold("{0}", num)
two = _print.bold("{0}", max_num)
part = _(" ({current} of {maximum})").format(current=one,
maximum=two)
_print = _print.foreground(Colors.RED)
self.startTask(
@ -440,7 +434,8 @@ class Update:
elog = EmergeLog(
EmergeLogNamedTask(ClUpdateAction.log_names['premerge']))
if check and (elog.list or elog.remove_list):
self.emerge_cache.drop_cache()
self.emerge_cache.drop_cache(
"Some packages was installed or removed")
return params, packages
installed_pkgs = elog.list
new_packages = self.emerge_cache.get_cached_package_list()
@ -476,7 +471,8 @@ class Update:
emerge.run()
if "@world" in packages:
if emerge.install_packages.remove_list:
self.emerge_cache.drop_cache()
self.emerge_cache.drop_cache(
"List has packages for remove")
else:
self.updateCache(emerge.install_packages.list)
if not emerge.install_packages.list:
@ -484,7 +480,7 @@ class Update:
return True
self._display_install_package(emerge)
except EmergeError:
self.emerge_cache.drop_cache()
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':
@ -520,7 +516,7 @@ class Update:
try:
emerge.run()
except EmergeError:
self.emerge_cache.drop_cache()
self.emerge_cache.drop_cache("Emerge error")
if emerge.emerging_error:
self.printPre(
self._emerge_translate(emerge.emerging_error.log))
@ -548,7 +544,7 @@ class Update:
if not emerge.install_packages.list:
return True
except EmergeError:
self.emerge_cache.drop_cache()
self.emerge_cache.drop_cache("Emerge error")
self.printPre(self._emerge_translate(emerge.prepare_error))
raise
self._startEmerging(emerge)

Loading…
Cancel
Save