From 12df0e73c1c04f904c7ffc21ce014d798dc7d53a Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Wed, 23 Jan 2008 14:34:27 +0000 Subject: [PATCH] some more historydb code --- pisi/api.py | 6 ++++++ pisi/atomicoperations.py | 2 ++ pisi/db/historydb.py | 10 ++++++++++ pisi/history.py | 24 +++++++++++++++++++++--- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index 32042c6e..6741ea53 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -27,6 +27,7 @@ import pisi.db.packagedb import pisi.db.repodb import pisi.db.filesdb import pisi.db.installdb +import pisi.db.historydb import pisi.db.sourcedb import pisi.db.componentdb import pisi.index @@ -268,6 +269,9 @@ def install(packages, reinstall=False, ignore_file_conflicts=False): @param ignore_file_conflicts: Ignores file conflicts during the installation and continues to install packages. """ + + historydb = pisi.db.historydb.HistoryDB().create("install") + if not ctx.get_option('ignore_file_conflicts'): ctx.set_option('ignore_file_conflicts', ignore_file_conflicts) @@ -567,9 +571,11 @@ def rebuild_db(files=False): # from pisi.atomicoperations import resurrect_package, build def remove(*args, **kw): + pisi.db.historydb.HistoryDB().create("remove") return pisi.operations.remove.remove(*args, **kw) def upgrade(*args, **kw): + pisi.db.historydb.HistoryDB().create("upgrade") return pisi.operations.upgrade.upgrade(*args, **kw) def emerge(*args, **kw): diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 636d16ea..f85b23c0 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -47,6 +47,8 @@ class AtomicOperation(object): else: self.ignore_dep = ignore_dep + self.historydb = pisi.db.historydb.HistoryDB() + def run(self, package): "perform an atomic package operation" pass diff --git a/pisi/db/historydb.py b/pisi/db/historydb.py index aa9dfe48..ed8b2377 100644 --- a/pisi/db/historydb.py +++ b/pisi/db/historydb.py @@ -15,7 +15,9 @@ __trans = gettext.translation('pisi', fallback=True) _ = __trans.ugettext import piksemel + import pisi.db.lazydb as lazydb +import pisi.history class HistoryDB(lazydb.LazyDB): @@ -24,3 +26,11 @@ class HistoryDB(lazydb.LazyDB): def __generate_history(self, doc): pass + + def create(self, operation): + self.history = pisi.history.History() + self.history.create(operation) + + def update(self, pkgBefore=None, pkgAfter=None, operation=None): + self.history.add(pkgBefore, pkgAfter, operation) + self.history.update() diff --git a/pisi/history.py b/pisi/history.py index a7ac4150..f6af42e0 100644 --- a/pisi/history.py +++ b/pisi/history.py @@ -10,6 +10,7 @@ # Please read the COPYING file. # +import os import time import gettext __trans = gettext.translation('pisi', fallback=True) @@ -17,6 +18,7 @@ _ = __trans.ugettext import pisi.pxml.autoxml as autoxml import pisi.pxml.xmlfile as xmlfile +import pisi.context as ctx __metaclass__ = autoxml.autoxml @@ -56,28 +58,44 @@ class History(xmlfile.XmlFile): t_Operation = [Operation, autoxml.mandatory] - def initialize(self, operation): + def create(self, operation): if operation not in ["upgrade", "remove", "install"]: raise Exception("Unknown package operation") + + self.histfile = "%s_%s.xml" % (self._get_latest(), operation) year, month, day, hour, minute = time.localtime()[0:5] self.operation.type = operation self.operation.date = "%s-%02d-%02d" % (year, month, day) self.operation.time = "%02d:%02d" % (hour, minute) - def add_operation(self, pkgBefore=None, pkgAfter=None, operation=None): + def add(self, pkgBefore=None, pkgAfter=None, operation=None): if operation not in ["upgrade", "remove", "install"]: raise Exception("Unknown package operation") package = Package() package.operation = operation + package.name = (pkgAfter and pkgAfter.name) or (pkgBefore and pkgBefore.name) for histInfo, pkgInfo in [(package.before, pkgBefore), (package.after, pkgAfter)]: if pkgInfo: histInfo.version = str(pkgInfo.version) histInfo.release = str(pkgInfo.release) - histInfo.build = build and str(pkgInfo.build) + histInfo.build = pkgInfo.build and str(pkgInfo.build) self.operation.packages.append(package) + + def update(self): + self.write(os.path.join("%s/%s", ctx.config.history_dir(), self.histfile)) + + def _get_latest(self): + + files = filter(lambda h:h.endswith(".xml"), os.listdir(ctx.config.history_dir())) + if not files: + return "001" + + files.sort() + no, opxml = files[-1].split("_") + return "%03d" % (int(no) + 1)