Skip to content

Commit 7e48554

Browse files
Daniel Machm-blaha
authored andcommitted
[callback] Bring TransactionDisplay.PKG_* constants back.
TransactionDisplay.PKG_* constants are not an official API, but they are widely used in callbacks. This patch brings them back and prints a deprecation warning to suggest migration to the official API.
1 parent 8a49bf7 commit 7e48554

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

dnf/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#
2020

2121
from __future__ import unicode_literals
22-
from dnf.exceptions import DeprecationWarning
2322
import warnings
2423
import dnf.pycomp
2524

dnf/yum/rpmtrans.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import libdnf.transaction
2121

2222
from dnf.i18n import _, ucd
23+
import dnf.callback
2324
import dnf.transaction
2425
import dnf.util
2526
import rpm
@@ -28,6 +29,7 @@
2829
import sys
2930
import tempfile
3031
import traceback
32+
import warnings
3133

3234

3335
# TODO: merge w/ libdnf
@@ -47,11 +49,39 @@
4749
logger = logging.getLogger('dnf')
4850

4951

52+
def _add_deprecated_action(name):
53+
"""
54+
Wrapper to return a deprecated action constant
55+
while printing a deprecation warning.
56+
"""
57+
@property
58+
def _func(self):
59+
msg = "%s.%s is deprecated. Use dnf.callback.%s instead." \
60+
% (self.__class__.__name__, name, name)
61+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
62+
value = getattr(dnf.callback, name)
63+
return value
64+
return _func
65+
66+
5067
class TransactionDisplay(object):
5168

5269
def __init__(self):
5370
pass
5471

72+
# use constants from dnf.callback which are the official API
73+
PKG_CLEANUP = _add_deprecated_action("PKG_CLEANUP")
74+
PKG_DOWNGRADE = _add_deprecated_action("PKG_DOWNGRADE")
75+
PKG_ERASE = _add_deprecated_action("PKG_ERASE")
76+
PKG_INSTALL = _add_deprecated_action("PKG_INSTALL")
77+
PKG_OBSOLETE = _add_deprecated_action("PKG_OBSOLETE")
78+
PKG_REINSTALL = _add_deprecated_action("PKG_REINSTALL")
79+
PKG_UPGRADE = _add_deprecated_action("PKG_UPGRADE")
80+
PKG_VERIFY = _add_deprecated_action("PKG_VERIFY")
81+
TRANS_PREPARATION = _add_deprecated_action("TRANS_PREPARATION")
82+
PKG_SCRIPTLET = _add_deprecated_action("PKG_SCRIPTLET")
83+
TRANS_POST = _add_deprecated_action("TRANS_POST")
84+
5585
def progress(self, package, action, ti_done, ti_total, ts_done, ts_total):
5686
"""Report ongoing progress on a transaction item. :api
5787

0 commit comments

Comments
 (0)