summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-04-01 17:40:54 +0200
committerJulian Andres Klode <jak@debian.org>2009-04-01 17:40:54 +0200
commit75eeb9186bd254f60964d2ec9e70c45ecc92a247 (patch)
treef976207303584c5006f6ad48455fabfa97078ce7 /apt
parentc884ff15493617480ac2fa5a4bbbd75cce3f9a51 (diff)
parentb2d0d968e0aa3e3211b1a697c02117b7c09fb384 (diff)
downloadpython-apt-75eeb9186bd254f60964d2ec9e70c45ecc92a247.tar.gz
python-apt (0.7.10) unstable; urgency=low
* Build-Depend on python-debian, use it to get version number from changelog * Depend on libjs-jquery, and remove internal copy (Closes: #521532) * apt/package.py: - Introduce Version.{uri,uris,fetch_binary()} * debian/control: - Remove mdz from Uploaders (Closes: #521477), add myself. - Update Standards-Version to 3.8.1 - Use ${binary:Version} instead of ${Source-Version} - Fix spelling error: python -> Python * debian/copyright: Switch to machine-interpretable copyright * Fix documentation building - doc/source/conf.py: Only include directories for current python version. - debian/control: Build-Depend on python-gtk2, python-vte. - setup.py: If pygtk can not be imported, do not build the documentation. * Breaks: debdelta (<< 0.28~) to avoid more problems due to the internal API changes from 0.7.9. -- Julian Andres Klode <jak@debian.org> Wed, 01 Apr 2009 15:24:29 +0200
Diffstat (limited to 'apt')
-rw-r--r--apt/__init__.py18
-rw-r--r--apt/cache.py2
-rw-r--r--apt/cdrom.py2
-rw-r--r--apt/debfile.py31
-rw-r--r--apt/package.py118
-rw-r--r--apt/progress/__init__.py4
-rw-r--r--apt/progress/gtk2.py2
7 files changed, 145 insertions, 32 deletions
diff --git a/apt/__init__.py b/apt/__init__.py
index e3cfacbe..ae2abbf2 100644
--- a/apt/__init__.py
+++ b/apt/__init__.py
@@ -1,3 +1,21 @@
+# Copyright (c) 2005-2009 Canonical
+#
+# Author: Michael Vogt <michael.vogt@ubuntu.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
# import the core of apt_pkg
import apt_pkg
import sys
diff --git a/apt/cache.py b/apt/cache.py
index a9430d6b..cc425ccb 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -1,6 +1,6 @@
# cache.py - apt cache abstraction
#
-# Copyright (c) 2005 Canonical
+# Copyright (c) 2005-2009 Canonical
#
# Author: Michael Vogt <michael.vogt@ubuntu.com>
#
diff --git a/apt/cdrom.py b/apt/cdrom.py
index 61250fc4..b52762ad 100644
--- a/apt/cdrom.py
+++ b/apt/cdrom.py
@@ -1,6 +1,6 @@
# cdrom.py - CDROM handling
#
-# Copyright (c) 2005 Canonical
+# Copyright (c) 2005-2009 Canonical
# Copyright (c) 2009 Julian Andres Klode <jak@debian.org>
#
# Author: Michael Vogt <michael.vogt@ubuntu.com>
diff --git a/apt/debfile.py b/apt/debfile.py
index c550d766..0406a250 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -1,24 +1,21 @@
-# Copyright (c) 2005-2007 Canonical
+# Copyright (c) 2005-2009 Canonical
#
-# AUTHOR:
-# Michael Vogt <mvo@ubuntu.com>
+# Author: Michael Vogt <michael.vogt@ubuntu.com>
#
-# This file is part of GDebi
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
#
-# GDebi is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as published
-# by the Free Software Foundation; either version 2 of the License, or (at
-# your option) any later version.
-#
-# GDebi is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GDebi; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
"""Classes for working with locally available Debian packages."""
from gettext import gettext as _
import os
diff --git a/apt/package.py b/apt/package.py
index 37cd33fb..9afe1674 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -1,6 +1,6 @@
# package.py - apt package abstraction
#
-# Copyright (c) 2005 Canonical
+# Copyright (c) 2005-2009 Canonical
#
# Author: Michael Vogt <michael.vogt@ubuntu.com>
#
@@ -41,6 +41,17 @@ def _(string):
return gettext.dgettext("python-apt", string)
+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
+
+
+class FetchError(Exception):
+ """Raised when a file could not be fetched."""
+
+
class BaseDependency(object):
"""A single dependency.
@@ -338,10 +349,87 @@ class Version(object):
origins.append(Origin(self.package, verFileIter))
return origins
- def fetch_source(self):
- """Get the source code of a package"""
+ @property
+ def filename(self):
+ """Return the path to the file inside the archive."""
+ return self._records.FileName
+
+ @property
+ def md5(self):
+ """Return the md5sum of the binary."""
+ return self._records.MD5Hash
+
+ @property
+ def sha1(self):
+ """Return the sha1sum of the binary."""
+ return self._records.SHA1Hash
+
+ @property
+ def sha256(self):
+ """Return the sha1sum of the binary."""
+ return self._records.SHA256Hash
+
+ def _uris(self):
+ """Return an iterator over all available urls."""
+ for (packagefile, index) in self._cand.FileList:
+ indexfile = self.package._pcache._list.FindIndex(packagefile)
+ if indexfile:
+ yield indexfile.ArchiveURI(self._records.FileName)
+
+ @property
+ def uris(self):
+ """Return a list of all available uris for the binary."""
+ return list(self._uris())
+
+ @property
+ def uri(self):
+ """Return a single URI for the binary."""
+ return self._uris().next()
+
+ def fetch_binary(self, destdir='', progress=None):
+ """Fetch the binary version of the package.
+
+ The parameter 'destdir' specifies the directory where the package will
+ be fetched to.
+
+ The parameter 'progress' may refer to an apt.progress.FetchProgress()
+ object. If not specified or None, apt.progress.TextFetchProgress() is
+ used.
+ """
+ base = os.path.basename(self._records.FileName)
+ destfile = os.path.join(destdir, base)
+ if _file_is_same(destfile, self.size, self._records.MD5Hash):
+ print 'Ignoring already existing file:', destfile
+ return
+ acq = apt_pkg.GetAcquire(progress or apt.progress.TextFetchProgress())
+ apt_pkg.GetPkgAcqFile(acq, self.uri, self._records.MD5Hash, self.size,
+ base, destFile=destfile)
+ acq.Run()
+ for item in acq.Items:
+ if item.Status != item.StatDone:
+ raise FetchError("The item %r could not be fetched: %s" %
+ (item.DestFile, item.ErrorText))
+ return os.path.abspath(destfile)
+
+ def fetch_source(self, destdir="", progress=None, unpack=True):
+ """Get the source code of a package.
+
+ The parameter 'destdir' specifies the directory where the source will
+ be fetched to.
+
+ The parameter 'progress' may refer to an apt.progress.FetchProgress()
+ object. If not specified or None, apt.progress.TextFetchProgress() is
+ used.
+
+ The parameter 'unpack' describes whether the source should be unpacked
+ (True) or not (False). By default, it is unpacked.
+
+ If 'unpack' is True, the path to the extracted directory is returned.
+ Otherwise, the path to the .dsc file is returned.
+ """
src = apt_pkg.GetPkgSrcRecords()
- acq = apt_pkg.GetAcquire(apt.progress.TextFetchProgress())
+ acq = apt_pkg.GetAcquire(progress or apt.progress.TextFetchProgress())
+
dsc = None
src.Lookup(self.package.name)
try:
@@ -351,23 +439,33 @@ class Version(object):
raise ValueError("No source for %r" % self)
for md5, size, path, type in src.Files:
base = os.path.basename(path)
+ destfile = os.path.join(destdir, base)
if type == 'dsc':
- dsc = base
+ dsc = destfile
if os.path.exists(base) and os.path.getsize(base) == size:
fobj = open(base)
try:
if apt_pkg.md5sum(fobj) == md5:
- print 'Ignoring already existing file', base
+ print 'Ignoring already existing file:', destfile
continue
finally:
fobj.close()
apt_pkg.GetPkgAcqFile(acq, src.Index.ArchiveURI(path), md5, size,
- base)
+ base, destFile=destfile)
acq.Run()
- outdir = src.Package + '-' + apt_pkg.UpstreamVersion(src.Version)
- subprocess.check_call(["dpkg-source", "-x", dsc, outdir])
- return os.path.abspath(outdir)
+ for item in acq.Items:
+ if item.Status != item.StatDone:
+ raise FetchError("The item %r could not be fetched: %s" %
+ (item.DestFile, item.ErrorText))
+
+ if unpack:
+ outdir = src.Package + '-' + apt_pkg.UpstreamVersion(src.Version)
+ outdir = os.path.join(destdir, outdir)
+ subprocess.check_call(["dpkg-source", "-x", dsc, outdir])
+ return os.path.abspath(outdir)
+ else:
+ return os.path.abspath(dsc)
class Package(object):
diff --git a/apt/progress/__init__.py b/apt/progress/__init__.py
index 51eb2426..769942ce 100644
--- a/apt/progress/__init__.py
+++ b/apt/progress/__init__.py
@@ -1,6 +1,6 @@
-# Progress.py - progress reporting classes
+# progress.py - progress reporting classes
#
-# Copyright (c) 2005 Canonical
+# Copyright (c) 2005-2009 Canonical
#
# Author: Michael Vogt <michael.vogt@ubuntu.com>
#
diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py
index 435265d4..f872e34f 100644
--- a/apt/progress/gtk2.py
+++ b/apt/progress/gtk2.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (c) 2004-2005 Canonical
+# Copyright (c) 2004-2009 Canonical
#
# Authors: Michael Vogt <michael.vogt@ubuntu.com>
# Sebastian Heinlein <glatzor@ubuntu.com>