Merge lp:~mvo/python-apt/mvo into lp:~mvo/python-apt/debian-sid-mirror

Proposed by Michael Vogt
Status: Needs review
Proposed branch: lp:~mvo/python-apt/mvo
Merge into: lp:~mvo/python-apt/debian-sid-mirror
Diff against target: 293 lines (+117/-9) (has conflicts)
10 files modified
apt/auth.py (+2/-1)
apt/cache.py (+23/-0)
debian/changelog (+16/-0)
debian/control (+1/-0)
debian/tests/control (+2/-0)
debian/tests/run-tests (+8/-0)
python/apt_pkgmodule.cc (+2/-2)
python/cache.cc (+8/-0)
python/generic.h (+4/-0)
tests/test_apt_cache.py (+51/-6)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~mvo/python-apt/mvo
Reviewer Review Type Date Requested Status
Michael Vogt Pending
Review via email: mp+119519@code.launchpad.net

Description of the change

This adds the "codename" to the PackageFile object.

To post a comment you must log in.
lp:~mvo/python-apt/mvo updated
612. By Michael Vogt

add dep8 style tests

613. By Michael Vogt

debian/tests/control: update depends line

614. By Michael Vogt

merge from the debian-sid branch

615. By Michael Vogt

update changelog

616. By Michael Vogt

merged lp:~jconti/python-apt/closeable-cache

617. By Michael Vogt

add changelog for lp:~jconti/python-apt/closeable-cache and add new test "test_cache_close_download_fails"

618. By Michael Vogt

close cache on (re)open

619. By Michael Vogt

apt/cache.py: add comment

620. By Michael Vogt

tests/test_apt_cache.py: delete test_cache_delete_leasks_fds() as its not reliable

621. By Michael Vogt

build fixes for python3.3

622. By Michael Vogt

fix documentation for version_compare(), thanks to
Ansgar Burchardt, closes: #680891

Unmerged revisions

622. By Michael Vogt

