From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2BEBE1382C5 for ; Mon, 18 Jan 2021 20:22:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4267CE082B; Mon, 18 Jan 2021 20:22:08 +0000 (UTC) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3CD52E082B for ; Mon, 18 Jan 2021 20:22:08 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id 143so19818958qke.10 for ; Mon, 18 Jan 2021 12:22:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ivvovsy92fQ4Z5ExTM1hNbWY+hHfOEfPGQRzeTdFYhA=; b=IrYBO3dmqi+hKU3rnK5qHYnLh4/LDSQrqYr8Ck1wkxEVfHtmrMh6YkW2zbm890PnLq VFYo4mCplsKyMtQldSefpxSwh+KH/niGUBJuyjAYQnjDLDp37VFAY1cBYQD6+4fURfOu JuGg/tetXO2zylQ9BJErcNmfeigP0FP8lU1aHqP3qYm8soxgCUPEA0366zmmfZvGd4vE KHH5DiiLGGumglws8Zz3qCiXbdPICQrFBvMJ9QXS9Eq771remxA9wt4CyTQQie1XPe95 llYKIPUTubPEd9c8u5UoXO2HI0f0WN++lqV4Qz+nxGXERXQGJY+GEFUaPKSd4BeFYPPk +6yQ== X-Gm-Message-State: AOAM532W+Z+c9T7/fO+lzeUW6EgcQ4dFHSyaQHvKR12cYKT9hmQA9A/3 wm9t537dWAyGrEp11BQtdYxtyKPK8lA= X-Google-Smtp-Source: ABdhPJye9OskF8qAQsSMeIMyQHCWiKdnGWOXMq5ThITA9xXJKju5MYCs/O1H61MWlHwWDEZK7VV9WA== X-Received: by 2002:a05:620a:69c:: with SMTP id f28mr1286831qkh.127.1611001327106; Mon, 18 Jan 2021 12:22:07 -0800 (PST) Received: from localhost ([208.104.103.123]) by smtp.gmail.com with ESMTPSA id h8sm2789983qtm.5.2021.01.18.12.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 12:22:06 -0800 (PST) From: Matt Turner To: gentoo-catalyst@lists.gentoo.org Cc: Matt Turner Subject: [gentoo-catalyst] [PATCH 06/11] catalyst: Store references to functions Date: Mon, 18 Jan 2021 15:21:47 -0500 Message-Id: <20210118202152.374078-6-mattst88@gentoo.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210118202152.374078-1-mattst88@gentoo.org> References: <20210118202152.374078-1-mattst88@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 50528df6-d657-4029-9c2e-faf4930213d2 X-Archives-Hash: 8b9413226f9822113c8647673745a2d9 ... rather than their names. This makes it possible for tooling to understand the code structure better. Signed-off-by: Matt Turner --- 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() -- 2.26.2