Uploaded image for project: 'Community Linux Engineering'
  1. Community Linux Engineering
  2. CLE-574

Refactor PkgHelper to avoid modifying global DNF package behavior

    • rhel-cle-nexus

          1. Problem

      Currently, fedora-easy-karma uses a PkgHelper class that modifies the global behavior of the `dnf.package.Package` class by dynamically injecting a `_getitem_` method:

      ```
      dnf.package.Package._getitem_ = lambda self, key: getattr(self, key)
      ```

      This practice is dangerous and can lead to unexpected side effects elsewhere in the application or any libraries using DNF.

          1. Possible solution

      Refactor PkgHelper into a new design that wraps the `dnf.package.Package` object in a safe local wrapper class.

      The wrapper should:

      • provide the same convenience (pkg["name"] and pkg.name both work),
      • avoid modifying any DNF internal objects globally.

      `PackageWrapper` will be a small wrapper class that proxies both attribute access and index access to the underlying dnf.package.Package instance.

      `Packages`: the `PkgHelper` will be renamed so that the name tells more about what we can expext from this class. It will stay the same, but will use the `PackageWrapper` to enable the previous functionality.

              lruzicka@redhat.com Lukas Ruzicka
              cle_bot CLE bot
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: