Add pisi history --snapshot cmd

This commit is contained in:
Faik Uygur
2008-02-11 12:32:16 +00:00
parent 6ec978e8db
commit d009a2fdad
5 changed files with 56 additions and 18 deletions
+20 -4
View File
@@ -262,7 +262,6 @@ def search_file(term):
term = term[1:] term = term[1:]
return filesdb.search_file(term) return filesdb.search_file(term)
def install(packages, reinstall=False, ignore_file_conflicts=False): def install(packages, reinstall=False, ignore_file_conflicts=False):
""" """
Returns True if no errors occured during the operation Returns True if no errors occured during the operation
@@ -272,7 +271,7 @@ def install(packages, reinstall=False, ignore_file_conflicts=False):
packages. packages.
""" """
historydb = pisi.db.historydb.HistoryDB().create("install") pisi.db.historydb.HistoryDB().create_history("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)
@@ -283,6 +282,23 @@ def install(packages, reinstall=False, ignore_file_conflicts=False):
else: else:
return pisi.operations.install.install_pkg_names(packages, reinstall) return pisi.operations.install.install_pkg_names(packages, reinstall)
def snapshot():
"""
Takes snapshot of the system packages. The snapshot is only a record of which packages are currently
installed. The record is kept by pisi history mechanism as it works automatically on install, remove
and upgrade operations.
"""
installdb = pisi.db.installdb.InstallDB()
historydb = pisi.db.historydb.HistoryDB()
historydb.create_history("snapshot")
for name in installdb.list_installed():
package = installdb.get_package(name)
historydb.add_package(pkgBefore=package, operation="snapshot")
historydb.update_history()
# ****** Danger Zone Below! Tressspassers' eyes will explode! ********** # # ****** Danger Zone Below! Tressspassers' eyes will explode! ********** #
def package_graph(A, packagedb, ignore_installed = False): def package_graph(A, packagedb, ignore_installed = False):
@@ -576,11 +592,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") pisi.db.historydb.HistoryDB().create_history("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") pisi.db.historydb.HistoryDB().create_history("upgrade")
return pisi.operations.upgrade.upgrade(*args, **kw) return pisi.operations.upgrade.upgrade(*args, **kw)
def emerge(*args, **kw): def emerge(*args, **kw):
+2 -2
View File
@@ -427,7 +427,7 @@ class Install(AtomicOperation):
# installed packages # installed packages
self.installdb.add_package(self.pkginfo) self.installdb.add_package(self.pkginfo)
self.historydb.update(pkgBefore=self.old_pkginfo, pkgAfter=self.pkginfo, operation=opttostr[self.operation]) self.historydb.add_and_update(pkgBefore=self.old_pkginfo, pkgAfter=self.pkginfo, operation=opttostr[self.operation])
def install_single(pkg, upgrade = False): def install_single(pkg, upgrade = False):
"""install a single package from URI or ID""" """install a single package from URI or ID"""
@@ -546,7 +546,7 @@ class Remove(AtomicOperation):
def update_databases(self): def update_databases(self):
self.remove_db() self.remove_db()
self.historydb.update(pkgBefore=self.package, operation="remove") self.historydb.add_and_update(pkgBefore=self.package, operation="remove")
def remove_pisi_files(self): def remove_pisi_files(self):
util.clean_dir(self.package.pkg_dir()) util.clean_dir(self.package.pkg_dir())
+21 -5
View File
@@ -46,13 +46,29 @@ Lists previous operations."""
def add_options(self, group): def add_options(self, group):
group.add_option("-l", "--last", action="store", type="int", default=0, group.add_option("-l", "--last", action="store", type="int", default=0,
help=_("Output only the last n operations")) help=_("Output only the last n operations"))
group.add_option("-s", "--snapshot", action="store_true", default=False,
help=_("Take snapshot of the current system"))
def run(self): def take_snapshot(self):
self.init(database = False, write = False) pisi.api.snapshot()
for operation in self.historydb.latest_operations(ctx.get_option('last')):
print "Operation: %s" % operation.type def print_history(self):
print "Date: %s %s" % (operation.date, operation.time) for operation in self.historydb.get_last(ctx.get_option('last')):
print _("Operation: %s") % operation.type
print _("Date: %s %s") % (operation.date, operation.time)
print print
if operation.type == "snapshot":
print _(" * There are %d packages in this snapshot.") % len(operation.packages)
else:
for pkg in operation.packages: for pkg in operation.packages:
print " *", pkg print " *", pkg
print print
def run(self):
self.init(database = False, write = False)
if ctx.get_option('snapshot'):
self.take_snapshot()
else:
self.print_history()
+9 -3
View File
@@ -31,15 +31,21 @@ class HistoryDB(lazydb.LazyDB):
logs.sort() logs.sort()
return logs return logs
def create(self, operation): def create_history(self, operation):
self.history = pisi.history.History() self.history = pisi.history.History()
self.history.create(operation) self.history.create(operation)
def update(self, pkgBefore=None, pkgAfter=None, operation=None): def add_and_update(self, pkgBefore=None, pkgAfter=None, operation=None):
self.add_package(pkgBefore, pkgAfter, operation)
self.update_history()
def add_package(self, pkgBefore=None, pkgAfter=None, operation=None):
self.history.add(pkgBefore, pkgAfter, operation) self.history.add(pkgBefore, pkgAfter, operation)
def update_history(self):
self.history.update() self.history.update()
def latest_operations(self, count=0): def get_last(self, count=0):
if not count or count > len(self.__logs): if not count or count > len(self.__logs):
count = len(self.__logs) count = len(self.__logs)
+2 -2
View File
@@ -76,7 +76,7 @@ class History(xmlfile.XmlFile):
def create(self, operation): def create(self, operation):
if operation not in ["upgrade", "remove", "install"]: if operation not in ["upgrade", "remove", "install", "snapshot"]:
raise Exception("Unknown package operation") raise Exception("Unknown package operation")
self.histfile = "%s_%s.xml" % (self._get_latest(), operation) self.histfile = "%s_%s.xml" % (self._get_latest(), operation)
@@ -88,7 +88,7 @@ class History(xmlfile.XmlFile):
def add(self, pkgBefore=None, pkgAfter=None, operation=None): def add(self, pkgBefore=None, pkgAfter=None, operation=None):
if operation not in ["upgrade", "remove", "install", "reinstall", "downgrade"]: if operation not in ["upgrade", "remove", "install", "reinstall", "downgrade", "snapshot"]:
raise Exception("Unknown package operation") raise Exception("Unknown package operation")
package = Package() package = Package()