#12 drop legacy code
Merged 4 years ago by till. Opened 4 years ago by kparal.

file modified
+17 -68
@@ -16,8 +16,6 @@ 

  # You should have received a copy of the GNU General Public License

  # along with fedora-easy-karma.  If not, see <http://www.gnu.org/licenses/>.

  

- from __future__ import print_function

- 

  # default python modules

  import pickle

  import datetime
@@ -33,10 +31,11 @@ 

  from textwrap import wrap

  

  # extra python modules

+ from bodhi.client.bindings import BodhiClient

+ import dnf

  # Used to catch fedora.client.AuthError and fedora.client.ServerError

  # exceptions

  import fedora

- 

  # fedora_cert is optional. It is only used to get the real fas_username, which

  # is also supplied as a command line option and eventually in a config file.

  try:
@@ -44,37 +43,9 @@ 

  except ImportError:

      pass

  

- try:

-     import dnf

- except ImportError:

-     dnf = None

-     import yum

- 

- # Use newer Bodhi bindings when available

- # As of 2017-08-29 they are in Fedora 26+ and EPEL7+

- # FIXME: Only use the newer bindings when EPEL6 and Fedora 25 are EOL

- try:

-     from bodhi.client.bindings import BodhiClient

- except ImportError:

-     from fedora.client.bodhi import BodhiClient

- 

  PROMPT = "Comment? -1/0/1 -> karma, 'i' -> ignore, other -> skip> "

  

  

- # Use Python 2 names of things

- try:

-     basestring

- except NameError:

-     # Python 3 -- unicode strings only

-     basestring = str

- 

- try:

-     raw_input

- except NameError:

-     # Python 3 -- raw_input() was renamed to input()

-     raw_input = input

- 

- 

  class FEK_helper(object):

      @staticmethod

      def bodhi_update_str(
@@ -242,7 +213,7 @@ 

      @staticmethod

      def wrap_paragraphs_prefix(paragraphs, first_prefix, width=80,

                                 extra_newline=False):

-         if isinstance(paragraphs, basestring):

+         if isinstance(paragraphs, str):

              paragraphs = paragraphs.split("\n")

  

          if first_prefix:
@@ -304,37 +275,16 @@ 

  

  class PkgHelper(object):

      def __init__(self):

-         if dnf is not None:

-             self.my = dnf.Base()

-             # if not dnf.util.am_i_root():

-             #     cachedir = dnf.yum.misc.getCacheDir()

-             #     my.conf.cachedir = cachedir

-             self.my.fill_sack()

-             self.releasever = dnf.rpm.detect_releasever("/")

-             self.package_manager = 'dnf'

-             # make pkg objects subscriptable, i.e. pkg["name"] work

-             dnf.package.Package.__getitem__ = lambda self, key: \

-                 getattr(self, key)

-         else:

-             self.my = yum.YumBase()

-             self.my.preconf.debuglevel = 0

- 

-             self.releasever = self.my.conf.yumvar["releasever"]

-             if not self.releasever.isdigit():

-                 self.releasever = re.match('^(\d+)',

-                                            self.releasever).groups(1)[0]

-             self.package_manager = 'yum'

- 

-             # make pkg objects subscriptable, i.e. pkg["name"] work

-             yum.rpmsack.RPMInstalledPackage.__getitem__ = lambda self, key: \

-                 getattr(self, key)

+         self.my = dnf.Base()

+         self.my.fill_sack()

+         self.releasever = dnf.rpm.detect_releasever("/")

+         # make pkg objects subscriptable, i.e. pkg["name"] work

+         dnf.package.Package.__getitem__ = lambda self, key: \

+             getattr(self, key)

  

      @property

      def installed_packages(self):

-         if dnf is not None:

-             return self.my.sack.query().installed()

-         else:

-             return self.my.rpmdb.returnPackages()

+         return self.my.sack.query().installed()

  

  

  class FedoraEasyKarma(object):
@@ -457,7 +407,7 @@ 

                            "--releasever",

                            dest="releasever",

                            help="releasever to query Bodhi for, "

-                                "default: releasever from dnf or yum",

+                                "default: releasever from dnf",

                            default=None)

          parser.add_option("",

                            "--retries",
@@ -551,7 +501,7 @@ 

              self.options.installed_min_days)

  

          self.info("Getting list of installed packages...")

-         self.debug("starting %s query" % pkghelper.package_manager)

+         self.debug("starting dnf query")

          for pkg in pkghelper.installed_packages:

              installed = datetime.datetime.fromtimestamp(pkg.installtime)

              installed_timedelta = now - installed
@@ -637,8 +587,7 @@ 

  

          if not builds:

              print("No testing packages found, install some with: "\

-                 "'%s update --enablerepo=\"*-testing\"'" % \

-                 pkghelper.package_manager)

+                 "'dnf update --enablerepo=\"*-testing\"'")

          for build in builds:

              update = testing_builds[build]

  
@@ -698,11 +647,11 @@ 

                                                self.options.fas_username):

                          print("!!! already commented by you !!!")

                      try:

-                         karma = self.raw_input(

+                         karma = self.input(

                              PROMPT, default=self.options.default_karma,

                              add_to_history=False)

                          if karma in ["-1", "0", "1"]:

-                             comment = self.raw_input(

+                             comment = self.input(

                                  "Comment> ",

                                  default=self.options.default_comment)

                              if comment or not self.options.skip_empty_comment:
@@ -808,14 +757,14 @@ 

      def warning(self, message):

          sys.stderr.write("Warning: %s\n" % message)

  

-     def raw_input(self, prompt, default="", add_to_history=True):

+     def input(self, prompt, default="", add_to_history=True):

          def pre_input_hook():

              readline.insert_text(default)

              readline.redisplay()

  

          readline.set_pre_input_hook(pre_input_hook)

          try:

-             return raw_input(prompt)

+             return input(prompt)

          finally:

              readline.set_pre_input_hook(None)

              if not add_to_history:

This removes Python2-related code, yum-related code and old Bodhi
imports. None of that is required anymore on currently supported
systems.


Please note this probably removes support for RHEL 6 (which is EOL next year). However, RHEL 6 and 7 currently contain a very old and broken version of FEK and RHEL 8 doesn't contain any version. That suggests that RHEL support isn't a high priority for FEK. This change shouldn't prevent FEK from targetting RHEL 7 and 8, because they both contain a recent enough Python3 and dnf.

@till, is this an OK change? I really want to drop legacy code before we start working on improvements.

Pull-Request has been merged by till

4 years ago
Metadata