Merge lp:~aptdaemon-developers/aptdaemon/cached-changelogs into lp:aptdaemon

Proposed by Sebastian Heinlein
Status: Merged
Merged at revision: 730
Proposed branch: lp:~aptdaemon-developers/aptdaemon/cached-changelogs
Merge into: lp:aptdaemon
Diff against target: 65 lines (+41/-7)
1 file modified
aptdaemon/pkcompat.py (+41/-7)
To merge this branch: bzr merge lp:~aptdaemon-developers/aptdaemon/cached-changelogs
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+83377@code.launchpad.net

Description of the change

The changelogs are cached in "Dir::Cache::Changelog" which defaults to /var/cache/apt/Changelog

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

That looks great.

What I also don't get is where the changelogs are cached in the first place, but maybe that is already part of the code?

This code :
if pkg.name.startswith("linux-image-") or \
 pkg.name in ["libc6", "dbus"]:
        restart == RESTART_SYSTEM

could probably use the nwe (and yet unused) XB-Restart-Required bit in the packages file.

review: Approve
Revision history for this message
Sebastian Heinlein (glatzor) wrote :

The changelog gets written after being downloaded - line 57 ff

Revision history for this message
Sebastian Heinlein (glatzor) wrote :

The XB-Restart-Required bit is Ubuntu only?

Revision history for this message
Michael Vogt (mvo) wrote :

Its currently ubuntu only not not really used, but I think its really useful, so we could suggest it to debian as well.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'aptdaemon/pkcompat.py'
2--- aptdaemon/pkcompat.py 2011-11-25 00:23:33 +0000
3+++ aptdaemon/pkcompat.py 2011-11-25 09:18:23 +0000
4@@ -18,6 +18,8 @@
5 __author__ = "Sebastian Heinlein <devel@glatzor.de>"
6
7 import datetime
8+import glob
9+import gzip
10 import locale
11 import logging
12 import os
13@@ -2196,13 +2198,45 @@
14 # a reboot on Ubuntu but not on Debian
15 if pkg.name.startswith("linux-image-") or \
16 pkg.name in ["libc6", "dbus"]:
17- restart == RESTART_SYSTEM
18- changelog_raw = pkg.getChangelog()
19- # The internal download error string of python-apt ist not
20- # provided as unicode object
21- if not isinstance(changelog_raw, unicode):
22- changelog_raw = changelog_raw.decode(DEFAULT_ENCODING)
23- # Convert the changelog to markdown syntax
24+ restart == pk_enums.RESTART_SYSTEM
25+ changelog_dir = apt_pkg.config.find_dir("Dir::Cache::Changelog")
26+ if changelog_dir == "/":
27+ changelog_dir = os.path.join(apt_pkg.config.find_dir("Dir::"
28+ "Cache"),
29+ "Changelog")
30+ filename = os.path.join(changelog_dir,
31+ "%s_%s.gz" % (pkg.name,
32+ pkg.candidate.version))
33+ changelog_raw = ""
34+ if os.path.exists(filename):
35+ pklog.debug("Reading changelog from cache")
36+ changelog_file = gzip.open(filename, "rb")
37+ try:
38+ changelog_raw = changelog_file.read().decode("UTF-8")
39+ except:
40+ pass
41+ finally:
42+ changelog_file.close()
43+ if not changelog_raw:
44+ pklog.debug("Downloading changelog")
45+ changelog_raw = pkg.get_changelog()
46+ # The internal download error string of python-apt ist not
47+ # provided as unicode object
48+ if not isinstance(changelog_raw, unicode):
49+ changelog_raw = changelog_raw.decode("UTF-8")
50+ # Cache the fetched changelog
51+ if not os.path.exists(changelog_dir):
52+ os.makedirs(changelog_dir)
53+ # Remove old cached changelogs
54+ pattern = os.path.join(changelog_dir, "%s_*" % pkg.name)
55+ for old_changelog in glob.glob(pattern):
56+ os.rm(os.path.join(changelog_dir, old_changelog))
57+ changelog_file = gzip.open(filename, mode="wb")
58+ try:
59+ changelog_file.write(changelog_raw.encode("UTF-8"))
60+ finally:
61+ changelog_file.close()
62+ # Convert the changelog to markdown syntax
63 changelog = u""
64 for line in changelog_raw.split("\n"):
65 if line == "":

Subscribers

People subscribed via source and target branches

to status/vote changes: