summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2010-03-29 13:20:52 +0200
committerJulian Andres Klode <jak@debian.org>2010-03-29 13:20:52 +0200
commit4b74ecd4df220fcb9939445a9774bbcf6ba3212e (patch)
treefe24df1f2b3c5c1fd3dd4dc171bbfd5d2f8bc694 /apt
parent4f1a8ff1fcd780c2d42dbc59f41ca38581e6f10c (diff)
downloadpython-apt-4b74ecd4df220fcb9939445a9774bbcf6ba3212e.tar.gz
If PYTHON_APT_DEPRECATION_WARNINGS is unset, also disable the
deprecation warnings in apt_pkg directly; and don't just disable any deprecation warning in apt/__init__.py (LP: #548623)
Diffstat (limited to 'apt')
-rw-r--r--apt/__init__.py5
-rw-r--r--apt/deprecation.py13
-rw-r--r--apt/package.py2
-rw-r--r--apt/progress/old.py25
4 files changed, 25 insertions, 20 deletions
diff --git a/apt/__init__.py b/apt/__init__.py
index 8b66ad13..a8a8b8fc 100644
--- a/apt/__init__.py
+++ b/apt/__init__.py
@@ -17,11 +17,6 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-import os
-import warnings
-if not "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
- warnings.simplefilter('ignore', DeprecationWarning)
-
# import the core of apt_pkg
"""High-Level Interface for working with apt."""
import apt_pkg
diff --git a/apt/deprecation.py b/apt/deprecation.py
index 0f39ad63..cd33a51b 100644
--- a/apt/deprecation.py
+++ b/apt/deprecation.py
@@ -24,6 +24,7 @@ not use it for anything outside the apt package.
"""
import re
import operator
+import os
import warnings
import apt_pkg
@@ -49,12 +50,14 @@ class AttributeDeprecatedBy(object):
"""Issue a DeprecationWarning and return the requested value."""
if obj is None:
return getattr(type_, self.attribute, self)
- warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
return self.getter(obj or type_)
def __set__(self, obj, value):
"""Issue a DeprecationWarning and set the requested value."""
- warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
setattr(obj, self.attribute, value)
@@ -71,7 +74,8 @@ def function_deprecated_by(func, convert_names=True):
def deprecated_function(*args, **kwds):
"""Wrapper around a deprecated function."""
- warnings.warn(warning, DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn(warning, DeprecationWarning, stacklevel=2)
if convert_names:
for key in kwds.keys():
kwds[re.sub('([A-Z])', '_\\1', key).lower()] = kwds.pop(key)
@@ -93,7 +97,8 @@ def deprecated_args(func):
for key in kwds.keys():
new_key = re.sub('([A-Z])', '_\\1', key).lower()
if new_key != key:
- warnings.warn("Deprecated parameter %r" % key)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("Deprecated parameter %r" % key)
kwds[new_key] = kwds.pop(key)
return func(*args, **kwds)
diff --git a/apt/package.py b/apt/package.py
index 0c026504..701872a8 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -120,7 +120,7 @@ class DeprecatedProperty(property):
self.__doc__ = (doc or fget.__doc__ or '')
def __get__(self, obj, type_=None):
- if obj is not None:
+ if obj is not None and "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
warnings.warn("Accessed deprecated property %s.%s, please see the "
"Version class for alternatives." %
((obj.__class__.__name__ or type_.__name__),
diff --git a/apt/progress/old.py b/apt/progress/old.py
index 4bd79f2e..2d3fdb59 100644
--- a/apt/progress/old.py
+++ b/apt/progress/old.py
@@ -42,8 +42,9 @@ class OpProgress(base.OpProgress):
def __init__(self):
base.OpProgress.__init__(self)
- warnings.warn("apt.progress.OpProgress is deprecated.",
- DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("apt.progress.OpProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
subOp = AttributeDeprecatedBy('subop')
Op = AttributeDeprecatedBy('op')
@@ -54,8 +55,9 @@ class OpTextProgress(OpProgress, text.OpProgress):
def __init__(self):
text.OpProgress.__init__(self)
- warnings.warn("apt.progress.OpTextProgress is deprecated.",
- DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("apt.progress.OpTextProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
class FetchProgress(object):
@@ -75,8 +77,9 @@ class FetchProgress(object):
self.totalBytes = 0
self.totalItems = 0
self.currentCPS = 0
- warnings.warn("apt.progress.FetchProgress is deprecated.",
- DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("apt.progress.FetchProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
def start(self):
"""Called when the fetching starts."""
@@ -175,8 +178,9 @@ class CdromProgress(object):
"""Report the cdrom add progress."""
def __init__(self):
- warnings.warn("apt.progress.CdromProgress is deprecated.",
- DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("apt.progress.CdromProgress is deprecated.",
+ DeprecationWarning, stacklevel=2)
def askCdromName(self):
"""Ask for a cdrom name"""
@@ -193,8 +197,9 @@ class DumbInstallProgress(base.InstallProgress):
def __init__(self):
base.InstallProgress.__init__(self)
- warnings.warn("apt.progress.*InstallProgress are deprecated.",
- DeprecationWarning, stacklevel=2)
+ if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
+ warnings.warn("apt.progress.*InstallProgress are deprecated.",
+ DeprecationWarning, stacklevel=2)
def updateInterface(self):
# *_stream were not available in the old progress reporting classes,