summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-01-26 09:20:13 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2009-01-26 09:20:13 +0100
commitb8b968e115a377bdda2a0e4e74bb4cd9aa126e03 (patch)
tree9d7b78b95f913a2390da0480f5b9dfec076176e9
parent328db7f7d2c8779f2851479df1c28386701000bd (diff)
parent52546cc5e1a3980301286b8c2c14354d0b3b6dc5 (diff)
downloadpython-apt-b8b968e115a377bdda2a0e4e74bb4cd9aa126e03.tar.gz
merged from the mvo branch
-rw-r--r--apt/package.py109
1 files changed, 57 insertions, 52 deletions
diff --git a/apt/package.py b/apt/package.py
index 5a7da1f3..3d7846e4 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -593,63 +593,66 @@ class Package(object):
"src_pkg": src_pkg,
"src_ver": src_ver}
- timeout = socket.getdefaultimeout()
+ timeout = socket.getdefaulttimeout()
+
+ # FIXME: when python2.4 vanishes from the archive,
+ # merge this into a single try..finally block (pep 341)
try:
- # Set a timeout for the changelog download
- socket.setdefaulttimeout(2)
-
- # Check if the download was canceled
- if cancel_lock and cancel_lock.isSet():
- return ""
- changelog_file = urllib2.urlopen(uri)
- # do only get the lines that are new
- changelog = ""
- regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg))
-
- while True:
+ try:
+ # Set a timeout for the changelog download
+ socket.setdefaulttimeout(2)
+
# Check if the download was canceled
if cancel_lock and cancel_lock.isSet():
return ""
- # Read changelog line by line
- line_raw = changelog_file.readline()
- if line_raw == "":
- break
- # The changelog is encoded in utf-8, but since there isn't any
- # http header, urllib2 seems to treat it as ascii
- line = line_raw.decode("utf-8")
-
- #print line.encode('utf-8')
- match = re.match(regexp, line)
- if match:
- # strip epoch from installed version
- # and from changelog too
- installed = self.installedVersion
- if installed and ":" in installed:
- installed = installed.split(":", 1)[1]
- changelog_ver = match.group(1)
- if changelog_ver and ":" in changelog_ver:
- changelog_ver = changelog_ver.split(":", 1)[1]
- if installed and \
- apt_pkg.VersionCompare(changelog_ver, installed) <= 0:
+ changelog_file = urllib2.urlopen(uri)
+ # do only get the lines that are new
+ changelog = ""
+ regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg))
+
+ while True:
+ # Check if the download was canceled
+ if cancel_lock and cancel_lock.isSet():
+ return ""
+ # Read changelog line by line
+ line_raw = changelog_file.readline()
+ if line_raw == "":
break
- # EOF (shouldn't really happen)
- changelog += line
-
- # Print an error if we failed to extract a changelog
- if len(changelog) == 0:
- changelog = _("The list of changes is not available")
- self._changelog = changelog
-
- # FIXME: Ubuntu-specific part.
- except urllib2.HTTPError:
- return _("The list of changes is not available yet.\n\n"
- "Please use http://launchpad.net/ubuntu/+source/%s/%s/"
- "+changelog\n"
- "until the changes become available or try again "
- "later.") % (src_pkg, src_ver)
- except (IOError, httplib.BadStatusLine):
- return _("Failed to download the list of changes. \nPlease "
- "check your Internet connection.")
+ # The changelog is encoded in utf-8, but since there isn't any
+ # http header, urllib2 seems to treat it as ascii
+ line = line_raw.decode("utf-8")
+
+ #print line.encode('utf-8')
+ match = re.match(regexp, line)
+ if match:
+ # strip epoch from installed version
+ # and from changelog too
+ installed = self.installedVersion
+ if installed and ":" in installed:
+ installed = installed.split(":", 1)[1]
+ changelog_ver = match.group(1)
+ if changelog_ver and ":" in changelog_ver:
+ changelog_ver = changelog_ver.split(":", 1)[1]
+ if (installed and
+ apt_pkg.VersionCompare(changelog_ver, installed) <= 0):
+ break
+ # EOF (shouldn't really happen)
+ changelog += line
+
+ # Print an error if we failed to extract a changelog
+ if len(changelog) == 0:
+ changelog = _("The list of changes is not available")
+ self._changelog = changelog
+
+ except urllib2.HTTPError:
+ return _("The list of changes is not available yet.\n\n"
+ "Please use http://launchpad.net/ubuntu/+source/%s/%s/"
+ "+changelog\n"
+ "until the changes become available or try again "
+ "later.") % (src_pkg, src_ver)
+ except (IOError, httplib.BadStatusLine):
+ return _("Failed to download the list of changes. \nPlease "
+ "check your Internet connection.")
finally:
socket.setdefaulttimeout(timeout)
return self._changelog
@@ -775,9 +778,11 @@ def _test():
print "homepage: %s" % pkg.homepage
print "rec: ", pkg.candidateRecord
+
# now test install/remove
progress = apt.progress.OpTextProgress()
cache = apt.Cache(progress)
+ print cache["2vcard"].getChangelog()
for i in True, False:
print "Running install on random upgradable pkgs with AutoFix: %s " % i
for pkg in cache: