Add pisi history command
This commit is contained in:
+27
-1
@@ -10,8 +10,16 @@
|
|||||||
# Please read the COPYING file.
|
# Please read the COPYING file.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import optparse
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
import pisi.api
|
import pisi.api
|
||||||
|
import pisi.db
|
||||||
|
import pisi.context as ctx
|
||||||
import pisi.cli.command as command
|
import pisi.cli.command as command
|
||||||
|
|
||||||
class History(command.Command):
|
class History(command.Command):
|
||||||
@@ -25,8 +33,26 @@ Lists previous operations."""
|
|||||||
|
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
super(History, self).__init__(args)
|
super(History, self).__init__(args)
|
||||||
|
self.historydb = pisi.db.historydb.HistoryDB()
|
||||||
|
|
||||||
name = ("history", "hs")
|
name = ("history", "hs")
|
||||||
|
|
||||||
|
def options(self):
|
||||||
|
|
||||||
|
group = optparse.OptionGroup(self.parser, _("history options"))
|
||||||
|
self.add_options(group)
|
||||||
|
self.parser.add_option_group(group)
|
||||||
|
|
||||||
|
def add_options(self, group):
|
||||||
|
group.add_option("-l", "--last", action="store", type="int", default=0,
|
||||||
|
help=_("Output only the last n operations"))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
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
|
||||||
|
|||||||
+16
-4
@@ -10,22 +10,26 @@
|
|||||||
# Please read the COPYING file.
|
# Please read the COPYING file.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
import piksemel
|
import piksemel
|
||||||
|
|
||||||
|
import pisi.context as ctx
|
||||||
import pisi.db.lazydb as lazydb
|
import pisi.db.lazydb as lazydb
|
||||||
import pisi.history
|
import pisi.history
|
||||||
|
|
||||||
class HistoryDB(lazydb.LazyDB):
|
class HistoryDB(lazydb.LazyDB):
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
pass
|
self.__logs = self.__generate_history()
|
||||||
|
|
||||||
def __generate_history(self, doc):
|
def __generate_history(self):
|
||||||
pass
|
logs = os.listdir(ctx.config.history_dir())
|
||||||
|
logs.sort()
|
||||||
|
return logs
|
||||||
|
|
||||||
def create(self, operation):
|
def create(self, operation):
|
||||||
self.history = pisi.history.History()
|
self.history = pisi.history.History()
|
||||||
@@ -34,3 +38,11 @@ class HistoryDB(lazydb.LazyDB):
|
|||||||
def update(self, pkgBefore=None, pkgAfter=None, operation=None):
|
def update(self, pkgBefore=None, pkgAfter=None, operation=None):
|
||||||
self.history.add(pkgBefore, pkgAfter, operation)
|
self.history.add(pkgBefore, pkgAfter, operation)
|
||||||
self.history.update()
|
self.history.update()
|
||||||
|
|
||||||
|
def latest_operations(self, count=0):
|
||||||
|
if not count or count > len(self.__logs):
|
||||||
|
count = len(self.__logs)
|
||||||
|
|
||||||
|
for log in self.__logs[-count:]:
|
||||||
|
hist = pisi.history.History(os.path.join(ctx.config.history_dir(), log))
|
||||||
|
yield hist.operation
|
||||||
|
|||||||
+20
-1
@@ -29,7 +29,10 @@ class PackageInfo:
|
|||||||
a_build = [autoxml.String, autoxml.optional]
|
a_build = [autoxml.String, autoxml.optional]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.version + "-" + self.release + "-" + self.build
|
vrb = self.version + "-" + self.release
|
||||||
|
if self.build:
|
||||||
|
vrb += "-" + self.build
|
||||||
|
return vrb
|
||||||
|
|
||||||
class Package:
|
class Package:
|
||||||
|
|
||||||
@@ -39,6 +42,22 @@ class Package:
|
|||||||
t_Before = [PackageInfo, autoxml.optional]
|
t_Before = [PackageInfo, autoxml.optional]
|
||||||
t_After = [PackageInfo, autoxml.optional]
|
t_After = [PackageInfo, autoxml.optional]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
# "upgrade", "remove", "install", "reinstall", "downgrade"
|
||||||
|
operation = ""
|
||||||
|
if self.operation == "upgrade":
|
||||||
|
return "%s is upgraded from %s to %s." % (self.name, self.before, self.after)
|
||||||
|
elif self.operation == "remove":
|
||||||
|
return "%s %s is removed." % (self.name, self.before)
|
||||||
|
elif self.operation == "install":
|
||||||
|
return "%s %s is installed." % (self.name, self.after)
|
||||||
|
elif self.operation == "reinstall":
|
||||||
|
return "%s %s is reinstalled." % (self.name, self.after)
|
||||||
|
elif self.operation == "downgrade":
|
||||||
|
return "%s is downgraded from %s to %s." % (self.name, self.before, self.after)
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
class Operation:
|
class Operation:
|
||||||
|
|
||||||
a_type = [autoxml.String, autoxml.mandatory]
|
a_type = [autoxml.String, autoxml.mandatory]
|
||||||
|
|||||||
Reference in New Issue
Block a user