summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-03-08 18:58:17 +0100
committerJulian Andres Klode <jak@debian.org>2009-03-08 18:58:17 +0100
commit162844cc03d669fd1aaf4a6cf9424597bb299264 (patch)
treea0887d64151344f48e221d6d41ed922abbc0bc36
parent645c80f504f98332fb8eceb955c13a54e38e5956 (diff)
parent2342bc7c05da5589f166496fe1112b249598648f (diff)
downloadpython-apt-162844cc03d669fd1aaf4a6cf9424597bb299264.tar.gz
* Merge with mvo
-rw-r--r--apt/cache.py8
-rw-r--r--apt/package.py182
-rw-r--r--aptsources/sourceslist.py19
-rw-r--r--debian/changelog14
-rw-r--r--doc/examples/acquire.py1
-rw-r--r--doc/examples/desc.py1
-rw-r--r--doc/examples/indexfile.py1
-rw-r--r--doc/examples/metaindex.py1
-rw-r--r--doc/examples/progress.py2
-rwxr-xr-xdoc/examples/update.py1
-rw-r--r--po/python-apt.pot19
-rw-r--r--python/apt_pkgmodule.cc1
-rw-r--r--python/apt_pkgmodule.h2
-rw-r--r--python/cache.cc18
-rw-r--r--python/configuration.cc18
-rw-r--r--tests/getcache_mem_corruption.py24
16 files changed, 191 insertions, 121 deletions
diff --git a/apt/cache.py b/apt/cache.py
index 1b5531ac..9f00b8a5 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -51,6 +51,10 @@ class Cache(object):
# force apt to build its caches in memory
apt_pkg.Config.Set("Dir::Cache::pkgcache", "")
if rootdir:
+ if os.path.exists(rootdir+"/etc/apt/apt.conf"):
+ apt_pkg.ReadConfigFile(apt_pkg.Config, rootdir+"/etc/apt/apt.conf")
+ if os.path.isdir(rootdir+"/etc/apt/apt.conf.d"):
+ apt_pkg.ReadConfigDir(apt_pkg.Config, rootdir+"/etc/apt/apt.conf.d")
apt_pkg.Config.Set("Dir", rootdir)
apt_pkg.Config.Set("Dir::State::status",
rootdir + "/var/lib/dpkg/status")
@@ -85,9 +89,7 @@ class Cache(object):
last=i
# drop stuff with no versions (cruft)
if len(pkg.VersionList) > 0:
- self._dict[pkg.Name] = Package(self._cache, self._depcache,
- self._records, self._list,
- self, pkg)
+ self._dict[pkg.Name] = Package(self, pkg)
i += 1
if progress is not None:
diff --git a/apt/package.py b/apt/package.py
index 03b1e90c..37cd33fb 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -36,10 +36,6 @@ __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record',
'Version')
-# Set a timeout for the changelog download
-socket.setdefaulttimeout(2)
-
-
def _(string):
"""Return the translation of the string."""
return gettext.dgettext("python-apt", string)
@@ -117,8 +113,9 @@ class Origin(object):
self.label = VerFileIter.Label
self.origin = VerFileIter.Origin
self.site = VerFileIter.Site
+ self.not_automatic = VerFileIter.NotAutomatic
# check the trust
- indexfile = pkg._list.FindIndex(VerFileIter)
+ indexfile = pkg._pcache._list.FindIndex(VerFileIter)
if indexfile and indexfile.IsTrusted:
self.trusted = True
else:
@@ -202,8 +199,8 @@ class Version(object):
@property
def _records(self):
"""Internal helper that moves the Records to the right position."""
- if self.package._records.Lookup(self._cand.FileList[0]):
- return self.package._records
+ if self.package._pcache._records.Lookup(self._cand.FileList[0]):
+ return self.package._pcache._records
@property
def installed_size(self):
@@ -239,8 +236,8 @@ class Version(object):
def summary(self):
"""Return the short description (one line summary)."""
desc_iter = self._cand.TranslatedDescription
- self.package._records.Lookup(desc_iter.FileList.pop(0))
- return self.package._records.ShortDesc
+ self.package._pcache._records.Lookup(desc_iter.FileList.pop(0))
+ return self.package._pcache._records.ShortDesc
@property
def raw_description(self):
@@ -264,7 +261,7 @@ class Version(object):
self.summary # This does the lookup for us.
desc = ''
try:
- dsc = unicode(self.package._records.LongDesc, "utf-8")
+ dsc = unicode(self.package._pcache._records.LongDesc, "utf-8")
except UnicodeDecodeError, err:
return _("Invalid unicode in description for '%s' (%s). "
"Please report.") % (self.package.name, err)
@@ -381,13 +378,9 @@ class Package(object):
much more.
"""
- def __init__(self, cache, depcache, records, sourcelist, pcache, pkgiter):
+ def __init__(self, pcache, pkgiter):
""" Init the Package object """
- self._cache = cache # low level cache
- self._depcache = depcache
- self._records = records
self._pkg = pkgiter
- self._list = sourcelist # sourcelist
self._pcache = pcache # python cache in cache.py
self._changelog = "" # Cached changelog
@@ -399,7 +392,7 @@ class Package(object):
"""Return the candidate version of the package.
:since: 0.7.9"""
- return Version(self, self._depcache.GetCandidateVer(self._pkg))
+ return Version(self, self._pcache._depcache.GetCandidateVer(self._pkg))
@property
def installed(self):
@@ -519,7 +512,7 @@ class Package(object):
@DeprecatedProperty
def candidateRecord(self):
"""Return the Record of the candidate version of the package."""
- return self.candidate.record
+ return self.candidate.recor
@DeprecatedProperty
def installedRecord(self):
@@ -531,32 +524,32 @@ class Package(object):
@property
def markedInstall(self):
"""Return True if the package is marked for install."""
- return self._depcache.MarkedInstall(self._pkg)
+ return self._pcache._depcache.MarkedInstall(self._pkg)
@property
def markedUpgrade(self):
"""Return True if the package is marked for upgrade."""
- return self._depcache.MarkedUpgrade(self._pkg)
+ return self._pcache._depcache.MarkedUpgrade(self._pkg)
@property
def markedDelete(self):
"""Return True if the package is marked for delete."""
- return self._depcache.MarkedDelete(self._pkg)
+ return self._pcache._depcache.MarkedDelete(self._pkg)
@property
def markedKeep(self):
"""Return True if the package is marked for keep."""
- return self._depcache.MarkedKeep(self._pkg)
+ return self._pcache._depcache.MarkedKeep(self._pkg)
@property
def markedDowngrade(self):
""" Package is marked for downgrade """
- return self._depcache.MarkedDowngrade(self._pkg)
+ return self._pcache._depcache.MarkedDowngrade(self._pkg)
@property
def markedReinstall(self):
"""Return True if the package is marked for reinstall."""
- return self._depcache.MarkedReinstall(self._pkg)
+ return self._pcache._depcache.MarkedReinstall(self._pkg)
@property
def isInstalled(self):
@@ -566,7 +559,8 @@ class Package(object):
@property
def isUpgradable(self):
"""Return True if the package is upgradable."""
- return self.isInstalled and self._depcache.IsUpgradable(self._pkg)
+ return (self.isInstalled and
+ self._pcache._depcache.IsUpgradable(self._pkg))
@property
def isAutoRemovable(self):
@@ -576,7 +570,7 @@ class Package(object):
another package, and if no packages depend on it anymore, the package
is no longer required.
"""
- return self.isInstalled and self._depcache.IsGarbage(self._pkg)
+ return self.isInstalled and self._pcache._depcache.IsGarbage(self._pkg)
# sizes
@@ -655,7 +649,7 @@ class Package(object):
# assume "main" section
src_section = "main"
# use the section of the candidate as a starting point
- section = self._depcache.GetCandidateVer(self._pkg).Section
+ section = self.candidate.section
# get the source version, start with the binaries version
bin_ver = self.candidate.version
@@ -703,59 +697,68 @@ class Package(object):
"prefix": prefix,
"src_pkg": src_pkg,
"src_ver": src_ver}
+
+ timeout = socket.getdefaulttimeout()
+
+ # FIXME: when python2.4 vanishes from the archive,
+ # merge this into a single try..finally block (pep 341)
try:
- # 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 = getattr(self.installed, 'version', None)
- 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
@DeprecatedProperty
@@ -776,7 +779,7 @@ class Package(object):
def markKeep(self):
"""Mark a package for keep."""
self._pcache.cachePreChange()
- self._depcache.MarkKeep(self._pkg)
+ self._pcache._depcache.MarkKeep(self._pkg)
self._pcache.cachePostChange()
def markDelete(self, autoFix=True, purge=False):
@@ -789,10 +792,10 @@ class Package(object):
well. The default is to keep the configuration.
"""
self._pcache.cachePreChange()
- self._depcache.MarkDelete(self._pkg, purge)
+ self._pcache._depcache.MarkDelete(self._pkg, purge)
# try to fix broken stuffsta
- if autoFix and self._depcache.BrokenCount > 0:
- Fix = apt_pkg.GetPkgProblemResolver(self._depcache)
+ if autoFix and self._pcache._depcache.BrokenCount > 0:
+ Fix = apt_pkg.GetPkgProblemResolver(self._pcache._depcache)
Fix.Clear(self._pkg)
Fix.Protect(self._pkg)
Fix.Remove(self._pkg)
@@ -815,10 +818,10 @@ class Package(object):
it.
"""
self._pcache.cachePreChange()
- self._depcache.MarkInstall(self._pkg, autoInst, fromUser)
+ self._pcache._depcache.MarkInstall(self._pkg, autoInst, fromUser)
# try to fix broken stuff
- if autoFix and self._depcache.BrokenCount > 0:
- fixer = apt_pkg.GetPkgProblemResolver(self._depcache)
+ if autoFix and self._pcache._depcache.BrokenCount > 0:
+ fixer = apt_pkg.GetPkgProblemResolver(self._pcache._depcache)
fixer.Clear(self._pkg)
fixer.Protect(self._pkg)
fixer.Resolve(True)
@@ -842,7 +845,7 @@ class Package(object):
The parameter `iprogress` refers to an InstallProgress() object, as
found in apt.progress.
"""
- self._depcache.Commit(fprogress, iprogress)
+ self._pcache._depcache.Commit(fprogress, iprogress)
def _test():
@@ -851,13 +854,9 @@ def _test():
import random
import apt
apt_pkg.init()
- cache = apt_pkg.GetCache()
- depcache = apt_pkg.GetDepCache(cache)
- records = apt_pkg.GetPkgRecords(cache)
- sourcelist = apt_pkg.GetPkgSourceList()
-
- pkgiter = cache["apt-utils"]
- pkg = Package(cache, depcache, records, sourcelist, None, pkgiter)
+ progress = apt.progress.OpTextProgress()
+ cache = apt.Cache(progress)
+ pkg = cache["apt-utils"]
print "Name: %s " % pkg.name
print "ID: %s " % pkg.id
print "Priority (Candidate): %s " % pkg.candidate.priority
@@ -881,9 +880,8 @@ def _test():
print "homepage: %s" % pkg.candidate.homepage
print "rec: ", pkg.candidate.record
- # 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:
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py
index dc2a5d45..f4d88822 100644
--- a/aptsources/sourceslist.py
+++ b/aptsources/sourceslist.py
@@ -219,7 +219,7 @@ class NullMatcher(object):
return True
-class SourcesList:
+class SourcesList(object):
""" represents the full sources.list + sources.list.d file """
def __init__(self,
@@ -236,9 +236,8 @@ class SourcesList:
""" update the list of known entries """
self.list = []
# read sources.list
- dir = apt_pkg.Config.FindDir("Dir::Etc")
- file = apt_pkg.Config.Find("Dir::Etc::sourcelist")
- self.load(dir+file)
+ file = apt_pkg.Config.FindFile("Dir::Etc::sourcelist")
+ self.load(file)
# read sources.list.d
partsdir = apt_pkg.Config.FindDir("Dir::Etc::sourceparts")
for file in glob.glob("%s/*.list" % partsdir):
@@ -312,11 +311,10 @@ class SourcesList:
def restoreBackup(self, backup_ext):
" restore sources.list files based on the backup extension "
- dir = apt_pkg.Config.FindDir("Dir::Etc")
- file = apt_pkg.Config.Find("Dir::Etc::sourcelist")
- if os.path.exists(dir+file+backup_ext) and \
- os.path.exists(dir+file):
- shutil.copy(dir+file+backup_ext, dir+file)
+ file = apt_pkg.Config.FindFile("Dir::Etc::sourcelist")
+ if os.path.exists(file+backup_ext) and \
+ os.path.exists(file):
+ shutil.copy(file+backup_ext, file)
# now sources.list.d
partsdir = apt_pkg.Config.FindDir("Dir::Etc::sourceparts")
for file in glob.glob("%s/*.list" % partsdir):
@@ -353,8 +351,7 @@ class SourcesList:
files = {}
# write an empty default config file if there aren't any sources
if len(self.list) == 0:
- path = "%s%s" % (apt_pkg.Config.FindDir("Dir::Etc"),
- apt_pkg.Config.Find("Dir::Etc::sourcelist"))
+ path = apt_pkg.Config.FindFile("Dir::Etc::sourcelist"
header = (
"## See sources.list(5) for more information, especialy\n"
"# Remember that you can only use http, ftp or file URIs\n"
diff --git a/debian/changelog b/debian/changelog
index 45785487..a7241740 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -19,6 +19,20 @@ python-apt (0.7.9~exp3) experimental; urgency=low
- fix incorrect indent
* debian/control:
- add Recommends to iso-codes (for iso_3166.xml)
+ * apt/package.py:
+ - make sure to set the defaulttimeout back to the
+ original value (in getChangelog(), LP: #314212)
+ * apt/cache.py:
+ - when setting a alternative rootdir, read the
+ config from it as well
+ * python/configuration.cc, python/apt_pkgmodule.cc:
+ - add apt_pkg.ReadConfigDir()
+ * python/cache.cc, tests/getcache_mem_corruption.py:
+ - test if progress objects have the right methods
+ and raise error if not (thanks to Emanuele Rocca)
+ closes: #497049
+ * apt/package.py:
+ - avoid uneeded interal references in the Package objects
--
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
index 58372961..a23c41c6 100644
--- a/doc/examples/acquire.py
+++ b/doc/examples/acquire.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import apt
import apt_pkg
import os
diff --git a/doc/examples/desc.py b/doc/examples/desc.py
index f47517cf..2febf348 100644
--- a/doc/examples/desc.py
+++ b/doc/examples/desc.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import apt_pkg
diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py
index 22d0b635..2f1f27f8 100644
--- a/doc/examples/indexfile.py
+++ b/doc/examples/indexfile.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import apt_pkg
diff --git a/doc/examples/metaindex.py b/doc/examples/metaindex.py
index f00a7e01..816a3fd7 100644
--- a/doc/examples/metaindex.py
+++ b/doc/examples/metaindex.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import apt_pkg
diff --git a/doc/examples/progress.py b/doc/examples/progress.py
index 83847598..304bd117 100644
--- a/doc/examples/progress.py
+++ b/doc/examples/progress.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
import sys
import time
diff --git a/doc/examples/update.py b/doc/examples/update.py
index 364fa1c9..5929c9f8 100755
--- a/doc/examples/update.py
+++ b/doc/examples/update.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import apt
import apt_pkg
import os.path
diff --git a/po/python-apt.pot b/po/python-apt.pot
index 6af898db..217c772c 100644
--- a/po/python-apt.pot
+++ b/po/python-apt.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-01-09 18:08+0100\n"
+"POT-Creation-Date: 2009-03-03 21:17+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -82,11 +82,6 @@ msgstr ""
msgid "Community-maintained"
msgstr ""
-#. CompDescriptionLong
-#: ../data/templates/Ubuntu.info.in:305
-msgid "Proprietary drivers for devices"
-msgstr ""
-
#. CompDescription
#: ../data/templates/Ubuntu.info.in:307
msgid "Restricted software"
@@ -124,7 +119,7 @@ msgstr ""
#. CompDescriptionLong
#: ../data/templates/Ubuntu.info.in:357
-msgid "Proprietary drivers for devices "
+msgid "Proprietary drivers for devices"
msgstr ""
#. CompDescription
@@ -275,7 +270,7 @@ msgstr ""
#. Description
#: ../data/templates/Debian.info.in:33
-msgid "Debian 4.0 'Etch' "
+msgid "Debian 4.0 'Etch'"
msgstr ""
#. Description
@@ -319,7 +314,7 @@ msgid "Non-DFSG-compatible Software"
msgstr ""
#. TRANSLATORS: %s is a country
-#: ../aptsources/distro.py:194 ../aptsources/distro.py:401
+#: ../aptsources/distro.py:207 ../aptsources/distro.py:422
#, python-format
msgid "Server for %s"
msgstr ""
@@ -327,12 +322,12 @@ msgstr ""
#. More than one server is used. Since we don't handle this case
#. in the user interface we set "custom servers" to true and
#. append a list of all used servers
-#: ../aptsources/distro.py:213 ../aptsources/distro.py:218
-#: ../aptsources/distro.py:232
+#: ../aptsources/distro.py:225 ../aptsources/distro.py:231
+#: ../aptsources/distro.py:247
msgid "Main server"
msgstr ""
-#: ../aptsources/distro.py:235
+#: ../aptsources/distro.py:251
msgid "Custom servers"
msgstr ""
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index 2e488d58..86732781 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -402,6 +402,7 @@ static PyMethodDef methods[] =
// Command line
{"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig},
+ {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir},
{"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig},
{"ParseCommandLine",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine},
diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h
index 38486182..e047bcd8 100644
--- a/python/apt_pkgmodule.h
+++ b/python/apt_pkgmodule.h
@@ -23,9 +23,11 @@ extern PyTypeObject VersionType;
extern char *doc_LoadConfig;
extern char *doc_LoadConfigISC;
+extern char *doc_LoadConfigDir;
extern char *doc_ParseCommandLine;
PyObject *LoadConfig(PyObject *Self,PyObject *Args);
PyObject *LoadConfigISC(PyObject *Self,PyObject *Args);
+PyObject *LoadConfigDir(PyObject *Self,PyObject *Args);
PyObject *ParseCommandLine(PyObject *Self,PyObject *Args);
// Tag File Stuff
diff --git a/python/cache.cc b/python/cache.cc
index 1c59bece..0c59f561 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -936,14 +936,26 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args)
pkgCacheFile *Cache = new pkgCacheFile();
if(pyCallbackInst != 0) {
+ // sanity check for the progress object, see #497049
+ if (PyObject_HasAttrString(pyCallbackInst, "done") != true) {
+ PyErr_SetString(PyExc_ValueError,
+ "OpProgress object must implement done()");
+ return 0;
+ }
+ if (PyObject_HasAttrString(pyCallbackInst, "update") != true) {
+ PyErr_SetString(PyExc_ValueError,
+ "OpProgress object must implement update()");
+ return 0;
+ }
PyOpProgress progress;
progress.setCallbackInst(pyCallbackInst);
if (Cache->Open(progress,false) == false)
- return HandleErrors();
- } else {
+ return HandleErrors();
+ }
+ else {
OpTextProgress Prog;
if (Cache->Open(Prog,false) == false)
- return HandleErrors();
+ return HandleErrors();
}
CppOwnedPyObject<pkgCacheFile*> *CacheFileObj =
diff --git a/python/configuration.cc b/python/configuration.cc
index f52c3c97..21f70bc1 100644
--- a/python/configuration.cc
+++ b/python/configuration.cc
@@ -330,6 +330,24 @@ PyObject *LoadConfigISC(PyObject *Self,PyObject *Args)
Py_INCREF(Py_None);
return HandleErrors(Py_None);
}
+char *doc_LoadConfigDir = "LoadConfigDir(Configuration,DirName) -> None";
+PyObject *LoadConfigDir(PyObject *Self,PyObject *Args)
+{
+ char *Name = 0;
+ if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0)
+ return 0;
+ if (Configuration_Check(Self)== 0)
+ {
+ PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration.");
+ return 0;
+ }
+
+ if (ReadConfigDir(GetSelf(Self),Name,false) == false)
+ return HandleErrors();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
/*}}}*/
// ParseCommandLine - Wrapper for the command line interface /*{{{*/
diff --git a/tests/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py
new file mode 100644
index 00000000..42e9af00
--- /dev/null
+++ b/tests/getcache_mem_corruption.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+import apt
+import apt_pkg
+import re
+
+import unittest
+
+class TestGetCache(unittest.TestCase):
+
+ def setUp(self):
+ apt_pkg.InitConfig()
+ apt_pkg.InitSystem()
+
+ def testWrongInvocation(self):
+ # wrongly invoke GetCache() rather than GetDepCache()
+ apt_cache = apt_pkg.GetCache()
+ self.assertRaises(ValueError, apt_pkg.GetCache, apt_cache)
+
+ def testProperInvocation(self):
+ apt_cache = apt_pkg.GetCache(apt.progress.OpTextProgress())
+ apt_depcache = apt_pkg.GetDepCache(apt_cache)
+
+if __name__ == "__main__":
+ unittest.main()