diff options
author | Philipp Hörist <philipp@hoerist.com> | 2022-12-04 02:41:11 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2022-12-04 02:41:11 +0300 |
commit | 3d5363d060ddb5fbf9814e9bed4800f0dfee8a7e (patch) | |
tree | 69f5c576b982ed5ee477d71e53bd95dbff587a29 /.ci | |
parent | 2bbcd18bbe9609d8155c5988076aa4004b69e6cb (diff) |
refactor: Scripts: Fix various issues
- Use logging module everywhere
- Fix boolean traps
- replace exit() with sys.exit()
Diffstat (limited to '.ci')
-rw-r--r-- | .ci/appveyor_build.py | 25 | ||||
-rw-r--r-- | .ci/deploy.py | 18 | ||||
-rwxr-xr-x | .ci/link-gtk.py | 11 |
3 files changed, 32 insertions, 22 deletions
diff --git a/.ci/appveyor_build.py b/.ci/appveyor_build.py index 5ab2750b0..64a7002d7 100644 --- a/.ci/appveyor_build.py +++ b/.ci/appveyor_build.py @@ -2,14 +2,14 @@ from typing import Any +import logging import json import os import requests +import sys import time from pathlib import Path -from rich.console import Console - ACCOUNT = 'lovetox' PROJECT_SLUG = 'gajim' @@ -25,7 +25,8 @@ BUILDS_API_URL = f'{BASE_URL}/builds' PROJECT_API_URL = f'{BASE_URL}/projects/{ACCOUNT}/{PROJECT_SLUG}' -console = Console() +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() def get_gajim_version() -> str: @@ -34,13 +35,13 @@ def get_gajim_version() -> str: tag = os.environ.get('CI_COMMIT_TAG') if tag is None: - exit('No tag found') + sys.exit('No tag found') return tag def push_yaml_to_project() -> None: - console.print('Push settings ...') - with open('.ci/appveyor.yml', 'r') as file: + log.info('Push settings ...') + with open('.ci/appveyor.yml') as file: yaml = file.read() req = requests.put(SETTINGS_API_URL, data=yaml, headers=HEADERS) @@ -48,7 +49,7 @@ def push_yaml_to_project() -> None: def start_build() -> str: - console.print('Start build ...') + log.info('Start build ...') payload = { 'accountName': ACCOUNT, 'projectSlug': PROJECT_SLUG, @@ -66,7 +67,7 @@ def start_build() -> str: def is_build_finished(build: dict[str, str]) -> bool: if build['status'] in ('failed', 'cancelled'): - exit('Found failed job') + sys.exit('Found failed job') return build['status'] == 'success' @@ -76,18 +77,18 @@ def check_for_response(build_id: str) -> None: while True: time.sleep(RETRY_TIMEOUT) - console.print('Check build status ...') + log.info('Check build status ...') req = requests.get(PROJECT_API_URL, headers=HEADERS) req.raise_for_status() response = req.json() build = response['build'] if build_id != build['buildId']: - exit('Unable to find buildid: %s' % build_id) + sys.exit('Unable to find buildid: %s' % build_id) if is_build_finished(build): break - console.print('Build status:', build['status']) + log.info('Build status: %s', build['status']) build_folder = Path.cwd() / 'build' build_folder.mkdir() @@ -96,7 +97,7 @@ def check_for_response(build_id: str) -> None: response = get_job_response(job['jobId']) result = build_folder / f'{job["jobId"]}.json' result.write_text(json.dumps(response)) - console.print('Write job response:', result) + log.info('Write job response: %s', result) def get_job_response(job_id: str) -> list[dict[str, Any]]: diff --git a/.ci/deploy.py b/.ci/deploy.py index bc3d4afcb..96683bfdc 100644 --- a/.ci/deploy.py +++ b/.ci/deploy.py @@ -4,6 +4,7 @@ from typing import Any from typing import Optional import functools +import logging import json import os import sys @@ -12,7 +13,6 @@ from ftplib import FTP_TLS from pathlib import Path import requests -from rich.console import Console FTP_URL = 'panoramix.gajim.org' @@ -27,17 +27,19 @@ LINUX_NIGHTLY_FOLDER = 'downloads/snap' RELEASE_FOLDER_BASE = 'downloads' -console = Console() + +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() def ftp_connection(func: Any) -> Any: @functools.wraps(func) def func_wrapper(filedir: Path) -> None: ftp = FTP_TLS(FTP_URL, FTP_USER, FTP_PASS) - console.print('Successfully connected to', FTP_URL) + log.info('Successfully connected to %s', FTP_URL) func(ftp, filedir) ftp.quit() - console.print('Quit') + log.info('Quit') return return func_wrapper @@ -50,14 +52,14 @@ def get_release_folder_from_tag(tag: str) -> str: def get_gajim_tag() -> str: tag = os.environ.get('CI_COMMIT_TAG') if tag is None: - exit('No tag found') + sys.exit('No tag found') return tag def find_linux_tarball(filedir: Path) -> Path: files = list(filedir.glob('gajim-*.tar.gz')) if len(files) != 1: - exit('Unknown files found') + sys.exit('Unknown files found') return files[0] @@ -86,7 +88,7 @@ def upload_file(ftp: FTP_TLS, if name is None: name = filepath.name - console.print('Upload file', filepath.name, 'as', name) + log.info('Upload file %s as %s', filepath.name, name) with open(filepath, 'rb') as f: ftp.storbinary('STOR ' + name, f) @@ -103,7 +105,7 @@ def download_artifacts(path: Path) -> None: filename = artifact['fileName'] file_url = artifact['fileUrl'] - console.print('Download', filename, '...') + log.info('Download %s', filename) req = requests.get(file_url, headers=HEADERS) req.raise_for_status() diff --git a/.ci/link-gtk.py b/.ci/link-gtk.py index 0690563f7..365e2c117 100755 --- a/.ci/link-gtk.py +++ b/.ci/link-gtk.py @@ -3,7 +3,9 @@ # Creates links from gui folder to all files in the gtk folder # This is needed for pyright to work correctly with the dynamic gui imports +import logging from pathlib import Path +import sys IGNORED_FILES = ['__init__.py'] IGNORED_DIRS = ['__pycache__'] @@ -11,12 +13,17 @@ IGNORED_DIRS = ['__pycache__'] cwd = Path.cwd() if cwd.name != 'gajim': - exit('Script needs to be excecuted from gajim repository root directory') + sys.exit('Script needs to be excecuted from gajim repository ' + 'root directory') gui_path = cwd / 'gajim' / 'gui' gtk_path = cwd / 'gajim' / 'gtk' +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() + + def cleanup_dir(target_dir: Path) -> None: for path in target_dir.iterdir(): if path.name in IGNORED_FILES: @@ -31,7 +38,7 @@ def link(target: Path) -> None: source = source.replace('gajim/gtk', 'gajim/gui') source = Path(source) source.symlink_to(target) - print('create symlink from', source, 'to', target) + log.info('create symlink from %s -> %s', source, target) def link_files(source_dir: Path) -> None: |