commit:     501529d9d464406db34f10e642ae7b375ccbbe3a
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 17 23:53:21 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 18:01:21 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=501529d9

catalyst: Store references to functions

... rather than their names. This makes it possible for tooling to
understand the code structure better.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py        | 69 ++++++++++++++++++++-------------------
 catalyst/targets/embedded.py      | 34 +++++++++----------
 catalyst/targets/livecd_stage1.py | 18 +++++-----
 catalyst/targets/livecd_stage2.py | 46 +++++++++++++-------------
 catalyst/targets/netboot.py       | 34 +++++++++----------
 catalyst/targets/stage1.py        | 12 +++----
 catalyst/targets/stage4.py        | 36 ++++++++++----------
 7 files changed, 125 insertions(+), 124 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index ed4d1227..447e073d 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -30,6 +30,23 @@ from catalyst.fileops import ensure_dirs, clear_dir, 
clear_path
 from catalyst.base.resume import AutoResume
 
 
+def run_sequence(sequence):
+    for func in sequence:
+        log.notice('--- Running action sequence: %s', func.__name__)
+        sys.stdout.flush()
+        try:
+            func()
+        except LockInUse:
+            log.error('Unable to aquire the lock...')
+            return False
+        except Exception:
+            log.error('Exception running action sequence %s',
+                      func.__name__, exc_info=True)
+            return False
+
+    return True
+
+
 class StageBase(TargetBase, ClearBase, GenBase):
     """
     This class does all of the chroot setup, copying of files, etc. It is
@@ -475,39 +492,39 @@ class StageBase(TargetBase, ClearBase, GenBase):
         Or it calls the normal set_action_sequence() for the target stage.
         """
         if "purgeonly" in self.settings["options"]:
-            self.build_sequence.append("remove_chroot")
+            self.build_sequence.append(self.remove_chroot)
             return
         self.set_action_sequence()
 
     def set_action_sequence(self):
         """Set basic stage1, 2, 3 action sequences"""
         self.prepare_sequence.extend([
-            "unpack",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "run_local",
-            "preclean",
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.run_local,
+            self.preclean,
         ])
         self.finish_sequence.extend([
-            "clean",
+            self.clean,
         ])
         self.set_completion_action_sequences()
 
     def set_completion_action_sequences(self):
         if "fetch" not in self.settings["options"]:
-            self.finish_sequence.append("capture")
+            self.finish_sequence.append(self.capture)
         if "keepwork" in self.settings["options"]:
-            self.finish_sequence.append("clear_autoresume")
+            self.finish_sequence.append(self.clear_autoresume)
         elif "seedcache" in self.settings["options"]:
-            self.finish_sequence.append("remove_autoresume")
+            self.finish_sequence.append(self.remove_autoresume)
         else:
-            self.finish_sequence.append("remove_autoresume")
-            self.finish_sequence.append("remove_chroot")
+            self.finish_sequence.append(self.remove_autoresume)
+            self.finish_sequence.append(self.remove_chroot)
 
     def set_use(self):
         use = self.settings["spec_prefix"] + "/use"
@@ -1308,22 +1325,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
-    def run_sequence(self, sequence):
-        for func in sequence:
-            log.notice('--- Running action sequence: %s', func)
-            sys.stdout.flush()
-            try:
-                getattr(self, func)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                return False
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          func, exc_info=True)
-                return False
-
-        return True
-
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1342,14 +1343,14 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        if not self.run_sequence(self.prepare_sequence):
+        if not run_sequence(self.prepare_sequence):
             return False
 
         with namespace(mount=True):
-            if not self.run_sequence(self.build_sequence):
+            if not run_sequence(self.build_sequence):
                 return False
 
-        if not self.run_sequence(self.finish_sequence):
+        if not run_sequence(self.finish_sequence):
             return False
 
         return True

diff --git a/catalyst/targets/embedded.py b/catalyst/targets/embedded.py
index 918b36bf..7d328808 100644
--- a/catalyst/targets/embedded.py
+++ b/catalyst/targets/embedded.py
@@ -42,27 +42,27 @@ class embedded(StageBase):
 
     def set_action_sequence(self):
         self.prepare_sequence.extend([
-            "unpack",
-            "config_profile_link",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.config_profile_link,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "build_kernel",
-            "build_packages",
-            "root_overlay",
-            "fsscript",
-            "unmerge",
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.build_kernel,
+            self.build_packages,
+            self.root_overlay,
+            self.fsscript,
+            self.unmerge,
         ])
         self.finish_sequence.extend([
-            "remove",
-            "empty",
-            "clean",
-            "capture",
-            "clear_autoresume",
+            self.remove,
+            self.empty,
+            self.clean,
+            self.capture,
+            self.clear_autoresume,
         ])
 
     def set_root_path(self):

diff --git a/catalyst/targets/livecd_stage1.py 
b/catalyst/targets/livecd_stage1.py
index 5c5e9f58..eb6bb0f0 100644
--- a/catalyst/targets/livecd_stage1.py
+++ b/catalyst/targets/livecd_stage1.py
@@ -24,19 +24,19 @@ class livecd_stage1(StageBase):
 
     def set_action_sequence(self):
         self.prepare_sequence.extend([
-            "unpack",
-            "config_profile_link",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.config_profile_link,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "build_packages",
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.build_packages,
         ])
         self.finish_sequence.extend([
-            "clean",
+            self.clean,
         ])
         self.set_completion_action_sequences()
 

diff --git a/catalyst/targets/livecd_stage2.py 
b/catalyst/targets/livecd_stage2.py
index 3606047f..5fecff85 100644
--- a/catalyst/targets/livecd_stage2.py
+++ b/catalyst/targets/livecd_stage2.py
@@ -87,34 +87,34 @@ class livecd_stage2(StageBase):
 
     def set_action_sequence(self):
         self.prepare_sequence.extend([
-            "unpack",
-            "config_profile_link",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.config_profile_link,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "run_local",
-            "build_kernel"
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.run_local,
+            self.build_kernel
         ])
         if "fetch" not in self.settings["options"]:
             self.build_sequence.extend([
-                "bootloader",
-                "preclean",
-                "livecd_update",
-                "root_overlay",
-                "fsscript",
-                "rcupdate",
-                "unmerge",
+                self.bootloader,
+                self.preclean,
+                self.livecd_update,
+                self.root_overlay,
+                self.fsscript,
+                self.rcupdate,
+                self.unmerge,
             ])
             self.finish_sequence.extend([
-                "remove",
-                "empty",
-                "clean",
-                "target_setup",
-                "setup_overlay",
-                "create_iso",
+                self.remove,
+                self.empty,
+                self.clean,
+                self.target_setup,
+                self.setup_overlay,
+                self.create_iso,
             ])
-        self.finish_sequence.append("clear_autoresume")
+        self.finish_sequence.append(self.clear_autoresume)

diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py
index 55f4dff1..9a7e59e5 100644
--- a/catalyst/targets/netboot.py
+++ b/catalyst/targets/netboot.py
@@ -159,25 +159,25 @@ class netboot(StageBase):
 
     def set_action_sequence(self):
         self.prepare_sequence.extend([
-            "unpack",
-            "config_profile_link",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.config_profile_link,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "build_packages",
-            "root_overlay",
-            "copy_files_to_image",
-            "setup_overlay",
-            "build_kernel",
-            "move_kernels",
-            "remove",
-            "empty",
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.build_packages,
+            self.root_overlay,
+            self.copy_files_to_image,
+            self.setup_overlay,
+            self.build_kernel,
+            self.move_kernels,
+            self.remove,
+            self.empty,
         ])
         self.finish_sequence.extend([
-            "clean",
-            "clear_autoresume",
+            self.clean,
+            self.clear_autoresume,
         ])

diff --git a/catalyst/targets/stage1.py b/catalyst/targets/stage1.py
index 5aa27bb9..5a154e76 100644
--- a/catalyst/targets/stage1.py
+++ b/catalyst/targets/stage1.py
@@ -82,15 +82,15 @@ class stage1(StageBase):
         chroot for re-use in stage2 without the need to unpack it.
         '''
         if "fetch" not in self.settings["options"]:
-            self.finish_sequence.append("capture")
+            self.finish_sequence.append(self.capture)
         if "keepwork" in self.settings["options"]:
-            self.finish_sequence.append("clear_autoresume")
+            self.finish_sequence.append(self.clear_autoresume)
         elif "seedcache" in self.settings["options"]:
-            self.finish_sequence.append("remove_autoresume")
-            self.finish_sequence.append("clean_stage1")
+            self.finish_sequence.append(self.remove_autoresume)
+            self.finish_sequence.append(self.clean_stage1)
         else:
-            self.finish_sequence.append("remove_autoresume")
-            self.finish_sequence.append("remove_chroot")
+            self.finish_sequence.append(self.remove_autoresume)
+            self.finish_sequence.append(self.remove_chroot)
 
     def clean_stage1(self):
         '''seedcache is enabled, so salvage the /tmp/stage1root,

diff --git a/catalyst/targets/stage4.py b/catalyst/targets/stage4.py
index b7f74b01..997139a5 100644
--- a/catalyst/targets/stage4.py
+++ b/catalyst/targets/stage4.py
@@ -40,27 +40,27 @@ class stage4(StageBase):
 
     def set_action_sequence(self):
         self.prepare_sequence.extend([
-            "unpack",
-            "config_profile_link",
-            "setup_confdir",
-            "portage_overlay",
+            self.unpack,
+            self.config_profile_link,
+            self.setup_confdir,
+            self.portage_overlay,
         ])
         self.build_sequence.extend([
-            "bind",
-            "chroot_setup",
-            "setup_environment",
-            "build_packages",
-            "build_kernel",
-            "bootloader",
-            "root_overlay",
-            "fsscript",
-            "preclean",
-            "rcupdate",
-            "unmerge",
+            self.bind,
+            self.chroot_setup,
+            self.setup_environment,
+            self.build_packages,
+            self.build_kernel,
+            self.bootloader,
+            self.root_overlay,
+            self.fsscript,
+            self.preclean,
+            self.rcupdate,
+            self.unmerge,
         ])
         self.finish_sequence.extend([
-            "remove",
-            "empty",
-            "clean",
+            self.remove,
+            self.empty,
+            self.clean,
         ])
         self.set_completion_action_sequences()

Reply via email to