Add pisi history --snapshot cmd
This commit is contained in:
+20
-4
@@ -262,7 +262,6 @@ def search_file(term):
|
||||
term = term[1:]
|
||||
return filesdb.search_file(term)
|
||||
|
||||
|
||||
def install(packages, reinstall=False, ignore_file_conflicts=False):
|
||||
"""
|
||||
Returns True if no errors occured during the operation
|
||||
@@ -272,7 +271,7 @@ def install(packages, reinstall=False, ignore_file_conflicts=False):
|
||||
packages.
|
||||
"""
|
||||
|
||||
historydb = pisi.db.historydb.HistoryDB().create("install")
|
||||
pisi.db.historydb.HistoryDB().create_history("install")
|
||||
|
||||
if not ctx.get_option('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:
|
||||
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! ********** #
|
||||
|
||||
def package_graph(A, packagedb, ignore_installed = False):
|
||||
@@ -576,11 +592,11 @@ def rebuild_db(files=False):
|
||||
# from pisi.atomicoperations import resurrect_package, build
|
||||
|
||||
def remove(*args, **kw):
|
||||
pisi.db.historydb.HistoryDB().create("remove")
|
||||
pisi.db.historydb.HistoryDB().create_history("remove")
|
||||
return pisi.operations.remove.remove(*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)
|
||||
|
||||
def emerge(*args, **kw):
|
||||
|
||||
@@ -427,7 +427,7 @@ class Install(AtomicOperation):
|
||||
# installed packages
|
||||
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):
|
||||
"""install a single package from URI or ID"""
|
||||
@@ -546,7 +546,7 @@ class Remove(AtomicOperation):
|
||||
|
||||
def update_databases(self):
|
||||
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):
|
||||
util.clean_dir(self.package.pkg_dir())
|
||||
|
||||
+23
-7
@@ -46,13 +46,29 @@ Lists previous operations."""
|
||||
def add_options(self, group):
|
||||
group.add_option("-l", "--last", action="store", type="int", default=0,
|
||||
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 take_snapshot(self):
|
||||
pisi.api.snapshot()
|
||||
|
||||
def print_history(self):
|
||||
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
|
||||
|
||||
if operation.type == "snapshot":
|
||||
print _(" * There are %d packages in this snapshot.") % len(operation.packages)
|
||||
else:
|
||||
for pkg in operation.packages:
|
||||
print " *", pkg
|
||||
print
|
||||
|
||||
def run(self):
|
||||
self.init(database = False, write = False)
|
||||
for operation in self.historydb.latest_operations(ctx.get_option('last')):
|
||||
print "Operation: %s" % operation.type
|
||||
print "Date: %s %s" % (operation.date, operation.time)
|
||||
print
|
||||
for pkg in operation.packages:
|
||||
print " *", pkg
|
||||
print
|
||||
|
||||
if ctx.get_option('snapshot'):
|
||||
self.take_snapshot()
|
||||
else:
|
||||
self.print_history()
|
||||
|
||||
@@ -31,15 +31,21 @@ class HistoryDB(lazydb.LazyDB):
|
||||
logs.sort()
|
||||
return logs
|
||||
|
||||
def create(self, operation):
|
||||
def create_history(self, operation):
|
||||
self.history = pisi.history.History()
|
||||
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)
|
||||
|
||||
def update_history(self):
|
||||
self.history.update()
|
||||
|
||||
def latest_operations(self, count=0):
|
||||
def get_last(self, count=0):
|
||||
if not count or count > len(self.__logs):
|
||||
count = len(self.__logs)
|
||||
|
||||
|
||||
+2
-2
@@ -76,7 +76,7 @@ class History(xmlfile.XmlFile):
|
||||
|
||||
def create(self, operation):
|
||||
|
||||
if operation not in ["upgrade", "remove", "install"]:
|
||||
if operation not in ["upgrade", "remove", "install", "snapshot"]:
|
||||
raise Exception("Unknown package 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):
|
||||
|
||||
if operation not in ["upgrade", "remove", "install", "reinstall", "downgrade"]:
|
||||
if operation not in ["upgrade", "remove", "install", "reinstall", "downgrade", "snapshot"]:
|
||||
raise Exception("Unknown package operation")
|
||||
|
||||
package = Package()
|
||||
|
||||
Reference in New Issue
Block a user