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 /win | |
parent | 2bbcd18bbe9609d8155c5988076aa4004b69e6cb (diff) |
refactor: Scripts: Fix various issues
- Use logging module everywhere
- Fix boolean traps
- replace exit() with sys.exit()
Diffstat (limited to 'win')
-rw-r--r-- | win/misc/create-launcher.py | 18 | ||||
-rw-r--r-- | win/misc/depcheck.py | 12 |
2 files changed, 18 insertions, 12 deletions
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) |