summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-03-12 11:42:37 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2010-03-12 11:42:37 +0100
commit85238ea03cd35b48a90a2fc1f63f2cf05d5b83b4 (patch)
treebb7fcce7e80cc45e807eab19a3c36f628c888bd3 /apt
parent62a7342edb16c38e3d646cc731a4a50ad6657b4f (diff)
parentc657b7a2a59e15a0c415ba94021c4de547a78e60 (diff)
downloadpython-apt-85238ea03cd35b48a90a2fc1f63f2cf05d5b83b4.tar.gz
merged from debian-sid
Diffstat (limited to 'apt')
-rw-r--r--apt/cache.py37
-rw-r--r--apt/debfile.py22
-rw-r--r--apt/package.py34
-rw-r--r--apt/progress/base.py15
-rw-r--r--apt/progress/gtk2.py1
-rw-r--r--apt/progress/old.py92
-rw-r--r--apt/progress/text.py2
-rw-r--r--apt/utils.py20
8 files changed, 150 insertions, 73 deletions
diff --git a/apt/cache.py b/apt/cache.py
index b5733d98..2e6d24e5 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -46,17 +46,21 @@ class Cache(object):
"""Dictionary-like package cache.
This class has all the packages that are available in it's
- dictionary.
+ dictionary.
Keyword arguments:
progress -- a OpProgress object
- rootdir -- a alternative root directory. if that is given
- the system sources.list and system lists/ files are
+ rootdir -- a alternative root directory. if that is given
+ the system sources.list and system lists/ files are
not read, only files relative to the given rootdir
memonly -- build the cache in memory only
"""
def __init__(self, progress=None, rootdir=None, memonly=False):
+ self._cache = None
+ self._depcache = None
+ self._records = None
+ self._list = None
self._callbacks = {}
self._weakref = weakref.WeakValueDictionary()
self._set = set()
@@ -95,12 +99,12 @@ class Cache(object):
"/var/lib/apt/lists/partial",
]
for d in dirs:
- if not os.path.exists(rootdir+d):
- print "creating: ",rootdir+d
- os.makedirs(rootdir+d)
+ if not os.path.exists(rootdir + d):
+ print "creating: ", rootdir + d
+ os.makedirs(rootdir + d)
for f in files:
- if not os.path.exists(rootdir+f):
- open(rootdir+f,"w")
+ if not os.path.exists(rootdir + f):
+ open(rootdir + f, "w")
def _run_callbacks(self, name):
""" internal helper to run a callback """
@@ -125,12 +129,12 @@ class Cache(object):
self._weakref.clear()
progress.op = _("Building data structures")
- i=last=0
- size=len(self._cache.packages)
+ i = last = 0
+ size = len(self._cache.packages)
for pkg in self._cache.packages:
if progress is not None and last+100 < i:
progress.update(i/float(size)*100)
- last=i
+ last = i
# drop stuff with no versions (cruft)
if len(pkg.version_list) > 0:
self._set.add(pkg.name)
@@ -376,9 +380,10 @@ class Cache(object):
elif res == pm.RESULT_FAILED:
raise SystemError("installArchives() failed")
elif res == pm.RESULT_INCOMPLETE:
- pass
+ pass
else:
- raise SystemError("internal-error: unknown result code from InstallArchives: %s" % res)
+ raise SystemError("internal-error: unknown result code "
+ "from InstallArchives: %s" % res)
# reload the fetcher for media swaping
fetcher.shutdown()
return (res == pm.RESULT_COMPLETED)
@@ -623,9 +628,9 @@ def _test():
# see if fetching works
- for dir in ["/tmp/pytest", "/tmp/pytest/partial"]:
- if not os.path.exists(dir):
- os.mkdir(dir)
+ for dirname in ["/tmp/pytest", "/tmp/pytest/partial"]:
+ if not os.path.exists(dirname):
+ os.mkdir(dirname)
apt_pkg.config.set("Dir::Cache::Archives", "/tmp/pytest")
pm = apt_pkg.PackageManager(cache._depcache)
fetcher = apt_pkg.Acquire(apt.progress.text.AcquireProgress())
diff --git a/apt/debfile.py b/apt/debfile.py
index e27917d5..ccaa25e4 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -43,6 +43,9 @@ class DebPackage(object):
def __init__(self, filename=None, cache=None):
self._cache = cache
self._need_pkgs = []
+ self._debfile = None
+ self.pkgname = ""
+ self.filename = filename
self._sections = {}
self._installed_conflicts = set()
self._failure_string = ""
@@ -168,9 +171,6 @@ class DebPackage(object):
"""Check the or-group for conflicts with installed pkgs."""
self._dbg(2, "_check_conflicts_or_group(): %s " % (or_group))
- or_found = False
- virtual_pkg = None
-
for dep in or_group:
depname = dep[0]
ver = dep[1]
@@ -287,13 +287,13 @@ class DebPackage(object):
else:
cachever = self._cache[pkgname].candidate.version
if cachever is not None:
- cmp = apt_pkg.version_compare(cachever, debver)
- self._dbg(1, "CompareVersion(debver,instver): %s" % cmp)
- if cmp == 0:
+ cmpres = apt_pkg.version_compare(cachever, debver)
+ self._dbg(1, "CompareVersion(debver,instver): %s" % cmpres)
+ if cmpres == 0:
return VERSION_SAME
- elif cmp < 0:
+ elif cmpres < 0:
return VERSION_NEWER
- elif cmp > 0:
+ elif cmpres > 0:
return VERSION_OUTDATED
return VERSION_NONE
@@ -361,7 +361,7 @@ class DebPackage(object):
for pkg in self._need_pkgs:
try:
self._cache[pkg].mark_install(fromUser=False)
- except SystemError, e:
+ except SystemError:
self._failure_string = _("Cannot install '%s'" % pkg)
self._cache.clear()
return False
@@ -427,7 +427,8 @@ class DscSrcPackage(DebPackage):
DebPackage.__init__(self, None, cache)
self._depends = []
self._conflicts = []
- self._binaries = []
+ self.pkgname = ""
+ self.binaries = []
if filename is not None:
self.open(filename)
@@ -465,7 +466,6 @@ class DscSrcPackage(DebPackage):
if 'Version' in sec:
self._sections['Version'] = sec['Version']
finally:
- del sec
del tagfile
fobj.close()
diff --git a/apt/package.py b/apt/package.py
index 7f736583..0c026504 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -70,9 +70,18 @@ class BaseDependency(object):
pre_depend - Boolean value whether this is a pre-dependency.
"""
+ class __dstr(str):
+ """Helper to make > match >> and < match <<"""
+
+ def __eq__(self, other):
+ return str.__eq__(self, other) or str.__eq__(2 * self, other)
+
+ def __ne__(self, other):
+ return str.__eq__(self, other) and str.__ne__(2 * self, other)
+
def __init__(self, name, rel, ver, pre, rawtype=None):
self.name = name
- self.relation = rel
+ self.relation = len(rel) == 1 and self.__dstr(rel) or rel
self.version = ver
self.pre_depend = pre
self.rawtype = rawtype
@@ -528,9 +537,10 @@ class Version(object):
dsc = None
record = self._records
src.lookup(record.source_pkg)
+ source_version = record.source_ver or self._cand.ver_str
try:
- while record.source_ver != src.version:
+ while source_version != src.version:
src.lookup(record.source_pkg)
except AttributeError:
raise ValueError("No source for %r" % self)
@@ -971,7 +981,7 @@ class Package(object):
which if set, prevents the download.
"""
# Return a cached changelog if available
- if self._changelog != "":
+ if self._changelog != u"":
return self._changelog
if uri is None:
@@ -986,7 +996,8 @@ class Package(object):
"/%(src_section)s/%(prefix)s/%(src_pkg)s" \
"/%(src_pkg)s_%(src_ver)s/changelog"
else:
- return _("The list of changes is not available")
+ res = _("The list of changes is not available")
+ return res if isinstance(res, unicode) else res.decode("utf-8")
# get the src package name
src_pkg = self.candidate.source_name
@@ -1056,15 +1067,15 @@ class Package(object):
# Check if the download was canceled
if cancel_lock and cancel_lock.isSet():
- return ""
+ return u""
changelog_file = urllib2.urlopen(uri)
# do only get the lines that are new
- changelog = ""
+ changelog = u""
regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg))
while True:
# Check if the download was canceled
if cancel_lock and cancel_lock.isSet():
- return ""
+ return u""
# Read changelog line by line
line_raw = changelog_file.readline()
if line_raw == "":
@@ -1084,6 +1095,7 @@ class Package(object):
changelog_ver = match.group(1)
if changelog_ver and ":" in changelog_ver:
changelog_ver = changelog_ver.split(":", 1)[1]
+
if (installed and apt_pkg.version_compare(
changelog_ver, installed) <= 0):
break
@@ -1093,17 +1105,21 @@ class Package(object):
# Print an error if we failed to extract a changelog
if len(changelog) == 0:
changelog = _("The list of changes is not available")
+ if not isinstance(changelog, unicode):
+ changelog = changelog.decode("utf-8")
self._changelog = changelog
except urllib2.HTTPError:
- return _("The list of changes is not available yet.\n\n"
+ res = _("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)
+ return res if isinstance(res, unicode) else res.decode("utf-8")
except (IOError, httplib.BadStatusLine):
- return _("Failed to download the list of changes. \nPlease "
+ res = _("Failed to download the list of changes. \nPlease "
"check your Internet connection.")
+ return res if isinstance(res, unicode) else res.decode("utf-8")
finally:
socket.setdefaulttimeout(timeout)
return self._changelog
diff --git a/apt/progress/base.py b/apt/progress/base.py
index 8075f790..6822b74a 100644
--- a/apt/progress/base.py
+++ b/apt/progress/base.py
@@ -16,6 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
+# pylint: disable-msg = R0201
"""Base classes for progress reporting.
Custom progress classes should inherit from these classes. They can also be
@@ -28,7 +29,6 @@ import re
import select
import apt_pkg
-from apt.deprecation import function_deprecated_by
__all__ = ['AcquireProgress', 'CdromProgress', 'InstallProgress', 'OpProgress']
@@ -137,7 +137,7 @@ class CdromProgress(object):
class InstallProgress(object):
"""Class to report the progress of installing packages."""
- percent, select_timeout, status = 0.0, 0.1, ""
+ child_pid, percent, select_timeout, status = 0, 0.0, 0.1, ""
def __init__(self):
(self.statusfd, self.writefd) = os.pipe()
@@ -159,9 +159,6 @@ class InstallProgress(object):
def status_change(self, pkg, percent, status):
"""(Abstract) Called when the APT status changed."""
- # compat with 0.7
- if apt_pkg._COMPAT_0_7 and hasattr(self, "statusChange"):
- self.statusChange(pkg, percent, status)
def dpkg_status_change(self, pkg, status):
"""(Abstract) Called when the dpkg status changed."""
@@ -197,7 +194,8 @@ class InstallProgress(object):
os._exit(obj.do_install(self.write_stream.fileno()))
except AttributeError:
os._exit(os.spawnlp(os.P_WAIT, "dpkg", "dpkg", "--status-fd",
- str(self.write_stream.fileno()), "-i", obj))
+ str(self.write_stream.fileno()), "-i",
+ obj))
except Exception:
os._exit(apt_pkg.PackageManager.RESULT_FAILED)
@@ -266,8 +264,9 @@ class InstallProgress(object):
(pid, res) = (0, 0)
while True:
try:
- select.select([self.status_stream], [], [], self.select_timeout)
- except select.error, (errno_, errstr):
+ select.select([self.status_stream], [], [],
+ self.select_timeout)
+ except select.error, (errno_, _errstr):
if errno_ != errno.EINTR:
raise
diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py
index 29e730a3..acb01eed 100644
--- a/apt/progress/gtk2.py
+++ b/apt/progress/gtk2.py
@@ -124,6 +124,7 @@ class GInstallProgress(gobject.GObject, base.InstallProgress):
base.InstallProgress.__init__(self)
gobject.GObject.__init__(self)
self.finished = False
+ self.apt_status = -1
self.time_last_update = time.time()
self.term = term
reaper = vte.reaper_get()
diff --git a/apt/progress/old.py b/apt/progress/old.py
index 15ead890..4bd79f2e 100644
--- a/apt/progress/old.py
+++ b/apt/progress/old.py
@@ -18,6 +18,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
+# pylint: disable-msg = C0103
"""Deprecated progress reporting classes.
This module provides classes for compatibility with python-apt 0.7. They are
@@ -39,6 +40,11 @@ __all__ = []
class OpProgress(base.OpProgress):
"""Abstract class to implement reporting on cache opening."""
+ def __init__(self):
+ base.OpProgress.__init__(self)
+ warnings.warn("apt.progress.OpProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
+
subOp = AttributeDeprecatedBy('subop')
Op = AttributeDeprecatedBy('op')
@@ -46,6 +52,11 @@ class OpProgress(base.OpProgress):
class OpTextProgress(OpProgress, text.OpProgress):
"""A simple text based cache open reporting class."""
+ def __init__(self):
+ text.OpProgress.__init__(self)
+ warnings.warn("apt.progress.OpTextProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
+
class FetchProgress(object):
"""Report the download/fetching progress."""
@@ -64,7 +75,8 @@ class FetchProgress(object):
self.totalBytes = 0
self.totalItems = 0
self.currentCPS = 0
- warnings.warn("FetchProgress() is deprecated.", DeprecationWarning)
+ warnings.warn("apt.progress.FetchProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
def start(self):
"""Called when the fetching starts."""
@@ -159,27 +171,55 @@ class TextFetchProgress(FetchProgress):
return raw_input() not in ('c', 'C')
-class CdromProgress(base.CdromProgress):
- """Report the cdrom add progress.
+class CdromProgress(object):
+ """Report the cdrom add progress."""
- This class has been replaced by apt_pkg.CdromProgress.
- """
- _basetype = base.CdromProgress
- askCdromName = function_deprecated_by(_basetype.ask_cdrom_name)
- changeCdrom = function_deprecated_by(_basetype.change_cdrom)
- del _basetype
+ def __init__(self):
+ warnings.warn("apt.progress.CdromProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
+
+ def askCdromName(self):
+ """Ask for a cdrom name"""
+
+ def changeCdrom(self):
+ """Change cdrom"""
+
+ def update(self, text, current):
+ """Update."""
class DumbInstallProgress(base.InstallProgress):
- """Report the install progress.
+ """Report the install progress."""
- Subclass this class to implement install progress reporting.
- """
+ def __init__(self):
+ base.InstallProgress.__init__(self)
+ warnings.warn("apt.progress.*InstallProgress are deprecated.",
+ DeprecationWarning, stacklevel=2)
- startUpdate = function_deprecated_by(base.InstallProgress.start_update)
- finishUpdate = function_deprecated_by(base.InstallProgress.finish_update)
- updateInterface = function_deprecated_by(
- base.InstallProgress.update_interface)
+ def updateInterface(self):
+ # *_stream were not available in the old progress reporting classes,
+ # create the attributes if they do not exist yet; as they are used
+ # in base.InstallProgress.update_interface().
+ if hasattr(self, "writefd") and not hasattr(self, "write_stream"):
+ self.write_stream = os.fdopen(self.writefd, "w")
+ if hasattr(self, "statusfd") and not hasattr(self, "status_stream"):
+ self.status_stream = os.fdopen(self.statusfd, "r")
+ return base.InstallProgress.update_interface(self)
+
+ def update_interface(self):
+ return self.updateInterface()
+
+ def startUpdate(self):
+ return base.InstallProgress.start_update(self)
+
+ def start_update(self):
+ return self.startUpdate()
+
+ def finishUpdate(self):
+ return base.InstallProgress.finish_update(self)
+
+ def finish_update(self):
+ return self.finishUpdate()
class InstallProgress(DumbInstallProgress, base.InstallProgress):
@@ -190,17 +230,29 @@ class InstallProgress(DumbInstallProgress, base.InstallProgress):
"""
selectTimeout = AttributeDeprecatedBy('select_timeout')
- statusChange = function_deprecated_by(base.InstallProgress.status_change)
- updateInterface = function_deprecated_by(base.InstallProgress.update_interface)
- waitChild = function_deprecated_by(base.InstallProgress.wait_child)
+
+ def statusChange(self, pkg, percent, status):
+ return base.InstallProgress.status_change(self, pkg, percent, status)
+
+ def status_change(self, pkg, percent, status):
+ return self.statusChange(pkg, percent, status)
+
+ def waitChild(self):
+ return base.InstallProgress.wait_child(self)
+
+ def wait_child(self):
+ return self.waitChild()
class DpkgInstallProgress(InstallProgress):
"""Progress handler for a local Debian package installation."""
+ debfile = ""
+ debname = ""
+
def run(self, debfile):
"""Start installing the given Debian package."""
# Deprecated stuff
self.debfile = debfile
self.debname = os.path.basename(debfile).split("_")[0]
- return base.InstallProgress(self, debfile)
+ return base.InstallProgress.run(self, debfile)
diff --git a/apt/progress/text.py b/apt/progress/text.py
index 5e45c1db..95f18831 100644
--- a/apt/progress/text.py
+++ b/apt/progress/text.py
@@ -257,5 +257,3 @@ class CdromProgress(base.CdromProgress, TextProgress):
return (raw_input() == '')
except KeyboardInterrupt:
return False
-
-InstallProgress = base.InstallProgress
diff --git a/apt/utils.py b/apt/utils.py
index 61d5d54f..80ba6d65 100644
--- a/apt/utils.py
+++ b/apt/utils.py
@@ -17,9 +17,11 @@
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-import apt_pkg
import os.path
+import apt_pkg
+
+
def get_maintenance_end_date(release_date, m_months):
"""
get the (year, month) tuple when the maintenance for the distribution
@@ -28,10 +30,12 @@ def get_maintenance_end_date(release_date, m_months):
"""
years = m_months / 12
months = m_months % 12
- support_end_year = release_date.year + years + (release_date.month + months)/12
+ support_end_year = (release_date.year + years +
+ (release_date.month + months)/12)
support_end_month = (release_date.month + months) % 12
return (support_end_year, support_end_month)
+
def get_release_date_from_release_file(path):
"""
return the release date as time_t for the given release file
@@ -45,6 +49,7 @@ def get_release_date_from_release_file(path):
date = section["Date"]
return apt_pkg.str_to_time(date)
+
def get_release_filename_for_pkg(cache, pkgname, label, release):
" get the release file that provides this pkg "
if pkgname not in cache:
@@ -54,9 +59,9 @@ def get_release_filename_for_pkg(cache, pkgname, label, release):
# look for the version that comes from the repos with
# the given label and origin
for aver in pkg._pkg.version_list:
- if aver == None or aver.file_list == None:
+ if aver is None or aver.file_list is None:
continue
- for ver_file, index in aver.file_list:
+ for ver_file, _index in aver.file_list:
#print verFile
if (ver_file.origin == label and
ver_file.label == label and
@@ -70,7 +75,8 @@ def get_release_filename_for_pkg(cache, pkgname, label, release):
if (indexfile and
indexfile.describe == m.describe and
indexfile.is_trusted):
- dir = apt_pkg.config.find_dir("Dir::State::lists")
- name = apt_pkg.uri_to_filename(metaindex.uri)+"dists_%s_Release" % metaindex.dist
- return dir+name
+ dirname = apt_pkg.config.find_dir("Dir::State::lists")
+ name = (apt_pkg.uri_to_filename(metaindex.uri) +
+ "dists_%s_Release" % metaindex.dist)
+ return dirname + name
return None