some more historydb code

This commit is contained in:
Faik Uygur
2008-01-23 14:34:27 +00:00
parent 39dc7d11f8
commit 12df0e73c1
4 changed files with 39 additions and 3 deletions
+6
View File
@@ -27,6 +27,7 @@ import pisi.db.packagedb
import pisi.db.repodb import pisi.db.repodb
import pisi.db.filesdb import pisi.db.filesdb
import pisi.db.installdb import pisi.db.installdb
import pisi.db.historydb
import pisi.db.sourcedb import pisi.db.sourcedb
import pisi.db.componentdb import pisi.db.componentdb
import pisi.index 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 @param ignore_file_conflicts: Ignores file conflicts during the installation and continues to install
packages. packages.
""" """
historydb = pisi.db.historydb.HistoryDB().create("install")
if not ctx.get_option('ignore_file_conflicts'): if not ctx.get_option('ignore_file_conflicts'):
ctx.set_option('ignore_file_conflicts', 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 # from pisi.atomicoperations import resurrect_package, build
def remove(*args, **kw): def remove(*args, **kw):
pisi.db.historydb.HistoryDB().create("remove")
return pisi.operations.remove.remove(*args, **kw) return pisi.operations.remove.remove(*args, **kw)
def upgrade(*args, **kw): def upgrade(*args, **kw):
pisi.db.historydb.HistoryDB().create("upgrade")
return pisi.operations.upgrade.upgrade(*args, **kw) return pisi.operations.upgrade.upgrade(*args, **kw)
def emerge(*args, **kw): def emerge(*args, **kw):
+2
View File
@@ -47,6 +47,8 @@ class AtomicOperation(object):
else: else:
self.ignore_dep = ignore_dep self.ignore_dep = ignore_dep
self.historydb = pisi.db.historydb.HistoryDB()
def run(self, package): def run(self, package):
"perform an atomic package operation" "perform an atomic package operation"
pass pass
+10
View File
@@ -15,7 +15,9 @@ __trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext _ = __trans.ugettext
import piksemel import piksemel
import pisi.db.lazydb as lazydb import pisi.db.lazydb as lazydb
import pisi.history
class HistoryDB(lazydb.LazyDB): class HistoryDB(lazydb.LazyDB):
@@ -24,3 +26,11 @@ class HistoryDB(lazydb.LazyDB):
def __generate_history(self, doc): def __generate_history(self, doc):
pass 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()
+21 -3
View File
@@ -10,6 +10,7 @@
# Please read the COPYING file. # Please read the COPYING file.
# #
import os
import time import time
import gettext import gettext
__trans = gettext.translation('pisi', fallback=True) __trans = gettext.translation('pisi', fallback=True)
@@ -17,6 +18,7 @@ _ = __trans.ugettext
import pisi.pxml.autoxml as autoxml import pisi.pxml.autoxml as autoxml
import pisi.pxml.xmlfile as xmlfile import pisi.pxml.xmlfile as xmlfile
import pisi.context as ctx
__metaclass__ = autoxml.autoxml __metaclass__ = autoxml.autoxml
@@ -56,28 +58,44 @@ class History(xmlfile.XmlFile):
t_Operation = [Operation, autoxml.mandatory] t_Operation = [Operation, autoxml.mandatory]
def initialize(self, operation): def create(self, operation):
if operation not in ["upgrade", "remove", "install"]: if operation not in ["upgrade", "remove", "install"]:
raise Exception("Unknown package operation") raise Exception("Unknown package operation")
self.histfile = "%s_%s.xml" % (self._get_latest(), operation)
year, month, day, hour, minute = time.localtime()[0:5] year, month, day, hour, minute = time.localtime()[0:5]
self.operation.type = operation self.operation.type = operation
self.operation.date = "%s-%02d-%02d" % (year, month, day) self.operation.date = "%s-%02d-%02d" % (year, month, day)
self.operation.time = "%02d:%02d" % (hour, minute) 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"]: if operation not in ["upgrade", "remove", "install"]:
raise Exception("Unknown package operation") raise Exception("Unknown package operation")
package = Package() package = Package()
package.operation = operation package.operation = operation
package.name = (pkgAfter and pkgAfter.name) or (pkgBefore and pkgBefore.name)
for histInfo, pkgInfo in [(package.before, pkgBefore), (package.after, pkgAfter)]: for histInfo, pkgInfo in [(package.before, pkgBefore), (package.after, pkgAfter)]:
if pkgInfo: if pkgInfo:
histInfo.version = str(pkgInfo.version) histInfo.version = str(pkgInfo.version)
histInfo.release = str(pkgInfo.release) 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) 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)