From 944f539dd69ad880f18628e8b9cc3058d44865af Mon Sep 17 00:00:00 2001 From: BO41 Date: Mon, 20 Sep 2021 12:00:13 +0200 Subject: [PATCH] args.logfd: remove (MR 2114) Replace "args.logfd" with "pmb.helpers.logging.logfd" in order to avoid passing "args" to all functions that only use it to write to logfd. This is the first step to get rid of this args-passed-to-all-functions pattern in pmbootstrap. --- pmb/aportgen/device.py | 46 ++++++++++++++--------------- pmb/aportgen/linux.py | 2 +- pmb/config/init.py | 33 ++++++++++----------- pmb/helpers/args.py | 2 -- pmb/helpers/cli.py | 8 ++--- pmb/helpers/frontend.py | 2 +- pmb/helpers/logging.py | 17 ++++++----- pmb/helpers/run_core.py | 26 ++++++++-------- test/test_apk_static.py | 2 +- test/test_aportgen.py | 2 +- test/test_aportgen_device_wizard.py | 4 +-- test/test_bootimg.py | 2 +- test/test_build_is_necessary.py | 2 +- test/test_build_package.py | 2 +- test/test_config_pmaports.py | 2 +- test/test_config_user.py | 2 +- test/test_config_workdir.py | 2 +- test/test_cross_compile_distcc.py | 2 +- test/test_crossdirect.py | 2 +- test/test_envkernel.py | 2 +- test/test_file.py | 2 +- test/test_helpers_git.py | 2 +- test/test_helpers_lint.py | 2 +- test/test_helpers_package.py | 2 +- test/test_helpers_pmaports.py | 2 +- test/test_helpers_repo.py | 2 +- test/test_helpers_repo_missing.py | 2 +- test/test_helpers_status.py | 2 +- test/test_helpers_ui.py | 2 +- test/test_install.py | 2 +- test/test_kconfig_check.py | 2 +- test/test_keys.py | 2 +- test/test_newapkbuild.py | 2 +- test/test_parse_apkbuild.py | 2 +- test/test_parse_apkindex.py | 2 +- test/test_parse_depends.py | 2 +- test/test_parse_deviceinfo.py | 2 +- test/test_pkgrel_bump.py | 2 +- test/test_qemu_running_processes.py | 2 +- test/test_questions.py | 26 ++++++++-------- test/test_run_core.py | 8 ++--- test/test_shell_escape.py | 2 +- test/test_version.py | 2 +- 43 files changed, 119 insertions(+), 119 deletions(-) diff --git a/pmb/aportgen/device.py b/pmb/aportgen/device.py index a02ddda4..17b91ac3 100644 --- a/pmb/aportgen/device.py +++ b/pmb/aportgen/device.py @@ -9,13 +9,13 @@ import pmb.parse.apkindex import pmb.parse.bootimg -def ask_for_architecture(args): +def ask_for_architecture(): architectures = pmb.config.build_device_architectures # Don't show armhf, new ports shouldn't use this architecture if "armhf" in architectures: architectures.remove("armhf") while True: - ret = pmb.helpers.cli.ask(args, "Device architecture", architectures, + ret = pmb.helpers.cli.ask("Device architecture", architectures, architectures[0], complete=architectures) if ret in architectures: return ret @@ -25,14 +25,14 @@ def ask_for_architecture(args): " pmb/config/__init__.py.") -def ask_for_manufacturer(args): +def ask_for_manufacturer(): logging.info("Who produced the device (e.g. LG)?") - return pmb.helpers.cli.ask(args, "Manufacturer", None, None, False) + return pmb.helpers.cli.ask("Manufacturer", None, None, False) -def ask_for_name(args, manufacturer): +def ask_for_name(manufacturer): logging.info("What is the official name (e.g. Google Nexus 5)?") - ret = pmb.helpers.cli.ask(args, "Name", None, None, False) + ret = pmb.helpers.cli.ask("Name", None, None, False) # Always add the manufacturer if not ret.startswith(manufacturer) and \ @@ -41,19 +41,19 @@ def ask_for_name(args, manufacturer): return ret -def ask_for_year(args): +def ask_for_year(): # Regex from https://stackoverflow.com/a/12240826 logging.info("In what year was the device released (e.g. 2012)?") - return pmb.helpers.cli.ask(args, "Year", None, None, False, + return pmb.helpers.cli.ask("Year", None, None, False, validation_regex=r'^[1-9]\d{3,}$') -def ask_for_chassis(args): +def ask_for_chassis(): types = pmb.config.deviceinfo_chassis_types logging.info("What type of device is it?") logging.info("Valid types are: " + ", ".join(types)) - return pmb.helpers.cli.ask(args, "Chassis", None, None, True, + return pmb.helpers.cli.ask("Chassis", None, None, True, validation_regex='|'.join(types), complete=types) @@ -68,10 +68,10 @@ def ask_for_external_storage(args): " other external storage medium?") -def ask_for_flash_method(args): +def ask_for_flash_method(): while True: logging.info("Which flash method does the device support?") - method = pmb.helpers.cli.ask(args, "Flash method", + method = pmb.helpers.cli.ask("Flash method", pmb.config.flash_methods, pmb.config.flash_methods[0]) @@ -84,7 +84,7 @@ def ask_for_flash_method(args): logging.info("") - heimdall_type = pmb.helpers.cli.ask(args, "Type", + heimdall_type = pmb.helpers.cli.ask("Type", heimdall_types, heimdall_types[0]) if heimdall_type in heimdall_types: @@ -106,7 +106,7 @@ def ask_for_bootimg(args): " 'pmbootstrap bootimg_analyze').") while True: - response = pmb.helpers.cli.ask(args, "Path", None, "", False) + response = pmb.helpers.cli.ask("Path", None, "", False) path = os.path.expanduser(response) if not path: return None @@ -116,7 +116,7 @@ def ask_for_bootimg(args): logging.fatal("ERROR: " + str(e) + ". Please try again.") -def generate_deviceinfo_fastboot_content(args, bootimg=None): +def generate_deviceinfo_fastboot_content(bootimg=None): if bootimg is None: bootimg = {"cmdline": "", "qcdt": "false", @@ -205,9 +205,9 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch, """ if flash_method == "fastboot": - content += generate_deviceinfo_fastboot_content(args, bootimg) + content += generate_deviceinfo_fastboot_content(bootimg) elif flash_method == "heimdall-bootimg": - content += generate_deviceinfo_fastboot_content(args, bootimg) + content += generate_deviceinfo_fastboot_content(bootimg) content += content_heimdall_bootimg elif flash_method == "heimdall-isorec": content += content_heimdall_isorec @@ -273,14 +273,14 @@ def generate_apkbuild(args, pkgname, name, arch, flash_method): def generate(args, pkgname): - arch = ask_for_architecture(args) - manufacturer = ask_for_manufacturer(args) - name = ask_for_name(args, manufacturer) - year = ask_for_year(args) - chassis = ask_for_chassis(args) + arch = ask_for_architecture() + manufacturer = ask_for_manufacturer() + name = ask_for_name(manufacturer) + year = ask_for_year() + chassis = ask_for_chassis() has_keyboard = ask_for_keyboard(args) has_external_storage = ask_for_external_storage(args) - flash_method = ask_for_flash_method(args) + flash_method = ask_for_flash_method() bootimg = None if flash_method in ["fastboot", "heimdall-bootimg"]: bootimg = ask_for_bootimg(args) diff --git a/pmb/aportgen/linux.py b/pmb/aportgen/linux.py index 8eced1e2..200c8d33 100644 --- a/pmb/aportgen/linux.py +++ b/pmb/aportgen/linux.py @@ -26,7 +26,7 @@ def generate_apkbuild(args, pkgname, deviceinfo, patches): build += """\n # Master DTB (deviceinfo_bootimg_qcdt)""" vendors = ["spreadtrum", "exynos", "other"] - soc_vendor = pmb.helpers.cli.ask(args, "SoC vendor", vendors, + soc_vendor = pmb.helpers.cli.ask("SoC vendor", vendors, vendors[-1], complete=vendors) if soc_vendor == "spreadtrum": makedepends.append("dtbtool-sprd") diff --git a/pmb/config/init.py b/pmb/config/init.py index 5522fc55..74813ecd 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -47,7 +47,7 @@ def ask_for_work_path(args): while True: try: work = os.path.expanduser(pmb.helpers.cli.ask( - args, "Work path", None, args.work, False)) + "Work path", None, args.work, False)) work = os.path.realpath(work) exists = os.path.exists(work) @@ -103,7 +103,7 @@ def ask_for_channel(args): # Ask until user gives valid channel while True: - ret = pmb.helpers.cli.ask(args, "Channel", None, default, + ret = pmb.helpers.cli.ask("Channel", None, default, complete=choices) if ret in choices: return ret @@ -138,7 +138,7 @@ def ask_for_ui(args, device): " available. See: