From 137f072c499aae16b9b05c487f1d836266057210 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 24 Feb 2021 13:27:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=20=D0=B2=D1=8B?= =?UTF-8?q?=D1=87=D0=B8=D1=81=D0=BB=D1=8F=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20?= =?UTF-8?q?=D1=81=D1=83=D0=BC=D0=BC=D1=83=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=20/etc/portage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/utils/portage.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pym/calculate/lib/utils/portage.py b/pym/calculate/lib/utils/portage.py index edce2bb..3fe8c1a 100644 --- a/pym/calculate/lib/utils/portage.py +++ b/pym/calculate/lib/utils/portage.py @@ -40,6 +40,7 @@ from .common import getTupleVersion from contextlib import closing from functools import total_ordering from itertools import ifilter, imap, chain, groupby +import hashlib Colors = TextState.Colors import glob @@ -1789,3 +1790,38 @@ def clear_binhost_garbage(dn): fullpath=True): if fn.endswith(".portage.lockfile") or fn.endswith(".partial"): os.unlink(fn) + +class PortageState(object): + """ + Подсчёт контрольной суммы для определения изменений /etc/portage + """ + paths = ["/etc/portage", "/var/log/emerge.log"] + + def __init__(self, prefix='/'): + self.prefix = prefix + + def readFileContent(self, fn): + if fn.endswith("/var/log/emerge.log"): + return readFile(fn)[:-200] + return readFile(fn) + + def getpathdata(self, fn): + yield "%s"%fn + if path.lexists(fn): + if path.islink(fn): + yield os.readlink(fn) + elif path.isdir(fn): + for x in os.listdir(fn): + dfn = pathJoin(fn, x) + for dirdata in self.getpathdata(dfn): + yield dirdata + else: + yield readFile(fn) + + def get_state(self): + m = hashlib.md5() + for dn in self.paths: + fdn = pathJoin(self.prefix, dn) + for data in self.getpathdata(fdn): + m.update(data) + return m.hexdigest()