From 3fbbced1f6d22d6ce3a7188032b0d19251159fbd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 1 Apr 2009 15:34:44 +0200 Subject: * apt/package.py: Introduce Version.{uri,uris,fetch_binary()} --- apt/package.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 9 deletions(-) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index 37cd33fb..595cf8ec 100644 --- a/apt/package.py +++ b/apt/package.py @@ -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): -- cgit v1.2.3 From 312b5ca7acbe74bc73acc2b710628ea2a8ad83cc Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 1 Apr 2009 16:27:15 +0200 Subject: * Copyright updates: debian/copyright, etc. - debian/copyright: Switch to machine-interpretable copyright - apt/*.py: Fix the copyright years and comments. --- apt/__init__.py | 18 +++++++++++++++ apt/cache.py | 2 +- apt/cdrom.py | 2 +- apt/debfile.py | 31 ++++++++++++------------- apt/package.py | 2 +- apt/progress/__init__.py | 4 ++-- apt/progress/gtk2.py | 2 +- aptsources/distinfo.py | 10 ++++---- aptsources/distro.py | 4 ++-- aptsources/sourceslist.py | 12 +++++----- debian/changelog | 1 + debian/copyright | 58 ++++++++++++++++++++++++++++++++++++++++++----- 12 files changed, 103 insertions(+), 43 deletions(-) (limited to 'apt') 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 +# +# 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 # 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 # # Author: Michael Vogt 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 +# Author: Michael Vogt # -# 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 595cf8ec..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 # 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 # 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 # Sebastian Heinlein diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py index 59fa7e02..ce44e48b 100644 --- a/aptsources/distinfo.py +++ b/aptsources/distinfo.py @@ -1,12 +1,10 @@ -#!/usr/bin/env python -# # distinfo.py - provide meta information for distro repositories # -# Copyright (c) 2005 Gustavo Noronha Silva -# 2006-2007 Sebastian Heinlein +# Copyright (c) 2005 Gustavo Noronha Silva +# Copyright (c) 2006-2007 Sebastian Heinlein # -# Author: Gustavo Noronha Silva -# Sebastian Heinlein +# Authors: Gustavo Noronha Silva +# Sebastian Heinlein # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as diff --git a/aptsources/distro.py b/aptsources/distro.py index d81c6e4a..bbb8ba50 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -1,7 +1,7 @@ # distro.py - Provide a distro abstraction of the sources.list # -# Copyright (c) 2004-2007 Canonical Ltd. -# 2006-2007 Sebastian Heinlein +# Copyright (c) 2004-2009 Canonical Ltd. +# Copyright (c) 2006-2007 Sebastian Heinlein # # Authors: Sebastian Heinlein # Michael Vogt diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index b1f00446..1dfd870f 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -1,12 +1,12 @@ # aptsource.py - Provide an abstraction of the sources.list # -# Copyright (c) 2004-2007 Canonical Ltd. -# 2004 Michiel Sikkes -# 2006-2007 Sebastian Heinlein +# Copyright (c) 2004-2009 Canonical Ltd. +# Copyright (c) 2004 Michiel Sikkes +# Copyright (c) 2006-2007 Sebastian Heinlein # -# Author: Michiel Sikkes -# Michael Vogt -# Sebastian Heinlein +# Authors: Michiel Sikkes +# Michael Vogt +# Sebastian Heinlein # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as diff --git a/debian/changelog b/debian/changelog index f51944f9..91ce7304 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ python-apt (0.7.10~exp1) experimental; urgency=low - Remove mdz from Uploaders (Closes: #521477), add myself. - Update Standards-Version to 3.8.1 - Use ${binary:Version} instead of ${Source-Version} + * debian/copyright: Switch to machine-interpretable copyright -- Julian Andres Klode Wed, 01 Apr 2009 15:24:29 +0200 diff --git a/debian/copyright b/debian/copyright index f8463185..8599328a 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,7 +1,53 @@ -APT is free software; you can redistribute them and/or modify them 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. +Format-Specification: http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=443 -On Debian systems, a copy of the GNU General Public License can be -found in /usr/share/common-licenses/GPL. +Files: * +Copyright: © 2004-2009 Canonical Ltd. +License: GPL-2+ + +Files: aptsources/*.py +Copyright: © 2004-2009 Canonical Ltd. +Copyright: © 2005 Gustavo Noronha Silva +Copyright: © 2006-2007 Sebastian Heinlein +License: GPL-2+ + +Files: doc/source/* +Copyright: © 2009 Julian Andres Klode +License: GPL-2+ + +Files: utils/get_*.py +Copyright: © 2006 Free Software Foundation Europe +License: GPL-2+ + +Files: po/* +Copyright: © 2006 Canonical Ltd, and Rosetta Contributors 2006 +License: GPL-2+ + +Files: po/de.po +Copyright: © 2005 Michiel Sikkes +License: GPL-2+ + +Files: po/en_CA.po +Copyright: © 2005 Adam Weinberger and the GNOME Foundation +License: GPL-2+ + +Files: po/fi.po +Copyright: © 2005-2006 Timo Jyrinki +License: GPL-2+ + +Files: po/fr.po +Copyright: © 2007 Hugues NAULET +License: GPL-2+ + +Files: po/hu.po, po/lt.po, po/pt.po, po/ro.po, po/rw.po, po/sv.po, po/uk.po, + po/zh_HK.po +Copyright: © 2005-2006 Free Software Foundation +License: GPL-2+ + +License: GPL-2+ + APT is free software; you can redistribute them and/or modify them 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. + . + On Debian systems, a copy of the GNU General Public License can be + found in /usr/share/common-licenses/GPL-2. -- cgit v1.2.3