From 2d5ec8edad07b77a5323d686a4ca26c0945f3e99 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 28 May 2020 15:42:51 +0200 Subject: [PATCH] meta: extract module class to dir mapping Make the mapping of module class to the corresponding directory a method of the ModuleInfo class. This is so it can be re-used by others in the future. --- osbuild/meta.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/osbuild/meta.py b/osbuild/meta.py index 3b4a7616..9baa320d 100644 --- a/osbuild/meta.py +++ b/osbuild/meta.py @@ -326,16 +326,10 @@ class ModuleInfo: def targets(a): return [t.id for t in filter_type(a.targets, ast.Name)] - mapping = { - "Stage": "stages", - "Assembler": "assemblers" - } - - if klass not in mapping: + base = cls.module_class_to_directory(klass) + if not base: raise ValueError(f"Unsupported type: {klass}") - base = mapping[klass] - path = os.path.join(root, base, name) try: with open(path) as f: @@ -349,6 +343,15 @@ class ModuleInfo: info = {k: value(v) for k, v in targets if k in names} return cls(klass, name, info) + @staticmethod + def module_class_to_directory(klass: str) -> str: + mapping = { + "Stage": "stages", + "Assembler": "assemblers" + } + + return mapping.get(klass) + class Index: """Index of stages and assemblers