diff options
| author | Shyamnath Premnadh <shyamnath.premnadh@qt.io> | 2023-04-04 16:18:47 +0200 |
|---|---|---|
| committer | Shyamnath Premnadh <shyamnath.premnadh@qt.io> | 2023-04-17 11:12:55 +0200 |
| commit | 0e40c7af91df19a2ac20d88b55d4ef4d71845c55 (patch) | |
| tree | b1002ad68cba00384ea0ee5c390c088ea630afe1 /sources/pyside-tools/deploy_lib/config.py | |
| parent | b80c7822c61b70d9704b42db64db0d9637fa7079 (diff) | |
Deployment: Refactoring
- Fix --dry-run in Android deployment
- Add option to control raising a warning when adding new entries
to config file
- Remove unnecessary code and comments
Pick-to: 6.5
Task-number: PYSIDE-1612
Change-Id: I5975d76024d6289fe6b9af1caeca374acb81e8cc
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/config.py')
| -rw-r--r-- | sources/pyside-tools/deploy_lib/config.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index 781c2155d..af019a093 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -4,7 +4,6 @@ from pathlib import Path import configparser from configparser import ConfigParser -import shutil import logging from project import ProjectData @@ -17,17 +16,11 @@ EXCLUDED_QML_PLUGINS = {"QtQuick", "QtQuick3D", "QtCharts", "QtWebEngine", "QtTe class BaseConfig: - def __init__(self, config_file: Path, dry_run: bool, comment_prefixes: str = "/") -> None: + def __init__(self, config_file: Path, comment_prefixes: str = "/") -> None: self.config_file = config_file self.parser = ConfigParser(comment_prefixes=comment_prefixes, allow_no_value=True) - if not self.config_file.exists(): - if not dry_run: - logging.info(f"[DEPLOY] Creating config file {self.config_file}") - shutil.copy(Path(__file__).parent / "default.spec", self.config_file) - else: - self.config_file = Path(__file__).parent / "default.spec" - else: - logging.info(f"Using existing config file {config_file}") + if not config_file.exists(): + raise RuntimeError(f"[DEPLOY] {config_file} does not exist") self.parser.read(self.config_file) def update_config(self): @@ -35,15 +28,17 @@ class BaseConfig: with open(self.config_file, "w+") as config_file: self.parser.write(config_file, space_around_delimiters=True) - def set_value(self, section: str, key: str, new_value: str): + def set_value(self, section: str, key: str, new_value: str, raise_warning: bool = True): try: current_value = self.get_value(section, key, ignore_fail=True) if current_value != new_value: self.parser.set(section, key, new_value) except configparser.NoOptionError: - logging.warning(f"[DEPLOY] Key {key} does not exist") + if raise_warning: + logging.warning(f"[DEPLOY] Key {key} does not exist") except configparser.NoSectionError: - logging.warning(f"[DEPLOY] Section {section} does not exist") + if raise_warning: + logging.warning(f"[DEPLOY] Section {section} does not exist") def get_value(self, section: str, key: str, ignore_fail: bool = False): try: @@ -64,7 +59,7 @@ class Config(BaseConfig): def __init__(self, config_file: Path, source_file: Path, python_exe: Path, dry_run: bool, android_data, is_android: bool): - super().__init__(config_file, dry_run) + super().__init__(config_file) self._dry_run = dry_run # set source_file |
