summaryrefslogtreecommitdiff
path: root/apt/package.py
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-05-26 18:01:26 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-05-26 18:01:26 +0200
commit19e2e0f210da3fb4cb87cfe1ddd4bbc6c61d8cd1 (patch)
tree917dd7e06549e3ac7efffdae3c8e9d02788ac81d /apt/package.py
parente0b2560ab0fab5716187b7a1f93052373f5cbd23 (diff)
downloadpython-apt-19e2e0f210da3fb4cb87cfe1ddd4bbc6c61d8cd1.tar.gz
merge from debian, omit disable of the 0.7 API
Diffstat (limited to 'apt/package.py')
-rw-r--r--apt/package.py50
1 files changed, 39 insertions, 11 deletions
diff --git a/apt/package.py b/apt/package.py
index d7d5d167..14e80594 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -50,9 +50,9 @@ __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record',
def _file_is_same(path, size, md5):
"""Return ``True`` if the file is the same."""
- if (os.path.exists(path) and os.path.getsize(path) == size and
- apt_pkg.md5sum(open(path)) == md5):
- return True
+ if os.path.exists(path) and os.path.getsize(path) == size:
+ with open(path) as fobj:
+ return apt_pkg.md5sum(fobj) == md5
class FetchError(Exception):
@@ -162,10 +162,23 @@ class Origin(object):
class Record(Mapping):
- """Represent a pkgRecord.
+ """Record in a Packages file
+
+ Represent a record as stored in a Packages file. You can use this like
+ a dictionary mapping the field names of the record to their values::
+
+ >>> record = Record("Package: python-apt\\nVersion: 0.8.0\\n\\n")
+ >>> record["Package"]
+ 'python-apt'
+ >>> record["Version"]
+ '0.8.0'
+
+ For example, to get the tasks of a package from a cache, you could do::
+
+ package.candidate.record["Tasks"].split()
+
+ Of course, you can also use the :attr:`Version.tasks` property.
- It can be accessed like a dictionary and can also give the original package
- record if accessed as a string.
"""
def __init__(self, record_str):
@@ -209,6 +222,9 @@ class Record(Mapping):
class Version(object):
"""Representation of a package version.
+ The Version class contains all information related to a
+ specific package version.
+
.. versionadded:: 0.7.9
"""
@@ -393,7 +409,11 @@ class Version(object):
@property
def record(self):
- """Return a Record() object for this version."""
+ """Return a Record() object for this version.
+
+ Return a Record() object for this version which provides access
+ to the raw attributes of the candidate version
+ """
return Record(self._records.record)
def get_dependencies(self, *types):
@@ -474,6 +494,16 @@ class Version(object):
"""
return self._records.sha256_hash
+ @property
+ def tasks(self):
+ """Get the tasks of the package.
+
+ A set of the names of the tasks this package belongs to.
+
+ .. versionadded:: 0.8.0
+ """
+ return set(self.record["Task"].split())
+
def _uris(self):
"""Return an iterator over all available urls.
@@ -994,11 +1024,8 @@ class Package(object):
"""
path = "/var/lib/dpkg/info/%s.list" % self.name
try:
- file_list = open(path, "rb")
- try:
+ with open(path, "rb") as file_list:
return file_list.read().decode("utf-8").split(u"\n")
- finally:
- file_list.close()
except EnvironmentError:
return []
@@ -1104,6 +1131,7 @@ class Package(object):
# Check if the download was canceled
if cancel_lock and cancel_lock.isSet():
return u""
+ # FIXME: python3.2: Should be closed manually
changelog_file = urllib2.urlopen(uri)
# do only get the lines that are new
changelog = u""