diff options
-rw-r--r-- | .ci/appveyor_build.py | 25 | ||||
-rw-r--r-- | .ci/deploy.py | 18 | ||||
-rwxr-xr-x | .ci/link-gtk.py | 11 | ||||
-rwxr-xr-x | scripts/bump_version.py | 5 | ||||
-rwxr-xr-x | scripts/generate_ui_types.py | 16 | ||||
-rwxr-xr-x | scripts/update_translations.py | 2 | ||||
-rw-r--r-- | setup.py | 11 | ||||
-rw-r--r-- | win/misc/create-launcher.py | 18 | ||||
-rw-r--r-- | win/misc/depcheck.py | 12 |
9 files changed, 73 insertions, 45 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: diff --git a/scripts/bump_version.py b/scripts/bump_version.py index 84ea3fae8..4c99ece13 100755 --- a/scripts/bump_version.py +++ b/scripts/bump_version.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 -import re import argparse from datetime import datetime from pathlib import Path +import re import subprocess +import sys REPO_DIR = Path(__file__).resolve().parent.parent @@ -23,7 +24,7 @@ def get_current_version() -> str: match = re.search(VERSION_RX, content) if match is None: - exit('Unable to find current version') + sys.exit('Unable to find current version') return match[0] diff --git a/scripts/generate_ui_types.py b/scripts/generate_ui_types.py index 1a4d75aba..260e61f6f 100755 --- a/scripts/generate_ui_types.py +++ b/scripts/generate_ui_types.py @@ -3,15 +3,21 @@ # Reads all .ui files and creates builder.pyi # Excecute this script from the repo root dir +import logging +import sys from io import TextIOWrapper from pathlib import Path -from xml.etree import ElementTree as ET +from xml.etree import ElementTree +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() + 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') in_path = cwd / 'gajim' / 'data' / 'gui' out_path = cwd / 'gajim' / 'gtk' / 'builder.pyi' @@ -45,14 +51,14 @@ def get_builder(file_name: str, widgets: list[str] = ...) -> Builder: ...''' def make_class_name(path: Path) -> str: name = path.name.removesuffix('.ui') names = name.split('_') - names = map(lambda x: x.capitalize(), names) + names = [name.capitalize() for name in names] return ''.join(names) + 'Builder' def parse(path: Path, file: TextIOWrapper) -> str: - print('read', path) + log.info('Read %s', path) lines: list[str] = [] - tree = ET.parse(path) + tree = ElementTree.parse(path) for node in tree.iter(tag='object'): id_ = node.attrib.get('id') if id_ is None: diff --git a/scripts/update_translations.py b/scripts/update_translations.py index 3f867a315..c5e66ac46 100755 --- a/scripts/update_translations.py +++ b/scripts/update_translations.py @@ -23,7 +23,7 @@ TRANSLATABLE_FILES = [ def template_is_equal(old_template_path: Path, new_template: str) -> bool: - with open(old_template_path, 'r', encoding='utf8') as f: + with open(old_template_path, encoding='utf8') as f: old_template = f.read() pattern = r'"POT-Creation-Date: .*\n"' @@ -4,6 +4,7 @@ from __future__ import annotations from typing import cast +import logging import os import sys @@ -38,6 +39,10 @@ BUILD_DIR = REPO_DIR / 'build' ALL_LINGUAS = sorted([lang.stem for lang in TRANS_DIR.glob('*.po')]) +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() + + def newer(source: Path, target: Path) -> bool: if not source.exists(): raise ValueError('file "%s" does not exist' % source.resolve()) @@ -67,7 +72,7 @@ def build_translation() -> None: cwd=REPO_DIR, check=True) - print('Compiling %s >> %s' % (po_file, mo_file)) + log.info('Compiling %s >> %s', po_file, mo_file) def install_trans(data_files: DataFilesT) -> None: @@ -99,7 +104,7 @@ def build_man() -> None: with open(filename, 'rb') as f_in,\ gzip.open(man_file_gz, 'wb') as f_out: f_out.writelines(f_in) - print('Compiling %s >> %s' % (filename, man_file_gz)) + log.info('Compiling %s >> %s', filename, man_file_gz) def install_man(data_files: DataFilesT) -> None: @@ -148,7 +153,7 @@ def merge(in_file: Path, msg = ('ERROR: %s was not merged into the translation files!\n' % out_file) raise SystemExit(msg) - print('Compiling %s >> %s' % (in_file, out_file)) + log.info('Compiling %s >> %s', in_file, out_file) class build(_build): diff --git a/win/misc/create-launcher.py b/win/misc/create-launcher.py index f5e8d3225..2a1f6fcc8 100644 --- a/win/misc/create-launcher.py +++ b/win/misc/create-launcher.py @@ -50,8 +50,9 @@ def get_build_args() -> list[str]: def build_exe(source_path: str, resource_path: str, - is_gui: bool, - out_path: str) -> None: + out_path: str, + *, + is_gui: bool) -> None: args = ['gcc', '-s'] if is_gui: @@ -61,7 +62,7 @@ def build_exe(source_path: str, subprocess.check_call(args) -def get_launcher_code(debug: bool) -> str: +def get_launcher_code(*, debug: bool) -> str: template = '''\ #include "Python.h" #define WIN32_LEAN_AND_MEAN @@ -166,8 +167,9 @@ def build_launcher(out_path: str, product_name: str, product_version: str, company_name: str, + *, is_gui: bool, - debug: bool = False) -> None: + debug: bool) -> None: src_ico = os.path.abspath(icon_path) target = os.path.abspath(out_path) @@ -179,7 +181,7 @@ def build_launcher(out_path: str, try: os.chdir(temp) with open('launcher.c', 'w') as h: - h.write(get_launcher_code(debug)) + h.write(get_launcher_code(debug=debug)) shutil.copyfile(src_ico, 'launcher.ico') with open('launcher.rc', 'w') as h: h.write(get_resouce_code( @@ -187,7 +189,7 @@ def build_launcher(out_path: str, 'launcher.ico', product_name, product_version, company_name)) build_resource('launcher.rc', 'launcher.res') - build_exe('launcher.c', 'launcher.res', is_gui, target) + build_exe('launcher.c', 'launcher.res', target, is_gui=is_gui) finally: os.chdir(dir_) shutil.rmtree(temp) @@ -205,12 +207,12 @@ def main() -> None: build_launcher( os.path.join(target, 'Gajim.exe'), os.path.join(misc, 'gajim.ico'), 'Gajim', 'Gajim', - version, company_name, True) + version, company_name, is_gui=True, debug=False) build_launcher( os.path.join(target, 'Gajim-Debug.exe'), os.path.join(misc, 'gajim.ico'), 'Gajim', 'Gajim', - version, company_name, False, debug=True) + version, company_name, is_gui=False, debug=True) # build_launcher( # os.path.join(target, "history_manager.exe"), diff --git a/win/misc/depcheck.py b/win/misc/depcheck.py index a835079fa..cdef03272 100644 --- a/win/misc/depcheck.py +++ b/win/misc/depcheck.py @@ -12,12 +12,16 @@ import subprocess import os import sys +import logging from typing import Optional import gi gi.require_version('GIRepository', '2.0') from gi.repository import GIRepository # noqa: E402 +logging.basicConfig(level='INFO', format='%(levelname)s: %(message)s') +log = logging.getLogger() + def get_required_by_typelibs() -> set[str]: deps: set[str] = set() @@ -49,7 +53,7 @@ def get_dependencies(filename: str) -> list[str]: try: data = subprocess.getoutput('objdump -p %s' % filename) except Exception as error: - print(error) + log.error(error) return deps for line in data.splitlines(): @@ -79,12 +83,12 @@ def get_things_to_delete(root: str) -> list[str]: all_libs.add(lib) needed.add(lib) if find_lib(root, lib) is None: - print('MISSING:', path, lib) + log.info('MISSING: %s %s', path, lib) for lib in get_required_by_typelibs(): needed.add(lib) if find_lib(root, lib) is None: - print('MISSING:', lib) + log.info('MISSING: %s', lib) result: list[str] = [] libs = all_libs - needed @@ -106,7 +110,7 @@ def main() -> None: libs = get_things_to_delete(sys.prefix) while libs: for lib in libs: - print('DELETE:', lib) + log.info('DELETE: %s', lib) os.unlink(lib) libs = get_things_to_delete(sys.prefix) |