diff --git a/src/oebuild/command.py b/src/oebuild/command.py index a87abd3623dfc8ad94dd5bb7a457a14ab5ce0b65..ca5593f5513d4520d8756a0f814ab0c7fe65a402 100644 --- a/src/oebuild/command.py +++ b/src/oebuild/command.py @@ -12,7 +12,7 @@ See the Mulan PSL v2 for more details. from abc import ABC, abstractmethod import argparse -import importlib +import importlib.util from collections import OrderedDict import os from dataclasses import dataclass @@ -211,8 +211,10 @@ def _commands_module_from_file(file, mod_name): these modules in an (otherwise unpopulated) oebuild.commands.ext package. ''' - spec = importlib.util.spec_from_file_location(mod_name, file) # type: ignore - mod = importlib.util.module_from_spec(spec) # type: ignore + spec = importlib.util.spec_from_file_location(mod_name, file) + if spec is None: + return None + mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod diff --git a/src/oebuild/m_log.py b/src/oebuild/m_log.py index 2b6137142af9815482dc4c2a2c8b4e219573c387..6ac7737814e16c4d6b4a01cd573ef14ee40801ba 100644 --- a/src/oebuild/m_log.py +++ b/src/oebuild/m_log.py @@ -9,7 +9,7 @@ EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' - +import sys import logging import colorama @@ -25,25 +25,19 @@ WRN_COLOR = colorama.Fore.LIGHTYELLOW_EX #: Color used (when applicable) for printing with err() and die() ERR_COLOR = colorama.Fore.LIGHTRED_EX -# 创建logger对象 logger = logging.getLogger() logger.setLevel(logging.INFO) -# 创建文件处理器 fh = logging.FileHandler('oebuild.log') fh.setLevel(logging.INFO) -# 创建控制台处理器 -ch = logging.StreamHandler() +ch = logging.StreamHandler(stream=sys.stdout) ch.setLevel(logging.INFO) -# 创建格式化器 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') -# 将格式化器添加到文件处理器和控制台处理器 fh.setFormatter(formatter) ch.setFormatter(formatter) -# 将处理器添加到logger对象 logger.addHandler(fh) logger.addHandler(ch) diff --git a/src/oebuild/parse_compile.py b/src/oebuild/parse_compile.py index 385d9524bd712ba03e8a287c1e4ac1b6f8a01ba1..16d46f6a27bbda1105cbd84af047bc21c7571261 100644 --- a/src/oebuild/parse_compile.py +++ b/src/oebuild/parse_compile.py @@ -83,7 +83,7 @@ class ParseCompile: repos=None if "repos" not in data else ParseTemplate.parse_oebuild_repo(data['repos']), local_conf=None if "local_conf" not in data else data['local_conf'], layers=None if "layers" not in data else data['layers'] - ) + ) @property def build_in(self): @@ -205,14 +205,15 @@ class ParseCompile: Check whether the compile.yaml content is compliant ''' - if "platform" not in data: - raise CheckCompileError("the key platform is None") + keys = { + "platform": "the key platform is None", + "machine": "the key machine is None", + "toolchain_type": "the key toolchain_type is None" + } - if "machine" not in data: - raise CheckCompileError("the key machine is None") - - if "toolchain_type" not in data: - raise CheckCompileError("the key toolchain_type is None") + for key, value in keys.items(): + if key not in data: + raise CheckCompileError(value) if "toolchain_dir" in data and data['toolchain_dir'] is not None: if not os.path.exists(data['toolchain_dir']): @@ -220,10 +221,11 @@ class ParseCompile: if "repos" in data: for _, repo in data['repos'].items(): - if "url" not in repo: - raise CheckCompileError("the key url is None") - if "path" not in repo: - raise CheckCompileError("the key path is None") - if "refspec" not in repo: - raise CheckCompileError("the key refspec is None") + required_keys = { + "url": "the key url is None", + "path": "the key path is None", + "refspec": "the key refspec is None"} + for key, value in required_keys.items(): + if key not in repo: + raise CheckCompileError(value) \ No newline at end of file diff --git a/src/oebuild/parse_env.py b/src/oebuild/parse_env.py index 4cb482c8aebf809263819a9565173a8bab9c00d7..2e8e4a796ab76c149357210e4d8918f9973d75cf 100644 --- a/src/oebuild/parse_env.py +++ b/src/oebuild/parse_env.py @@ -10,6 +10,7 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' +from typing import Optional from dataclasses import dataclass import pathlib @@ -24,7 +25,7 @@ class EnvContainer: branch: str - short_id: str or None + short_id: Optional[str] volumns: list @@ -33,7 +34,7 @@ class Env: ''' the env object ''' - container: EnvContainer or None + container: Optional[EnvContainer] class ParseEnv: ''' @@ -42,7 +43,7 @@ class ParseEnv: ''' def __init__(self, env_dir): self.env_dir = pathlib.Path(env_dir) if isinstance(env_dir, str) else env_dir - self.env = Env + self.env:Env = Env(container=None) self._parse_env() @property @@ -82,6 +83,9 @@ class ParseEnv: if data.volumns is None: raise ValueError("the key volumns is lack") + if self.env is None: + return False + if self.env.container is None: return False diff --git a/src/oebuild/version.py b/src/oebuild/version.py index 3723df2a8a8d401982bdffde9129823e69eae17e..81392fe79a5ff3f7577769a60f20dc25d29af4e7 100644 --- a/src/oebuild/version.py +++ b/src/oebuild/version.py @@ -10,4 +10,4 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' -__version__ = '0.0.16' +__version__ = '0.0.18'