pisi hs --takeback <operation no>
Takes back the system to the state after the given operation finished. Taking back to a snapshot and taking real action (installing and removing packages) is not done yet. But we are there already. :)
This commit is contained in:
+12
@@ -39,6 +39,7 @@ import pisi.operations.delta
|
||||
import pisi.operations.remove
|
||||
import pisi.operations.upgrade
|
||||
import pisi.operations.install
|
||||
import pisi.operations.history
|
||||
import pisi.operations.helper
|
||||
import pisi.operations.emerge
|
||||
import pisi.operations.build
|
||||
@@ -282,6 +283,17 @@ def install(packages, reinstall=False, ignore_file_conflicts=False):
|
||||
else:
|
||||
return pisi.operations.install.install_pkg_names(packages, reinstall)
|
||||
|
||||
def takeback(operation):
|
||||
"""
|
||||
Takes the system back to the state after the given operation no from the pisi history.
|
||||
@param operation: operation number -> integer
|
||||
"""
|
||||
|
||||
historydb = pisi.db.historydb.HistoryDB()
|
||||
historydb.create_history("takeback")
|
||||
|
||||
pisi.operations.history.takeback(operation)
|
||||
|
||||
def snapshot():
|
||||
"""
|
||||
Takes snapshot of the system packages. The snapshot is only a record of which packages are currently
|
||||
|
||||
+8
-1
@@ -48,10 +48,15 @@ Lists previous 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"))
|
||||
group.add_option("-t", "--takeback", action="store", type="int", default=1,
|
||||
help=_("Takeback to the state after the given operation finished"))
|
||||
|
||||
def take_snapshot(self):
|
||||
pisi.api.snapshot()
|
||||
|
||||
def takeback(self, operation):
|
||||
pisi.api.takeback(operation)
|
||||
|
||||
def print_history(self):
|
||||
for operation in self.historydb.get_last(ctx.get_option('last')):
|
||||
print _("Operation #%d: %s") % (operation.no, operation.type)
|
||||
@@ -62,7 +67,7 @@ Lists previous operations."""
|
||||
print _(" * There are %d packages in this snapshot.") % len(operation.packages)
|
||||
else:
|
||||
for pkg in operation.packages:
|
||||
print " *", pkg
|
||||
print " *", pkg
|
||||
print
|
||||
|
||||
def run(self):
|
||||
@@ -70,5 +75,7 @@ Lists previous operations."""
|
||||
|
||||
if ctx.get_option('snapshot'):
|
||||
self.take_snapshot()
|
||||
elif ctx.get_option('takeback'):
|
||||
self.takeback(ctx.get_option('takeback'))
|
||||
else:
|
||||
self.print_history()
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ class History(xmlfile.XmlFile):
|
||||
|
||||
def create(self, operation):
|
||||
|
||||
if operation not in ["upgrade", "remove", "emerge", "install", "snapshot"]:
|
||||
if operation not in ["upgrade", "remove", "emerge", "install", "snapshot", "takeback"]:
|
||||
raise Exception("Unknown package operation")
|
||||
|
||||
self.histfile = "%s_%s.xml" % (self._get_latest(), operation)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2008, TUBITAK/UEKAE
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation; either version 2 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Please read the COPYING file.
|
||||
|
||||
import gettext
|
||||
__trans = gettext.translation("pisi", fallback=True)
|
||||
_ = __trans.ugettext
|
||||
|
||||
import pisi.context as ctx
|
||||
import pisi.util
|
||||
import pisi.db
|
||||
|
||||
def __listactions(actions):
|
||||
beinstalled = []
|
||||
beremoved = []
|
||||
|
||||
for pkg in actions:
|
||||
action, version = actions[pkg]
|
||||
if action == "install":
|
||||
beinstalled.append("%s-%s" % (pkg, version))
|
||||
else:
|
||||
beremoved.append("%s" % pkg)
|
||||
|
||||
return beinstalled, beremoved
|
||||
|
||||
def takeback(operation):
|
||||
|
||||
historydb = pisi.db.historydb.HistoryDB()
|
||||
actions = {}
|
||||
|
||||
for operation in historydb.get_till_operation(operation):
|
||||
if operation == "snapshot":
|
||||
pass
|
||||
|
||||
for pkg in operation.packages:
|
||||
if pkg.operation in ["upgrade", "downgrade", "remove"]:
|
||||
actions[pkg.name] = ("install", pkg.before)
|
||||
if pkg.operation == "install":
|
||||
actions[pkg.name] = ("remove", None)
|
||||
|
||||
beinstalled, beremoved = __listactions(actions)
|
||||
|
||||
if beinstalled:
|
||||
ctx.ui.info(_("Following packages will be installed:\n") + pisi.util.strlist(beinstalled))
|
||||
|
||||
if beremoved:
|
||||
ctx.ui.info(_("Following packages will be removed:\n") + pisi.util.strlist(beremoved))
|
||||
|
||||
if (beremoved or beinstalled) and not ctx.ui.confirm(_('Do you want to continue?')):
|
||||
return
|
||||
Reference in New Issue
Block a user