[v2,22/26] package_manager: Rename Indexer classes

Submitted by Fredrik Gustafsson on June 25, 2020, 10:21 a.m. | Patch ID: 173908

Details

Message ID 20200625102145.7139-23-fredrigu@axis.com
State New
Headers show

Commit Message

Fredrik Gustafsson June 25, 2020, 10:21 a.m.
Rename all *Indexer classeds to PkgIndexer to enable dynamic calling.

Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
---
 meta/lib/oe/package_manager.py                | 22 +++++--------------
 .../package_managers/deb/package_manager.py   |  8 +++++--
 .../package_managers/ipk/package_manager.py   |  7 ++++--
 .../package_managers/rpm/package_manager.py   |  5 ++++-
 4 files changed, 20 insertions(+), 22 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 111845d903..bfddbce93c 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -149,8 +149,6 @@  class Indexer(object, metaclass=ABCMeta):
     def write_index(self):
         pass
 
-
-
 class PkgsList(object, metaclass=ABCMeta):
     def __init__(self, d, rootfs_dir):
         self.d = d
@@ -576,22 +574,12 @@  def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencie
                         raise
 
 def generate_index_files(d):
-    classes = d.getVar('PACKAGE_CLASSES').replace("package_", "").split()
-
-    indexer_map = {
-        "rpm": (RpmSubdirIndexer, d.getVar('DEPLOY_DIR_RPM')),
-        "ipk": (OpkgIndexer, d.getVar('DEPLOY_DIR_IPK')),
-        "deb": (DpkgIndexer, d.getVar('DEPLOY_DIR_DEB'))
-    }
-
+    classes = d.getVar('PACKAGE_CLASSES').split()
     result = None
 
     for pkg_class in classes:
-        if not pkg_class in indexer_map:
-            continue
-
-        if os.path.exists(indexer_map[pkg_class][1]):
-            result = indexer_map[pkg_class][0](d, indexer_map[pkg_class][1]).write_index()
+        import importlib
+        result = importlib.import_module('oe.package_managers.' + classes + '.manifest').PkgIndexer(d).write_index()
 
-            if result is not None:
-                bb.fatal(result)
+        if result is not None:
+            bb.fatal(result)
diff --git a/meta/lib/oe/package_managers/deb/package_manager.py b/meta/lib/oe/package_managers/deb/package_manager.py
index 5d3c300700..0dc4004f66 100644
--- a/meta/lib/oe/package_managers/deb/package_manager.py
+++ b/meta/lib/oe/package_managers/deb/package_manager.py
@@ -94,7 +94,7 @@  class PkgPM(OpkgDpkgPM):
 
         self._create_configs(archs, base_archs)
 
-        self.indexer = DpkgIndexer(self.d, self.deploy_dir)
+        self.indexer = PkgIndexer(self.d, self.deploy_dir)
 
     def mark_packages(self, status_tag, packages=None):
         """
@@ -400,7 +400,7 @@  class PkgPM(OpkgDpkgPM):
         return tmp_dir
 
 
-class DpkgIndexer(Indexer):
+class PkgIndexer(Indexer):
     def _create_configs(self):
         bb.utils.mkdirhier(self.apt_conf_dir)
         bb.utils.mkdirhier(os.path.join(self.apt_conf_dir, "lists", "partial"))
@@ -423,6 +423,10 @@  class DpkgIndexer(Indexer):
                     apt_conf.write(line + "\n")
 
     def write_index(self):
+        if self.deploy_dir == "":
+            self.deploy_dir = self.d.getVar('DEPLOY_DIR_DEB')
+
+
         self.apt_conf_dir = os.path.join(self.d.expand("${APTCONF_TARGET}"),
                 "apt-ftparchive")
         self.apt_conf_file = os.path.join(self.apt_conf_dir, "apt.conf")
diff --git a/meta/lib/oe/package_managers/ipk/package_manager.py b/meta/lib/oe/package_managers/ipk/package_manager.py
index 8abc6c1c98..133af27182 100644
--- a/meta/lib/oe/package_managers/ipk/package_manager.py
+++ b/meta/lib/oe/package_managers/ipk/package_manager.py
@@ -106,7 +106,7 @@  class PkgPM(OpkgDpkgPM):
         else:
             self._create_config()
 
-        self.indexer = OpkgIndexer(self.d, self.deploy_dir)
+        self.indexer = PkgIndexer(self.d, self.deploy_dir)
 
     def mark_packages(self, status_tag, packages=None):
         """
@@ -423,8 +423,11 @@  class PkgPM(OpkgDpkgPM):
 
         return tmp_dir
 
-class OpkgIndexer(Indexer):
+class PkgIndexer(Indexer):
     def write_index(self):
+        if self.deploy_dir == "":
+            self.deploy_dir = self.d.getVar('DEPLOY_DIR_IPK')
+
         arch_vars = ["ALL_MULTILIB_PACKAGE_ARCHS",
                      "SDK_PACKAGE_ARCHS",
                      ]
diff --git a/meta/lib/oe/package_managers/rpm/package_manager.py b/meta/lib/oe/package_managers/rpm/package_manager.py
index 025e8cdfd2..e781676183 100644
--- a/meta/lib/oe/package_managers/rpm/package_manager.py
+++ b/meta/lib/oe/package_managers/rpm/package_manager.py
@@ -384,8 +384,11 @@  class RpmIndexer(Indexer):
                                self.d.getVar('PACKAGE_FEED_GPG_PASSPHRASE_FILE'),
                                armor=is_ascii_sig)
 
-class RpmSubdirIndexer(RpmIndexer):
+class PkgIndexer(RpmIndexer):
     def write_index(self):
+        if self.deploy_dir == "":
+            self.deploy_dir = self.d.getVar('DEPLOY_DIR_RPM')
+
         bb.note("Generating package index for %s" %(self.deploy_dir))
         self.do_write_index(self.deploy_dir)
         for entry in os.walk(self.deploy_dir):

Comments

Paul Barker June 25, 2020, 10:42 a.m.
On Thu, 25 Jun 2020 at 11:22, Fredrik Gustafsson
<fredrik.gustafsson@axis.com> wrote:
>
> Rename all *Indexer classeds to PkgIndexer to enable dynamic calling.

Typo: classes.

>
> Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
> ---
>  meta/lib/oe/package_manager.py                | 22 +++++--------------
>  .../package_managers/deb/package_manager.py   |  8 +++++--
>  .../package_managers/ipk/package_manager.py   |  7 ++++--
>  .../package_managers/rpm/package_manager.py   |  5 ++++-
>  4 files changed, 20 insertions(+), 22 deletions(-)
>
> diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
> index 111845d903..bfddbce93c 100644
> --- a/meta/lib/oe/package_manager.py
> +++ b/meta/lib/oe/package_manager.py
> @@ -149,8 +149,6 @@ class Indexer(object, metaclass=ABCMeta):
>      def write_index(self):
>          pass
>
> -
> -
>  class PkgsList(object, metaclass=ABCMeta):
>      def __init__(self, d, rootfs_dir):
>          self.d = d
> @@ -576,22 +574,12 @@ def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencie
>                          raise
>
>  def generate_index_files(d):
> -    classes = d.getVar('PACKAGE_CLASSES').replace("package_", "").split()
> -
> -    indexer_map = {
> -        "rpm": (RpmSubdirIndexer, d.getVar('DEPLOY_DIR_RPM')),
> -        "ipk": (OpkgIndexer, d.getVar('DEPLOY_DIR_IPK')),
> -        "deb": (DpkgIndexer, d.getVar('DEPLOY_DIR_DEB'))
> -    }
> -
> +    classes = d.getVar('PACKAGE_CLASSES').split()
>      result = None
>
>      for pkg_class in classes:
> -        if not pkg_class in indexer_map:
> -            continue
> -
> -        if os.path.exists(indexer_map[pkg_class][1]):
> -            result = indexer_map[pkg_class][0](d, indexer_map[pkg_class][1]).write_index()
> +        import importlib
> +        result = importlib.import_module('oe.package_managers.' + classes + '.manifest').PkgIndexer(d).write_index()
>
> -            if result is not None:
> -                bb.fatal(result)
> +        if result is not None:
> +            bb.fatal(result)
> diff --git a/meta/lib/oe/package_managers/deb/package_manager.py b/meta/lib/oe/package_managers/deb/package_manager.py
> index 5d3c300700..0dc4004f66 100644
> --- a/meta/lib/oe/package_managers/deb/package_manager.py
> +++ b/meta/lib/oe/package_managers/deb/package_manager.py
> @@ -94,7 +94,7 @@ class PkgPM(OpkgDpkgPM):
>
>          self._create_configs(archs, base_archs)
>
> -        self.indexer = DpkgIndexer(self.d, self.deploy_dir)
> +        self.indexer = PkgIndexer(self.d, self.deploy_dir)
>
>      def mark_packages(self, status_tag, packages=None):
>          """
> @@ -400,7 +400,7 @@ class PkgPM(OpkgDpkgPM):
>          return tmp_dir
>
>
> -class DpkgIndexer(Indexer):
> +class PkgIndexer(Indexer):
>      def _create_configs(self):
>          bb.utils.mkdirhier(self.apt_conf_dir)
>          bb.utils.mkdirhier(os.path.join(self.apt_conf_dir, "lists", "partial"))
> @@ -423,6 +423,10 @@ class DpkgIndexer(Indexer):
>                      apt_conf.write(line + "\n")
>
>      def write_index(self):
> +        if self.deploy_dir == "":
> +            self.deploy_dir = self.d.getVar('DEPLOY_DIR_DEB')
> +
> +
>          self.apt_conf_dir = os.path.join(self.d.expand("${APTCONF_TARGET}"),
>                  "apt-ftparchive")
>          self.apt_conf_file = os.path.join(self.apt_conf_dir, "apt.conf")
> diff --git a/meta/lib/oe/package_managers/ipk/package_manager.py b/meta/lib/oe/package_managers/ipk/package_manager.py
> index 8abc6c1c98..133af27182 100644
> --- a/meta/lib/oe/package_managers/ipk/package_manager.py
> +++ b/meta/lib/oe/package_managers/ipk/package_manager.py
> @@ -106,7 +106,7 @@ class PkgPM(OpkgDpkgPM):
>          else:
>              self._create_config()
>
> -        self.indexer = OpkgIndexer(self.d, self.deploy_dir)
> +        self.indexer = PkgIndexer(self.d, self.deploy_dir)
>
>      def mark_packages(self, status_tag, packages=None):
>          """
> @@ -423,8 +423,11 @@ class PkgPM(OpkgDpkgPM):
>
>          return tmp_dir
>
> -class OpkgIndexer(Indexer):
> +class PkgIndexer(Indexer):
>      def write_index(self):
> +        if self.deploy_dir == "":
> +            self.deploy_dir = self.d.getVar('DEPLOY_DIR_IPK')
> +
>          arch_vars = ["ALL_MULTILIB_PACKAGE_ARCHS",
>                       "SDK_PACKAGE_ARCHS",
>                       ]
> diff --git a/meta/lib/oe/package_managers/rpm/package_manager.py b/meta/lib/oe/package_managers/rpm/package_manager.py
> index 025e8cdfd2..e781676183 100644
> --- a/meta/lib/oe/package_managers/rpm/package_manager.py
> +++ b/meta/lib/oe/package_managers/rpm/package_manager.py
> @@ -384,8 +384,11 @@ class RpmIndexer(Indexer):
>                                 self.d.getVar('PACKAGE_FEED_GPG_PASSPHRASE_FILE'),
>                                 armor=is_ascii_sig)
>
> -class RpmSubdirIndexer(RpmIndexer):
> +class PkgIndexer(RpmIndexer):
>      def write_index(self):
> +        if self.deploy_dir == "":
> +            self.deploy_dir = self.d.getVar('DEPLOY_DIR_RPM')
> +
>          bb.note("Generating package index for %s" %(self.deploy_dir))
>          self.do_write_index(self.deploy_dir)
>          for entry in os.walk(self.deploy_dir):

As per previous comments, let's delay this for a later series. Also
please keep whitespace changes separate from functional changes.


--
Paul Barker
Konsulko Group
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#139946): https://lists.openembedded.org/g/openembedded-core/message/139946
Mute This Topic: https://lists.openembedded.org/mt/75100016/3617530
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  [oe-patchwork@oe-patch.openembedded.org]
-=-=-=-=-=-=-=-=-=-=-=-