fix documentation for version_compare(), thanks to
Ansgar Burchardt, closes: #680891

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'apt/auth.py'
--- apt/auth.py 2012-10-10 14:05:28 +0000
+++ apt/auth.py 2013-03-09 19:55:24 +0000
@@ -78,7 +78,8 @@
78 stderr=subprocess.PIPE)78 stderr=subprocess.PIPE)
7979
80 content = kwargs.get("stdin", None)80 content = kwargs.get("stdin", None)
81 if isinstance(content, unicode):81 # py2 needs this encoded, py3.3 will crash if it is
82 if isinstance(content, unicode) and sys.version_info[:2] < (3, 3):
82 content = content.encode("utf-8")83 content = content.encode("utf-8")
8384
84 output, stderr = proc.communicate(content)85 output, stderr = proc.communicate(content)
8586
=== modified file 'apt/cache.py'
--- apt/cache.py 2012-04-17 19:17:10 +0000
+++ apt/cache.py 2013-03-09 19:55:24 +0000
@@ -42,6 +42,9 @@
42class LockFailedException(IOError):42class LockFailedException(IOError):
43 """Exception that is thrown when locking fails."""43 """Exception that is thrown when locking fails."""
4444
45class CacheClosedException(Exception):
46 """Exception that is thrown when the cache is used after close()."""
47
4548
46class Cache(object):49class Cache(object):
47 """Dictionary-like package cache.50 """Dictionary-like package cache.
@@ -139,6 +142,8 @@
139 """142 """
140 if progress is None:143 if progress is None:
141 progress = apt.progress.base.OpProgress()144 progress = apt.progress.base.OpProgress()
145 # close old cache on (re)open
146 self.close()
142 self.op_progress = progress147 self.op_progress = progress
143 self._run_callbacks("cache_pre_open")148 self._run_callbacks("cache_pre_open")
144149
@@ -172,6 +177,20 @@
172 progress.done()177 progress.done()
173 self._run_callbacks("cache_post_open")178 self._run_callbacks("cache_post_open")
174179
180 def close(self):
181 """ Close the package cache """
182 # explicitely free the FDs that _records has open
183 del self._records
184 self._records = None
185
186 def __enter__(self):
187 """ Enter the with statement """
188 return self
189
190 def __exit__(self, exc_type, exc_value, traceback):
191 """ Exit the with statement """
192 self.close()
193
175 def __getitem__(self, key):194 def __getitem__(self, key):
176 """ look like a dictionary (get key) """195 """ look like a dictionary (get key) """
177 try:196 try:
@@ -238,6 +257,8 @@
238 @property257 @property
239 def required_download(self):258 def required_download(self):
240 """Get the size of the packages that are required to download."""259 """Get the size of the packages that are required to download."""
260 if self._records is None:
261 raise CacheClosedException("Cache object used after close() called")
241 pm = apt_pkg.PackageManager(self._depcache)262 pm = apt_pkg.PackageManager(self._depcache)
242 fetcher = apt_pkg.Acquire()263 fetcher = apt_pkg.Acquire()
243 pm.get_archives(fetcher, self._list, self._records)264 pm.get_archives(fetcher, self._list, self._records)
@@ -288,6 +309,8 @@
288309
289 def _fetch_archives(self, fetcher, pm):310 def _fetch_archives(self, fetcher, pm):
290 """ fetch the needed archives """311 """ fetch the needed archives """
312 if self._records is None:
313 raise CacheClosedException("Cache object used after close() called")
291314
292 # get lock315 # get lock
293 lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"316 lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"
294317
=== modified file 'debian/changelog'
--- debian/changelog 2012-11-15 13:30:14 +0000
+++ debian/changelog 2013-03-09 19:55:24 +0000
@@ -1,13 +1,29 @@
1python-apt (0.8.8.1) unstable; urgency=low1python-apt (0.8.8.1) unstable; urgency=low
22
3 [ Michael Vogt ]
3 * python/tag.cc:4 * python/tag.cc:
4 - make TagSecString_FromStringAndSize, TagSecString_FromString5 - make TagSecString_FromStringAndSize, TagSecString_FromString
5 static, thanks to jcristau6 static, thanks to jcristau
7<<<<<<< TREE
6 * tests/test_lp659438.py:8 * tests/test_lp659438.py:
7 - fix missing architecture to make the tests pass again during9 - fix missing architecture to make the tests pass again during
8 build with the latest apt10 build with the latest apt
911
10 -- Michael Vogt <mvo@debian.org> Thu, 15 Nov 2012 09:55:24 +010012 -- Michael Vogt <mvo@debian.org> Thu, 15 Nov 2012 09:55:24 +0100
13=======
14 * python/cache.cc:
15 - add "Codename" to PackageFile object
16 * add dep8 style autopkgtest support
17 * build fixes for python3.3
18 * fix documentation for version_compare(), thanks to
19 Ansgar Burchardt, closes: #680891
20
21 [ Jason Conti ]
22 * lp:~jconti/python-apt/closeable-cache:
23 - add apt.Cache.close() method
24
25 -- Michael Vogt <mvo@debian.org> Mon, 15 Oct 2012 10:03:21 +0200
26>>>>>>> MERGE-SOURCE
1127
12python-apt (0.8.8) unstable; urgency=low28python-apt (0.8.8) unstable; urgency=low
1329
1430
=== modified file 'debian/control'
--- debian/control 2012-10-12 08:08:21 +0000
+++ debian/control 2013-03-09 19:55:24 +0000
@@ -21,6 +21,7 @@
21 python-unittest221 python-unittest2
22Vcs-Bzr: http://bzr.debian.org/apt/python-apt/debian-sid22Vcs-Bzr: http://bzr.debian.org/apt/python-apt/debian-sid
23Vcs-Browser: http://bzr.debian.org/loggerhead/apt/python-apt/debian-sid/changes23Vcs-Browser: http://bzr.debian.org/loggerhead/apt/python-apt/debian-sid/changes
24XS-Testsuite: autopkgtest
2425
25Package: python-apt26Package: python-apt
26Architecture: any27Architecture: any
2728
=== added directory 'debian/tests'
=== added file 'debian/tests/control'
--- debian/tests/control 1970-01-01 00:00:00 +0000
+++ debian/tests/control 2013-03-09 19:55:24 +0000
@@ -0,0 +1,2 @@
1Tests: run-tests
2Depends: @, apt-utils, python-debian, fakeroot, intltool
03
=== added file 'debian/tests/run-tests'
--- debian/tests/run-tests 1970-01-01 00:00:00 +0000
+++ debian/tests/run-tests 2013-03-09 19:55:24 +0000
@@ -0,0 +1,8 @@
1#!/bin/sh
2
3set -e
4
5# from debian/rules
6for python in $(utils/pyversions -r); do
7 $python tests/test_all.py -q
8done
09
=== modified file 'python/apt_pkgmodule.cc'
--- python/apt_pkgmodule.cc 2012-03-05 12:05:39 +0000
+++ python/apt_pkgmodule.cc 2013-03-09 19:55:24 +0000
@@ -68,8 +68,8 @@
68// These are kind of legacy..68// These are kind of legacy..
69static char *doc_VersionCompare =69static char *doc_VersionCompare =
70 "version_compare(a: str, b: str) -> int\n\n"70 "version_compare(a: str, b: str) -> int\n\n"
71 "Compare the given versions; return -1 if 'a' is smaller than 'b',\n"71 "Compare the given versions; return <0 if 'a' is smaller than 'b',\n"
72 "0 if they are equal, and 2 if 'a' is larger than 'b'.";72 "0 if they are equal, and >0 if 'a' is larger than 'b'.";
73static PyObject *VersionCompare(PyObject *Self,PyObject *Args)73static PyObject *VersionCompare(PyObject *Self,PyObject *Args)
74{74{
75 char *A;75 char *A;
7676
=== modified file 'python/cache.cc'
--- python/cache.cc 2012-10-01 08:10:49 +0000
+++ python/cache.cc 2013-03-09 19:55:24 +0000
@@ -1247,6 +1247,12 @@
1247 return Safe_FromString(File.Architecture());1247 return Safe_FromString(File.Architecture());
1248}1248}
12491249
1250static PyObject *PackageFile_GetCodename(PyObject *Self,void*)
1251{
1252 pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);
1253 return Safe_FromString(File.Codename());
1254}
1255
1250static PyObject *PackageFile_GetSite(PyObject *Self,void*)1256static PyObject *PackageFile_GetSite(PyObject *Self,void*)
1251{1257{
1252 pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);1258 pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);
@@ -1305,6 +1311,8 @@
1305 "The archive of the package file (i.e. 'Suite' in the Release file)."},1311 "The archive of the package file (i.e. 'Suite' in the Release file)."},
1306 {"component",PackageFile_GetComponent,0,1312 {"component",PackageFile_GetComponent,0,
1307 "The component of this package file (e.g. 'main')."},1313 "The component of this package file (e.g. 'main')."},
1314 {"codename",PackageFile_GetCodename,0,
1315 "The codename of this package file (e.g. squeeze-updates)."},
1308 {"filename",PackageFile_GetFileName,0,1316 {"filename",PackageFile_GetFileName,0,
1309 "The path to the file."},1317 "The path to the file."},
1310 {"id",PackageFile_GetID,0,1318 {"id",PackageFile_GetID,0,
13111319
=== modified file 'python/generic.h'
--- python/generic.h 2011-08-01 07:29:25 +0000
+++ python/generic.h 2013-03-09 19:55:24 +0000
@@ -80,10 +80,14 @@
8080
81static inline const char *PyUnicode_AsString(PyObject *op) {81static inline const char *PyUnicode_AsString(PyObject *op) {
82 // Convert to bytes object, using the default encoding.82 // Convert to bytes object, using the default encoding.
83#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
84 return PyUnicode_AsUTF8(op);
85#else
83 // Use Python-internal API, there is no other way to do this86 // Use Python-internal API, there is no other way to do this
84 // without a memory leak.87 // without a memory leak.
85 PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);88 PyObject *bytes = _PyUnicode_AsDefaultEncodedString(op, 0);
86 return bytes ? PyBytes_AS_STRING(bytes) : 0;89 return bytes ? PyBytes_AS_STRING(bytes) : 0;
90#endif
87}91}
8892
89// Convert any type of string based object to a const char.93// Convert any type of string based object to a const char.
9094
=== modified file 'tests/test_apt_cache.py'
--- tests/test_apt_cache.py 2011-12-09 08:16:08 +0000
+++ tests/test_apt_cache.py 2013-03-09 19:55:24 +0000
@@ -7,19 +7,27 @@
7# are permitted in any medium without royalty provided the copyright7# are permitted in any medium without royalty provided the copyright
8# notice and this notice are preserved.8# notice and this notice are preserved.
9"""Unit tests for verifying the correctness of check_dep, etc in apt_pkg."""9"""Unit tests for verifying the correctness of check_dep, etc in apt_pkg."""
10
11import glob
12import logging
10import os13import os
14import shutil
15import sys
11import tempfile16import tempfile
12import unittest17import unittest
1318
19if sys.version_info[0] == 2 and sys.version_info[1] == 6:
20 from unittest2 import TestCase
21else:
22 from unittest import TestCase
23
24
14from test_all import get_library_dir25from test_all import get_library_dir
15import sys
16sys.path.insert(0, get_library_dir())26sys.path.insert(0, get_library_dir())
1727
18import apt28import apt
19import apt_pkg29import apt_pkg
20import shutil30
21import glob
22import logging
2331
24def if_sources_list_is_readable(f):32def if_sources_list_is_readable(f):
25 def wrapper(*args, **kwargs):33 def wrapper(*args, **kwargs):
@@ -29,7 +37,17 @@
29 logging.warn("skipping '%s' because sources.list is not readable" % f)37 logging.warn("skipping '%s' because sources.list is not readable" % f)
30 return wrapper38 return wrapper
3139
32class TestAptCache(unittest.TestCase):40
41def get_open_file_descriptors():
42 try:
43 fds = os.listdir("/proc/self/fd")
44 except OSError:
45 logging.warn("failed to list /proc/self/fd")
46 return set([])
47 return set(map(int, fds))
48
49
50class TestAptCache(TestCase):
33 """ test the apt cache """51 """ test the apt cache """
3452
35 def setUp(self):53 def setUp(self):
@@ -68,7 +86,34 @@
68 self.assertEqual(r['Package'], pkg.shortname)86 self.assertEqual(r['Package'], pkg.shortname)
69 self.assertTrue('Version' in r)87 self.assertTrue('Version' in r)
70 self.assertTrue(len(r['Description']) > 0)88 self.assertTrue(len(r['Description']) > 0)
71 self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname))89 self.assertTrue(
90 str(r).startswith('Package: %s\n' % pkg.shortname))
91
92 @if_sources_list_is_readable
93 def test_cache_close_leak_fd(self):
94 fds_before_open = get_open_file_descriptors()
95 cache = apt.Cache()
96 opened_fd = get_open_file_descriptors().difference(fds_before_open)
97 cache.close()
98 fds_after_close = get_open_file_descriptors()
99 unclosed_fd = opened_fd.intersection(fds_after_close)
100 self.assertEqual(fds_before_open, fds_after_close)
101 self.assertEqual(unclosed_fd, set())
102
103 def test_cache_open_twice_leaks_fds(self):
104 cache = apt.Cache()
105 fds_before_open = get_open_file_descriptors()
106 cache.open()
107 fds_after_open_twice = get_open_file_descriptors()
108 self.assertEqual(fds_before_open, fds_after_open_twice)
109
110 @if_sources_list_is_readable
111 def test_cache_close_download_fails(self):
112 cache = apt.Cache()
113 self.assertEqual(cache.required_download, 0)
114 cache.close()
115 with self.assertRaises(apt.cache.CacheClosedException):
116 cache.required_download
72117
73 def test_get_provided_packages(self):118 def test_get_provided_packages(self):
74 apt.apt_pkg.config.set("Apt::architecture", "i386")119 apt.apt_pkg.config.set("Apt::architecture", "i386")

Subscribers

People subscribed via source and target branches

to all changes: