Skip to content

Commit

Permalink
[callback] Bring TransactionDisplay.PKG_* constants back.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Daniel Mach authored and m-blaha committed Jun 28, 2018
1 parent 8a49bf7 commit 7e48554
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 0 additions & 1 deletion dnf/__init__.py
Expand Up @@ -19,7 +19,6 @@
#

from __future__ import unicode_literals
from dnf.exceptions import DeprecationWarning
import warnings
import dnf.pycomp

Expand Down
30 changes: 30 additions & 0 deletions dnf/yum/rpmtrans.py
Expand Up @@ -20,6 +20,7 @@
import libdnf.transaction

from dnf.i18n import _, ucd
import dnf.callback
import dnf.transaction
import dnf.util
import rpm
Expand All @@ -28,6 +29,7 @@
import sys
import tempfile
import traceback
import warnings


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


def _add_deprecated_action(name):
"""
Wrapper to return a deprecated action constant
while printing a deprecation warning.
"""
@property
def _func(self):
msg = "%s.%s is deprecated. Use dnf.callback.%s instead." \
% (self.__class__.__name__, name, name)
warnings.warn(msg, DeprecationWarning, stacklevel=2)
value = getattr(dnf.callback, name)
return value
return _func


class TransactionDisplay(object):

def __init__(self):
pass

# use constants from dnf.callback which are the official API
PKG_CLEANUP = _add_deprecated_action("PKG_CLEANUP")
PKG_DOWNGRADE = _add_deprecated_action("PKG_DOWNGRADE")
PKG_ERASE = _add_deprecated_action("PKG_ERASE")
PKG_INSTALL = _add_deprecated_action("PKG_INSTALL")
PKG_OBSOLETE = _add_deprecated_action("PKG_OBSOLETE")
PKG_REINSTALL = _add_deprecated_action("PKG_REINSTALL")
PKG_UPGRADE = _add_deprecated_action("PKG_UPGRADE")
PKG_VERIFY = _add_deprecated_action("PKG_VERIFY")
TRANS_PREPARATION = _add_deprecated_action("TRANS_PREPARATION")
PKG_SCRIPTLET = _add_deprecated_action("PKG_SCRIPTLET")
TRANS_POST = _add_deprecated_action("TRANS_POST")

def progress(self, package, action, ti_done, ti_total, ts_done, ts_total):
"""Report ongoing progress on a transaction item. :api
Expand Down

0 comments on commit 7e48554

Please sign in to comment.