summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-12-18 16:46:37 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2009-12-18 16:46:37 +0100
commit2cc697efb0bad365973c9dbfbd88fc7bb90b7a8f (patch)
treed176a7e8208956e3559423f3b41fbe2d674a71a7
parent51054e7baa348d2037d07102cc2f43392d528ada (diff)
downloadpython-apt-2cc697efb0bad365973c9dbfbd88fc7bb90b7a8f.tar.gz
* apt/history.py:
- simple abstraction for the apt history file
-rw-r--r--apt/history.py55
-rw-r--r--debian/changelog4
2 files changed, 59 insertions, 0 deletions
diff --git a/apt/history.py b/apt/history.py
new file mode 100644
index 00000000..f056e67e
--- /dev/null
+++ b/apt/history.py
@@ -0,0 +1,55 @@
+# histoy.py - apt package abstraction
+#
+# Copyright (c) 2005-2009 Canonical
+#
+# Author: Michael Vogt <michael.vogt@ubuntu.com>
+#
+# 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.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+"""Functionality related to the apt history file."""
+
+import apt_pkg
+apt_pkg.InitConfig()
+
+import gzip
+import string
+
+class Transaction(object):
+ def __init__(self, sec):
+ self.start_date = sec.has_key("Start-Date")
+ for k in ["Install", "Upgrade", "Downgrade" "Remove", "Purge","Error"]:
+ if sec.has_key(k):
+ setattr(self, k.lower(), map(string.strip, sec[k].split(",")))
+ else:
+ setattr(self, k.lower(), None)
+
+
+class AptHistory(dict):
+ def __init__(self, history_file=None):
+ if not history_file:
+ history_file = apt_pkg.Config.FindFile("Dir::Log::History")
+ # FIXME: test for .gz ending
+ f = open(history_file)
+ self._tagfile = apt_pkg.ParseTagFile(f)
+ while self._tagfile.Step():
+ sec = self._tagfile.Section
+ start_date = sec['Start-Date']
+ self[start_date] = Transaction(sec)
+
+if __name__ == "__main__":
+ #h = AptHistory("/var/log/apt/history.log.1.gz")
+ history = AptHistory()
+ for date in history:
+ print "'%s' - '%s'" % (date, history[date].install)
diff --git a/debian/changelog b/debian/changelog
index 60e1f265..945cfe3e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,10 @@ python-apt (0.7.13.5) UNRELEASED; urgency=low
* apt/progress/__init__.py:
- Fix InstallProgress.updateInterface() to cope with read() returning 0
on non-blocking file descriptors (LP: #491027).
+
+ [ Michael Vogt ]
+ * apt/history.py:
+ - simple abstraction for the apt history file
[ Michael Vogt ]
* data/templates/Ubuntu.info.in: