From dad1d3e7f978104cd2a5a9070f0762dcd7bd6db0 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 18 Mar 2023 19:09:02 -0700 Subject: [PATCH 01/10] Switch to Github release for wimboot --- setup/build_linux | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/setup/build_linux b/setup/build_linux index 3afe2a2d..73c05197 100755 --- a/setup/build_linux +++ b/setup/build_linux @@ -118,13 +118,12 @@ function update_live_env() { sed -i -r "s/SUPPORT_URL/$KIT_NAME_SHORT/" "$PROFILE_DIR/profiledef.sh" # Boot config (legacy) - mkdir -p "$PROFILE_DIR/syslinux/wimboot" + mkdir -p "$TEMP_DIR" 2>/dev/null + git clone --depth=1 https://github.com/ipxe/wimboot "$TEMP_DIR/wimboot" + rsync -aI "$TEMP_DIR/wimboot"/{LICENSE.txt,README.md,wimboot} "$PROFILE_DIR/syslinux/wimboot/" cp "$ROOT_DIR/images/Pxelinux.png" "$PROFILE_DIR/syslinux/pxelinux.png" cp "$ROOT_DIR/images/Syslinux.png" "$PROFILE_DIR/syslinux/syslinux.png" sed -i -r "s/__+/$KIT_NAME_FULL/" "$PROFILE_DIR/syslinux/syslinux.cfg" - mkdir -p "$TEMP_DIR" 2>/dev/null - curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip" - 7z e -aoa "$TEMP_DIR/wimboot.zip" -o"$PROFILE_DIR/syslinux/wimboot" 'wimboot*/LICENSE.txt' 'wimboot*/README.txt' 'wimboot*/wimboot' # Boot config (UEFI) curl -Lo "$TEMP_DIR/refind.zip" "https://sourceforge.net/projects/refind/files/latest/download" From e00920f24a0bf5093d12b6f8b0b9ad606ea3b4de Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 18:47:46 -0700 Subject: [PATCH 02/10] Switch to ruff linting --- scripts/auto_repairs.py | 5 ++--- scripts/auto_setup.py | 5 ++--- scripts/build_kit_windows.py | 4 ++-- scripts/ddrescue-tui.py | 3 +-- scripts/embedded_python_env.py | 2 +- scripts/export_bitlocker.py | 2 +- scripts/hw-diags.py | 3 +-- scripts/launch_sdio.py | 8 +++++--- scripts/mount-backup-shares | 1 - scripts/pyproject.toml | 18 ++++++++++++++++++ scripts/wk/cfg/ddrescue.py | 1 - scripts/wk/cfg/hw.py | 1 - scripts/wk/cfg/launchers.py | 1 - scripts/wk/cfg/setup.py | 2 -- scripts/wk/cfg/sources.py | 1 - scripts/wk/clone/ddrescue.py | 7 ------- scripts/wk/debug.py | 2 -- scripts/wk/exe.py | 3 --- scripts/wk/hw/diags.py | 5 ----- scripts/wk/hw/disk.py | 1 - scripts/wk/hw/sensors.py | 8 +++++--- scripts/wk/hw/test.py | 1 - scripts/wk/kit/build_win.py | 6 +++++- scripts/wk/kit/tools.py | 20 +++++++++++++++----- scripts/wk/kit/ufd.py | 1 - scripts/wk/log.py | 1 - scripts/wk/os/linux.py | 1 - scripts/wk/os/win.py | 4 +--- scripts/wk/repairs/win.py | 8 ++++++-- scripts/wk/setup/win.py | 1 - scripts/wk/std.py | 4 ---- scripts/wk/tmux.py | 1 - scripts/wk_debug.py | 3 +-- 33 files changed, 66 insertions(+), 68 deletions(-) create mode 100644 scripts/pyproject.toml diff --git a/scripts/auto_repairs.py b/scripts/auto_repairs.py index 1435003d..f2f8b09d 100644 --- a/scripts/auto_repairs.py +++ b/scripts/auto_repairs.py @@ -6,13 +6,12 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 # Classes REBOOT_STR = wk.std.color_string('Reboot', 'YELLOW') class MenuEntry(): - # pylint: disable=too-few-public-methods """Simple class to allow cleaner code below.""" def __init__(self, name, function=None, selected=True, **kwargs): self.name = name @@ -96,5 +95,5 @@ if __name__ == '__main__': wk.std.abort() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/auto_setup.py b/scripts/auto_setup.py index f6d4a0df..c729ff22 100644 --- a/scripts/auto_setup.py +++ b/scripts/auto_setup.py @@ -6,12 +6,11 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 # Classes class MenuEntry(): - # pylint: disable=too-few-public-methods """Simple class to allow cleaner code below.""" def __init__(self, name, function=None, selected=True, **kwargs): self.name = name @@ -163,5 +162,5 @@ if __name__ == '__main__': wk.std.abort() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/build_kit_windows.py b/scripts/build_kit_windows.py index e726dfef..8969115e 100644 --- a/scripts/build_kit_windows.py +++ b/scripts/build_kit_windows.py @@ -6,7 +6,7 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 if __name__ == '__main__': @@ -16,5 +16,5 @@ if __name__ == '__main__': wk.std.abort() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/ddrescue-tui.py b/scripts/ddrescue-tui.py index bd383ac5..183595a3 100755 --- a/scripts/ddrescue-tui.py +++ b/scripts/ddrescue-tui.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """WizardKit: ddrescue TUI""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 from docopt import docopt @@ -20,5 +19,5 @@ if __name__ == '__main__': wk.clone.ddrescue.main() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/embedded_python_env.py b/scripts/embedded_python_env.py index 32103427..0c86c0f1 100644 --- a/scripts/embedded_python_env.py +++ b/scripts/embedded_python_env.py @@ -10,7 +10,7 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 wk.std.print_colored( (wk.cfg.main.KIT_NAME_FULL, ': ', 'Debug Console'), ('GREEN', None, 'YELLOW'), diff --git a/scripts/export_bitlocker.py b/scripts/export_bitlocker.py index d44ff494..d1a5ef91 100644 --- a/scripts/export_bitlocker.py +++ b/scripts/export_bitlocker.py @@ -6,6 +6,6 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 wk.os.win.export_bitlocker_info() \ No newline at end of file diff --git a/scripts/hw-diags.py b/scripts/hw-diags.py index 858477fb..13c456a3 100755 --- a/scripts/hw-diags.py +++ b/scripts/hw-diags.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """WizardKit: Hardware Diagnostics""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 from docopt import docopt @@ -20,5 +19,5 @@ if __name__ == '__main__': wk.hw.diags.main() except SystemExit: raise - except: #pylint: disable=bare-except + except: # noqa: E722 wk.std.major_exception() diff --git a/scripts/launch_sdio.py b/scripts/launch_sdio.py index 70e6515b..9b52ca5f 100644 --- a/scripts/launch_sdio.py +++ b/scripts/launch_sdio.py @@ -6,8 +6,8 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position -from wk.cfg.net import SDIO_SERVER # pylint: disable=wrong-import-position +import wk # noqa: E402 +from wk.cfg.net import SDIO_SERVER # noqa: E402 # STATIC VARIABLES MOUNT_EXCEPTIONS = ( @@ -70,7 +70,9 @@ def use_network_sdio(): if __name__ == '__main__': - wk.std.set_title(f'{wk.cfg.main.KIT_NAME_FULL}: Snappy Driver Installer Origin Launcher') + wk.std.set_title( + f'{wk.cfg.main.KIT_NAME_FULL}: Snappy Driver Installer Origin Launcher', + ) log_dir = wk.log.format_log_path(tool=True).parent USE_NETWORK = False diff --git a/scripts/mount-backup-shares b/scripts/mount-backup-shares index c88312a6..cc1dd437 100755 --- a/scripts/mount-backup-shares +++ b/scripts/mount-backup-shares @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """WizardKit: Mount Backup Shares""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 import wk diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml new file mode 100644 index 00000000..05f92df9 --- /dev/null +++ b/scripts/pyproject.toml @@ -0,0 +1,18 @@ +[tool.ruff.per-file-ignores] +# Init files +"wk/__init__.py" = ["F401"] +"wk/cfg/__init__.py" = ["F401"] +"wk/clone/__init__.py" = ["F401"] +"wk/hw/__init__.py" = ["F401"] +"wk/kit/__init__.py" = ["F401"] +"wk/os/__init__.py" = ["F401"] +"wk/repairs/__init__.py" = ["F401"] +"wk/setup/__init__.py" = ["F401"] + +# Long lines +"wk/borrowed/acpi.py" = ["E501", "F841"] +"wk/cfg/ddrescue.py" = ["E501"] +"wk/cfg/hw.py" = ["E501"] +"wk/cfg/launchers.py" = ["E501"] +"wk/cfg/setup.py" = ["E501"] +"wk/cfg/sources.py" = ["E501"] diff --git a/scripts/wk/cfg/ddrescue.py b/scripts/wk/cfg/ddrescue.py index e621f968..7309236a 100644 --- a/scripts/wk/cfg/ddrescue.py +++ b/scripts/wk/cfg/ddrescue.py @@ -1,5 +1,4 @@ """WizardKit: Config - ddrescue""" -# pylint: disable=line-too-long # vim: sts=2 sw=2 ts=2 from collections import OrderedDict diff --git a/scripts/wk/cfg/hw.py b/scripts/wk/cfg/hw.py index 1ef7513c..4ebadb84 100644 --- a/scripts/wk/cfg/hw.py +++ b/scripts/wk/cfg/hw.py @@ -1,5 +1,4 @@ """WizardKit: Config - Hardware""" -# pylint: disable=line-too-long # vim: sts=2 sw=2 ts=2 import re diff --git a/scripts/wk/cfg/launchers.py b/scripts/wk/cfg/launchers.py index 6d78a207..da31d3e2 100644 --- a/scripts/wk/cfg/launchers.py +++ b/scripts/wk/cfg/launchers.py @@ -1,5 +1,4 @@ """WizardKit: Config - Launchers (Windows)""" -# pylint: disable=line-too-long # vim: sts=2 sw=2 ts=2 LAUNCHERS = { diff --git a/scripts/wk/cfg/setup.py b/scripts/wk/cfg/setup.py index 1b49897d..453b405c 100644 --- a/scripts/wk/cfg/setup.py +++ b/scripts/wk/cfg/setup.py @@ -1,5 +1,4 @@ """WizardKit: Config - Setup""" -# pylint: disable=line-too-long # vim: sts=2 sw=2 ts=2 @@ -31,7 +30,6 @@ REG_CHROME_UBLOCK_ORIGIN = { }, } REG_WINDOWS_EXPLORER = { - # pylint: disable=line-too-long 'HKLM': { # Disable Location Tracking r'Software\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}': ( diff --git a/scripts/wk/cfg/sources.py b/scripts/wk/cfg/sources.py index 9b15b7dd..16235639 100644 --- a/scripts/wk/cfg/sources.py +++ b/scripts/wk/cfg/sources.py @@ -1,5 +1,4 @@ """WizardKit: Config - Tool Sources""" -# pylint: disable=line-too-long # vim: sts=2 sw=2 ts=2 diff --git a/scripts/wk/clone/ddrescue.py b/scripts/wk/clone/ddrescue.py index cf812abf..29667bd9 100644 --- a/scripts/wk/clone/ddrescue.py +++ b/scripts/wk/clone/ddrescue.py @@ -1,5 +1,4 @@ """WizardKit: ddrescue TUI""" -# pylint: disable=too-many-lines # vim: sts=2 sw=2 ts=2 import atexit @@ -127,7 +126,6 @@ TIMEZONE = pytz.timezone(cfg.main.LINUX_TIME_ZONE) # Classes class BlockPair(): """Object for tracking source to dest recovery data.""" - # pylint: disable=too-many-instance-attributes def __init__(self, source, destination, model, working_dir): """Initialize BlockPair() @@ -336,7 +334,6 @@ class BlockPair(): class State(): - # pylint: disable=too-many-public-methods """Object for tracking hardware diagnostic data.""" def __init__(self): self.block_pairs = [] @@ -706,7 +703,6 @@ class State(): return sum(pair.size for pair in self.block_pairs) def init_recovery(self, docopt_args): - # pylint: disable=too-many-branches """Select source/dest and set env.""" std.clear_screen() source_parts = [] @@ -1896,7 +1892,6 @@ def source_or_destination_changed(state): def main(): - # pylint: disable=too-many-branches """Main function for ddrescue TUI.""" args = docopt(DOCSTRING) log.update_log_path(dest_name='ddrescue-TUI', timestamp=True) @@ -2038,7 +2033,6 @@ def mount_raw_image_macos(path): def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True): - # pylint: disable=too-many-statements """Run ddrescue using passed settings.""" cmd = build_ddrescue_cmd(block_pair, pass_name, settings) poweroff_source_after_idle = True @@ -2186,7 +2180,6 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True): def run_recovery(state, main_menu, settings_menu, dry_run=True): - # pylint: disable=too-many-branches """Run recovery passes.""" atexit.register(state.save_debug_reports) attempted_recovery = False diff --git a/scripts/wk/debug.py b/scripts/wk/debug.py index 3403d1f3..11da914d 100644 --- a/scripts/wk/debug.py +++ b/scripts/wk/debug.py @@ -1,11 +1,9 @@ """WizardKit: Debug Functions""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 # Classes class Debug(): - # pylint: disable=too-few-public-methods """Object used when dumping debug data.""" def method(self): """Dummy method used to identify functions vs data.""" diff --git a/scripts/wk/exe.py b/scripts/wk/exe.py index e57240c9..3511c510 100644 --- a/scripts/wk/exe.py +++ b/scripts/wk/exe.py @@ -21,7 +21,6 @@ LOG = logging.getLogger(__name__) # Classes class NonBlockingStreamReader(): """Class to allow non-blocking reads from a stream.""" - # pylint: disable=too-few-public-methods # Credits: ## https://gist.github.com/EyalAr/7915597 ## https://stackoverflow.com/a/4896288 @@ -200,7 +199,6 @@ def popen_program(cmd, minimized=False, pipe=False, shell=False, **kwargs): shell=shell, **kwargs) try: - # pylint: disable=consider-using-with proc = subprocess.Popen(**cmd_kwargs) except FileNotFoundError: LOG.error('Command not found: %s', cmd) @@ -212,7 +210,6 @@ def popen_program(cmd, minimized=False, pipe=False, shell=False, **kwargs): def run_program(cmd, check=True, pipe=True, shell=False, **kwargs): - # pylint: disable=subprocess-run-check """Run program and return a subprocess.CompletedProcess object.""" LOG.debug( 'cmd: %s, check: %s, pipe: %s, shell: %s', diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index c5f9484a..ed23ea8d 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -325,7 +325,6 @@ class State(): # Functions def build_menu(cli_mode=False, quick_mode=False) -> std.Menu: - # pylint: disable=too-many-branches """Build main menu, returns wk.std.Menu.""" menu = std.Menu(title=None) @@ -377,7 +376,6 @@ def build_menu(cli_mode=False, quick_mode=False) -> std.Menu: def cpu_stress_tests(state, test_objects, test_mode=False) -> None: - # pylint: disable=too-many-statements """CPU & cooling check using Prime95 and Sysbench.""" LOG.info('CPU Test (Prime95)') aborted = False @@ -508,7 +506,6 @@ def cpu_stress_tests(state, test_objects, test_mode=False) -> None: def disk_attribute_check(state, test_objects, test_mode=False) -> None: - # pylint: disable=unused-argument """Disk attribute check.""" LOG.info('Disk Attribute Check') for test in test_objects: @@ -587,7 +584,6 @@ def disk_io_benchmark( def disk_self_test(state, test_objects, test_mode=False) -> None: - # pylint: disable=unused-argument """Disk self-test if available.""" LOG.info('Disk Self-Test(s)') aborted = False @@ -749,7 +745,6 @@ def disk_surface_scan(state, test_objects, test_mode=False) -> None: def main() -> None: - # pylint: disable=too-many-branches """Main function for hardware diagnostics.""" args = docopt(DOCSTRING) log.update_log_path(dest_name='Hardware-Diagnostics', timestamp=True) diff --git a/scripts/wk/hw/disk.py b/scripts/wk/hw/disk.py index eaea2fbf..3c7c727c 100644 --- a/scripts/wk/hw/disk.py +++ b/scripts/wk/hw/disk.py @@ -33,7 +33,6 @@ WK_LABEL_REGEX = re.compile( # Classes @dataclass(**DATACLASS_DECORATOR_KWARGS) class Disk: - # pylint: disable=too-many-instance-attributes """Object for tracking disk specific data.""" attributes: dict[Any, dict] = field(init=False, default_factory=dict) bus: str = field(init=False) diff --git a/scripts/wk/hw/sensors.py b/scripts/wk/hw/sensors.py index 6950f191..49d693f0 100644 --- a/scripts/wk/hw/sensors.py +++ b/scripts/wk/hw/sensors.py @@ -121,7 +121,6 @@ class Sensors(): self, out_path, alt_max=None, exit_on_thermal_limit=True, temp_labels=None, thermal_action=None) -> None: - # pylint: disable=too-many-arguments """Write report to path every second until stopped. thermal_action is a cmd to run if ThermalLimitReachedError is caught. @@ -182,7 +181,6 @@ class Sensors(): self, out_path, alt_max=None, exit_on_thermal_limit=True, temp_labels=None, thermal_action=None) -> None: - # pylint: disable=too-many-arguments """Start background thread to save report to file. thermal_action is a cmd to run if ThermalLimitReachedError is caught. @@ -315,7 +313,11 @@ def get_sensor_data_linux() -> dict[Any, Any]: ## current temp is labeled xxxx_input for source, labels in sources.items(): for label, temp in labels.items(): - if label.startswith('fan') or label.startswith('in') or label.startswith('curr'): + if ( + label.startswith('fan') + or label.startswith('in') + or label.startswith('curr') + ): # Skip fan RPMs and voltages continue if 'input' in label: diff --git a/scripts/wk/hw/test.py b/scripts/wk/hw/test.py index 9769c51a..628ada11 100644 --- a/scripts/wk/hw/test.py +++ b/scripts/wk/hw/test.py @@ -8,7 +8,6 @@ from wk.cfg.python import DATACLASS_DECORATOR_KWARGS @dataclass(**DATACLASS_DECORATOR_KWARGS) class Test: - # pylint: disable=too-many-instance-attributes """Object for tracking test specific data.""" dev: Any label: str diff --git a/scripts/wk/kit/build_win.py b/scripts/wk/kit/build_win.py index 443768f1..ff377790 100644 --- a/scripts/wk/kit/build_win.py +++ b/scripts/wk/kit/build_win.py @@ -209,7 +209,11 @@ def download_fastcopy(): def download_furmark(): """Download FurMark.""" - installer = download_to_temp('FurMark_Setup.exe', SOURCES['FurMark'], referer=SOURCES['FurMark']) + installer = download_to_temp( + 'FurMark_Setup.exe', + SOURCES['FurMark'], + referer=SOURCES['FurMark'], + ) out_path = BIN_DIR.joinpath('FurMark') tmp_path = TMP_DIR.joinpath('FurMarkInstall') run_program([installer, f'/DIR={tmp_path}', '/SILENT']) diff --git a/scripts/wk/kit/tools.py b/scripts/wk/kit/tools.py index 854bf4c4..641beb2b 100644 --- a/scripts/wk/kit/tools.py +++ b/scripts/wk/kit/tools.py @@ -55,13 +55,23 @@ def download_file(out_path, source_url, as_new=False, overwrite=False, referer=N # Request download with requests.Session() as session: try: - response = session.get(source_url, allow_redirects=True, headers=headers, stream=True) - except requests.RequestException as _err: + response = session.get( + source_url, + allow_redirects=True, + headers=headers, + stream=True, + ) + except requests.RequestException: try: sleep(1) - response = session.get(source_url, allow_redirects=True, headers=headers, stream=True) - except requests.RequestException as _err2: - download_failed = _err2 + response = session.get( + source_url, + allow_redirects=True, + headers=headers, + stream=True, + ) + except requests.RequestException as _err: + download_failed = _err else: if not response.ok: download_failed = response diff --git a/scripts/wk/kit/ufd.py b/scripts/wk/kit/ufd.py index 72b20bff..cc5e9969 100644 --- a/scripts/wk/kit/ufd.py +++ b/scripts/wk/kit/ufd.py @@ -88,7 +88,6 @@ def apply_image(part_path, image_path, hide_macos_boot=True): def build_ufd(): - # pylint: disable=too-many-statements """Build UFD using selected sources.""" args = docopt(DOCSTRING) if args['--debug']: diff --git a/scripts/wk/log.py b/scripts/wk/log.py index dfa09127..b69afb1f 100644 --- a/scripts/wk/log.py +++ b/scripts/wk/log.py @@ -41,7 +41,6 @@ def enable_debug_mode(): def format_log_path( log_dir=None, log_name=None, timestamp=False, kit=False, tool=False, append=False): - # pylint: disable=too-many-arguments """Format path based on args passed, returns pathlib.Path obj.""" log_path = pathlib.Path( f'{log_dir if log_dir else DEFAULT_LOG_DIR}/' diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index 01b75c09..481e687c 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -178,7 +178,6 @@ def mount(source, mount_point=None, read_write=False): def mount_volumes(device_path=None, read_write=False, scan_corestorage=False): - # pylint: disable=too-many-branches """Mount all detected volumes. NOTE: If device_path is specified then only volumes diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 16658501..42930ba7 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -354,7 +354,6 @@ def show_alert_box(message, title=None): # Registry Functions def reg_delete_key(hive, key, recurse=False): - # pylint: disable=raise-missing-from """Delete a key from the registry. NOTE: If recurse is False then it will only work on empty keys. @@ -518,7 +517,6 @@ def reg_write_settings(settings): def reg_set_value(hive, key, name, data, data_type, option=None): - # pylint: disable=too-many-arguments """Set value for hive/key.""" access = winreg.KEY_WRITE data_type = reg_get_data_type(data_type) @@ -702,7 +700,7 @@ def start_service(service_name): run_program(cmd, check=False) # Verify service was started - if not get_service_status(service_name) in ('running', 'start_pending'): + if get_service_status(service_name) not in ('running', 'start_pending'): raise GenericError(f'Failed to start service {service_name}') diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index b4181a04..938fb3b3 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -1,5 +1,4 @@ """WizardKit: Repairs - Windows""" -# pylint: disable=too-many-lines # vim: sts=2 sw=2 ts=2 import atexit @@ -548,7 +547,12 @@ def set_log_path(): # Ignore and use default values update_log_path(dest_name='Auto Repairs', timestamp=True) else: - update_log_path(dest_name=log_path, keep_history=False, timestamp=False, append=True) + update_log_path( + dest_name=log_path, + keep_history=False, + timestamp=False, + append=True, + ) def show_main_menu(base_menus, menus, presets, title): diff --git a/scripts/wk/setup/win.py b/scripts/wk/setup/win.py index d51e4cf5..362c7b1a 100644 --- a/scripts/wk/setup/win.py +++ b/scripts/wk/setup/win.py @@ -1,5 +1,4 @@ """WizardKit: Setup - Windows""" -# pylint: disable=too-many-lines # vim: sts=2 sw=2 ts=2 import configparser diff --git a/scripts/wk/std.py b/scripts/wk/std.py index b3ad837e..3b174f6f 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -1,5 +1,4 @@ """WizardKit: Standard Functions""" -# pylint: disable=too-many-lines # vim: sts=2 sw=2 ts=2 import inspect @@ -134,7 +133,6 @@ class Menu(): def _get_display_name( self, name, details, index=None, no_checkboxes=True, setting_item=False): - # pylint: disable=too-many-arguments """Format display name based on details and args, returns str.""" disabled = details.get('Disabled', False) if setting_item and not details['Selected']: @@ -400,7 +398,6 @@ class Menu(): class TryAndPrint(): - # pylint: disable=too-many-instance-attributes """Object used to standardize running functions and returning the result. The errors and warning attributes are used to allow fine-tuned results @@ -521,7 +518,6 @@ class TryAndPrint(): def run( self, message, function, *args, catch_all=None, msg_good=None, verbose=None, **kwargs): - # pylint: disable=catching-non-exception """Run a function and print the results, returns results as dict. If catch_all is True then (nearly) all exceptions will be caught. diff --git a/scripts/wk/tmux.py b/scripts/wk/tmux.py index b6d32848..49fb3241 100644 --- a/scripts/wk/tmux.py +++ b/scripts/wk/tmux.py @@ -203,7 +203,6 @@ def prep_file(path): def resize_pane(pane_id=None, width=None, height=None, **kwargs): - # pylint: disable=unused-argument """Resize current or target pane. NOTE: kwargs is only here to make calling this function easier diff --git a/scripts/wk_debug.py b/scripts/wk_debug.py index 12a9b726..cf0bc86d 100755 --- a/scripts/wk_debug.py +++ b/scripts/wk_debug.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """WizardKit: Debug Launcher""" -# pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 import os @@ -10,7 +9,7 @@ import sys os.chdir(os.path.dirname(os.path.realpath(__file__))) sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # noqa: E402 # STATIC VARIABLES From 16ee95b1d9fdf3fa5ad1fc7cfb97bdfb630f3f52 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 19:42:54 -0700 Subject: [PATCH 03/10] Adjust Python module path handling Simplifies top-level scripts and removes linting exceptions. --- scripts/auto_repairs.py | 7 +------ scripts/auto_setup.py | 7 +------ scripts/build_kit_windows.py | 7 +------ scripts/embedded_python_env.py | 7 ++----- scripts/export_bitlocker.py | 9 ++------- scripts/launch_sdio.py | 8 ++------ scripts/wk_debug.py | 6 +----- setup/windows/build.ps1 | 3 +++ 8 files changed, 13 insertions(+), 41 deletions(-) diff --git a/scripts/auto_repairs.py b/scripts/auto_repairs.py index 1435003d..565a963e 100644 --- a/scripts/auto_repairs.py +++ b/scripts/auto_repairs.py @@ -1,12 +1,7 @@ """WizardKit: Auto Repair Tool""" # vim: sts=2 sw=2 ts=2 -import os -import sys - -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # Classes diff --git a/scripts/auto_setup.py b/scripts/auto_setup.py index f6d4a0df..eb881f40 100644 --- a/scripts/auto_setup.py +++ b/scripts/auto_setup.py @@ -1,12 +1,7 @@ """WizardKit: Auto System Setup Tool""" # vim: sts=2 sw=2 ts=2 -import os -import sys - -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # Classes diff --git a/scripts/build_kit_windows.py b/scripts/build_kit_windows.py index e726dfef..b05f0029 100644 --- a/scripts/build_kit_windows.py +++ b/scripts/build_kit_windows.py @@ -1,12 +1,7 @@ """WizardKit: Build Kit (Windows).""" # vim: sts=2 sw=2 ts=2 -import os -import sys - -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk if __name__ == '__main__': diff --git a/scripts/embedded_python_env.py b/scripts/embedded_python_env.py index 32103427..7ebf7b98 100644 --- a/scripts/embedded_python_env.py +++ b/scripts/embedded_python_env.py @@ -5,12 +5,9 @@ python.exe -i embedded_python_env.py """ # vim: sts=2 sw=2 ts=2 -import os -import sys +import wk + -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position wk.std.print_colored( (wk.cfg.main.KIT_NAME_FULL, ': ', 'Debug Console'), ('GREEN', None, 'YELLOW'), diff --git a/scripts/export_bitlocker.py b/scripts/export_bitlocker.py index d44ff494..05be8f3d 100644 --- a/scripts/export_bitlocker.py +++ b/scripts/export_bitlocker.py @@ -1,11 +1,6 @@ """WizardKit: Export Bitlocker Tool""" # vim: sts=2 sw=2 ts=2 -import os -import sys +import wk -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position - -wk.os.win.export_bitlocker_info() \ No newline at end of file +wk.os.win.export_bitlocker_info() diff --git a/scripts/launch_sdio.py b/scripts/launch_sdio.py index 70e6515b..958c41cb 100644 --- a/scripts/launch_sdio.py +++ b/scripts/launch_sdio.py @@ -1,13 +1,9 @@ """WizardKit: Launch Snappy Driver Installer Origin""" # vim: sts=2 sw=2 ts=2 -import os -import sys +import wk +from wk.cfg.net import SDIO_SERVER -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position -from wk.cfg.net import SDIO_SERVER # pylint: disable=wrong-import-position # STATIC VARIABLES MOUNT_EXCEPTIONS = ( diff --git a/scripts/wk_debug.py b/scripts/wk_debug.py index 12a9b726..2ed6ad12 100755 --- a/scripts/wk_debug.py +++ b/scripts/wk_debug.py @@ -3,14 +3,10 @@ # pylint: disable=invalid-name # vim: sts=2 sw=2 ts=2 -import os import pathlib import pickle -import sys -os.chdir(os.path.dirname(os.path.realpath(__file__))) -sys.path.append(os.getcwd()) -import wk # pylint: disable=wrong-import-position +import wk # STATIC VARIABLES diff --git a/setup/windows/build.ps1 b/setup/windows/build.ps1 index 36177787..b7ed43a7 100644 --- a/setup/windows/build.ps1 +++ b/setup/windows/build.ps1 @@ -180,6 +180,9 @@ if ($MyInvocation.InvocationName -ne ".") { } Remove-Item "$Temp\python*.zip" Remove-Item "$Temp\*.whl" + foreach ($File in Get-ChildItem "$Bin\Python\*\*._pth") { + Add-Content "$File" "`n#WizardKit`n..\..\Scripts" + } ## Done ## Pop-Location From 10400ec2c3e66d243a4a263aff313fe87abc9533 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 20:05:51 -0700 Subject: [PATCH 04/10] Add pre-commit hook --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a7992785 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/charliermarsh/ruff-pre-commit + # Ruff version. + rev: 'v0.0.257' + hooks: + - id: ruff From 2717ad1a88deec1298698dabebdc6e9b87e917f5 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 20:21:12 -0700 Subject: [PATCH 05/10] Drop pylint reference --- scripts/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 7396a3ef..5e7ad26b 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,8 +1,2 @@ # WizardKit: Scripts # -## pylint ## - -These scripts use two spaces per indent instead of the default four. As such you will need to update your pylintrc file or run like this: - -`pylint --indent-after-paren=2 --indent-string=' ' wk` - From 606e6575915e78ac89f35e0a90873aabbd5b9b0e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 20:47:36 -0700 Subject: [PATCH 06/10] Switch to Memtest86+ under UEFI Memtest86 (by Passmark) still available as an alternate option. --- setup/build_linux | 11 +++++++++-- setup/linux/profile/EFI/boot/refind.conf | 14 +++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/setup/build_linux b/setup/build_linux index 73c05197..37d0762d 100755 --- a/setup/build_linux +++ b/setup/build_linux @@ -134,7 +134,14 @@ function update_live_env() { rsync -aI "$TEMP_DIR/refind"/refind*/refind/icons/ "$PROFILE_DIR/EFI/boot/icons/" sed -i "s/%ARCHISO_LABEL%/${label}/" "$PROFILE_DIR/EFI/boot/refind.conf" - # Memtest86 + # Memtest86+ (Open Source) + mkdir -p "$PROFILE_DIR/EFI/memtest86+" + mkdir -p "$TEMP_DIR/memtest86+" + curl -Lo "$TEMP_DIR/memtest86+/memtest86-binaries.zip" "https://memtest.org/download/v6.10/mt86plus_6.10.binaries.zip" + 7z e "$TEMP_DIR/memtest86+/memtest86-binaries.zip" -o"$TEMP_DIR/memtest86+" "memtest64.efi" + mv "$TEMP_DIR/memtest86+/memtest64.efi" "$PROFILE_DIR/EFI/memtest86+/bootx64.efi" + + # Memtest86 (Passmark) mkdir -p "$PROFILE_DIR/EFI/memtest86/Benchmark" mkdir -p "$TEMP_DIR/memtest86" curl -Lo "$TEMP_DIR/memtest86/memtest86-usb.zip" "https://www.memtest86.com/downloads/memtest86-usb.zip" @@ -142,7 +149,7 @@ function update_live_env() { 7z e -aoa "$TEMP_DIR/memtest86/memtest86-usb.img" -o"$TEMP_DIR/memtest86" "MemTest86.img" 7z x -aoa "$TEMP_DIR/memtest86/MemTest86.img" -o"$TEMP_DIR/memtest86" rm "$TEMP_DIR/memtest86/EFI/BOOT/BOOTIA32.efi" - mv "$TEMP_DIR/memtest86/EFI/BOOT/BOOTX64.efi" "$PROFILE_DIR/EFI/memtest86/memtestx64.efi" + mv "$TEMP_DIR/memtest86/EFI/BOOT/BOOTX64.efi" "$PROFILE_DIR/EFI/memtest86/bootx64.efi" mv "$TEMP_DIR/memtest86/EFI/BOOT"/* "$PROFILE_DIR/EFI/memtest86"/ mv "$TEMP_DIR/memtest86/help"/* "$PROFILE_DIR/EFI/memtest86"/ mv "$TEMP_DIR/memtest86/license.rtf" "$PROFILE_DIR/EFI/memtest86"/ diff --git a/setup/linux/profile/EFI/boot/refind.conf b/setup/linux/profile/EFI/boot/refind.conf index 858081f9..a06beec2 100644 --- a/setup/linux/profile/EFI/boot/refind.conf +++ b/setup/linux/profile/EFI/boot/refind.conf @@ -3,7 +3,7 @@ timeout 0 scanfor manual showtools firmware,reboot,shutdown -default_selection MemTest86 +default_selection Memtest86+ csr_values 10,77 #use_graphics_for osx,linux,windows @@ -15,9 +15,17 @@ selection_small selection_small.png hideui arrows,badges # Entries -menuentry "MemTest86" { +menuentry "MemTest86+" { icon /EFI/boot/icons/wk_memtest.png - loader /EFI/memtest86/bootx64.efi + options "nobigstatus nopause" + loader /EFI/memtest86+/bootx64.efi + submenuentry "Memtest86+ (Open Source)" { + loader /EFI/memtest86+/bootx64.efi + } + submenuentry "Memtest86 (Passmark)" { + loader /EFI/memtest86/bootx64.efi + options + } } menuentry "Linux" { From 4f6a07c4492f7ee5d7960a0ac66cede2b2499ffe Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 19 Mar 2023 20:49:32 -0700 Subject: [PATCH 07/10] Set Linux as the default boot option --- setup/linux/profile/EFI/boot/refind.conf | 26 +++++++++++------------ setup/linux/profile/syslinux/syslinux.cfg | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/setup/linux/profile/EFI/boot/refind.conf b/setup/linux/profile/EFI/boot/refind.conf index a06beec2..243d3c1b 100644 --- a/setup/linux/profile/EFI/boot/refind.conf +++ b/setup/linux/profile/EFI/boot/refind.conf @@ -3,7 +3,7 @@ timeout 0 scanfor manual showtools firmware,reboot,shutdown -default_selection Memtest86+ +default_selection Linux csr_values 10,77 #use_graphics_for osx,linux,windows @@ -15,6 +15,18 @@ selection_small selection_small.png hideui arrows,badges # Entries +menuentry "Linux" { + icon /EFI/boot/icons/wk_arch.png + loader /arch/boot/x86_64/vmlinuz-linux + initrd /arch/boot/intel_ucode.img + initrd /arch/boot/amd_ucode.img + initrd /arch/boot/x86_64/initramfs-linux.img + options "archisobasedir=arch archisolabel=%ARCHISO_LABEL% copytoram loglevel=3" + submenuentry "Linux (CLI)" { + add_options "nox" + } +} + menuentry "MemTest86+" { icon /EFI/boot/icons/wk_memtest.png options "nobigstatus nopause" @@ -28,18 +40,6 @@ menuentry "MemTest86+" { } } -menuentry "Linux" { - icon /EFI/boot/icons/wk_arch.png - loader /arch/boot/x86_64/vmlinuz-linux - initrd /arch/boot/intel_ucode.img - initrd /arch/boot/amd_ucode.img - initrd /arch/boot/x86_64/initramfs-linux.img - options "archisobasedir=arch archisolabel=%ARCHISO_LABEL% copytoram loglevel=3" - submenuentry "Linux (CLI)" { - add_options "nox" - } -} - #UFD-MACOS-10.11#menuentry "macOS (El Capitan)" { #UFD-MACOS-10.11# icon /EFI/boot/icons/wk_mac_10.11.png #UFD-MACOS-10.11# volume "PARTUUID" diff --git a/setup/linux/profile/syslinux/syslinux.cfg b/setup/linux/profile/syslinux/syslinux.cfg index f441b62f..06a33949 100644 --- a/setup/linux/profile/syslinux/syslinux.cfg +++ b/setup/linux/profile/syslinux/syslinux.cfg @@ -35,11 +35,11 @@ MENU SEPARATOR MENU CLEAR -DEFAULT memtest +DEFAULT wk_linux TIMEOUT 0 -INCLUDE memtest.cfg INCLUDE linux.cfg +INCLUDE memtest.cfg #UFD-WINPE#INCLUDE winpe.cfg MENU SEPARATOR From d5bc74d21b2c704c9100d1f5bd49af8829cea1d2 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 25 Mar 2023 20:24:17 -0700 Subject: [PATCH 08/10] Show partition info in 4K alignment check --- scripts/wk/os/win.py | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 42930ba7..ba5eef3d 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -6,6 +6,7 @@ import logging import os import pathlib import platform +import re from contextlib import suppress import psutil @@ -71,6 +72,9 @@ KNOWN_HIVE_NAMES = { RAM_OK = 5.5 * 1024**3 # ~6 GiB assuming a bit of shared memory RAM_WARNING = 3.5 * 1024**3 # ~4 GiB assuming a bit of shared memory REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer' +REGEX_4K_ALIGNMENT = re.compile( + r'^(?P.*?)\s+(?P\d+)\s+(?P\d+)', + ) SLMGR = pathlib.Path(f'{os.environ.get("SYSTEMROOT")}/System32/slmgr.vbs') SYSTEMDRIVE = os.environ.get('SYSTEMDRIVE') @@ -163,19 +167,41 @@ def set_timezone(zone): # Info Functions def check_4k_alignment(show_alert=False): """Check if all partitions are 4K aligned, returns book.""" - cmd = ['WMIC', 'partition', 'get', 'StartingOffset'] + cmd = ['WMIC', 'partition', 'get', 'Caption,Size,StartingOffset'] + report = [] + show_alert = False # Check offsets proc = run_program(cmd) - for offset in proc.stdout.splitlines(): - offset = offset.strip() - if not offset.isnumeric(): + for line in proc.stdout.splitlines(): + line = line.strip() + if not line or not line.startswith('Disk'): continue - if int(offset) % 4096 != 0: - # Not aligned - if show_alert: - show_alert_box('One or more partitions are not 4K aligned') - raise GenericError('One or more partitions are not 4K aligned') + match = REGEX_4K_ALIGNMENT.match(line) + if not match: + LOG.error('Failed to parse partition info for: %s', line) + continue + if int(match.group('offset')) % 4096 == 0: + report.append( + color_string( + f'{match.group("description")}' + f' ({bytes_to_string(match.group("size"), decimals=1)})' + , + 'RED' + ) + ) + + # Show alert + if show_alert: + show_alert_box('One or more partitions not 4K aligned') + + # Done + if report: + report.insert( + 0, + color_string('One or more partitions not 4K aligned', 'YELLOW'), + ) + return report def export_bitlocker_info(): From 7c66eb5e99143e667ae7d3d14eef72176adc97b8 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 26 Mar 2023 23:04:45 -0700 Subject: [PATCH 09/10] Allow password sign-in for MS accounts Addresses issue #210 --- scripts/wk/cfg/setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/wk/cfg/setup.py b/scripts/wk/cfg/setup.py index 453b405c..0febc824 100644 --- a/scripts/wk/cfg/setup.py +++ b/scripts/wk/cfg/setup.py @@ -31,6 +31,10 @@ REG_CHROME_UBLOCK_ORIGIN = { } REG_WINDOWS_EXPLORER = { 'HKLM': { + # Allow password sign-in for MS accounts + r'Software\Microsoft\Windows NT\CurrentVersion\PasswordLess\Device': ( + ('DevicePasswordLessBuildVersion', 0, 'DWORD'), + ), # Disable Location Tracking r'Software\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}': ( ('SensorPermissionState', 0, 'DWORD'), From 08294caffcf99f8b4744c01607b399b0349452ae Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 26 Mar 2023 23:09:53 -0700 Subject: [PATCH 10/10] Drop photorec-sort script --- scripts/photorec-sort | 150 ------------------------------------------ 1 file changed, 150 deletions(-) delete mode 100755 scripts/photorec-sort diff --git a/scripts/photorec-sort b/scripts/photorec-sort deleted file mode 100755 index 6f11b0a6..00000000 --- a/scripts/photorec-sort +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/bash -# -## sort photorec results into something usefull - -## Set paths -recup_dir="${1%/}" -[ -n "$recup_dir" ] || recup_dir="." -recup_dir="$(realpath "$recup_dir")" -out_dir="$recup_dir/Recovered" -bad_dir="$recup_dir/Corrupt" - -## Test path before starting (using current dir if not specified) -for d in $recup_dir/recup*; do - ### Source: http://stackoverflow.com/a/6364244 - ## Check if the glob gets expanded to existing files. - ## If not, f here will be exactly the pattern above - ## and the exists test will evaluate to false. - [ -e "$d" ] && echo "Found recup folder(s)" || { - echo "ERROR: No recup folders found" - echo "Usage: $0 recup_dir" - exit 1 - } - - ## This is all we needed to know, so we can break after the first iteration - break -done - -# Hard link files into folders by type -for d in $recup_dir/recup*; do - if [ -d "$d" ]; then - echo "Linking $d" - pushd $d >/dev/null - find -type f | while read k; do - file="$(basename "$k")" - src="$(realpath "$k")" - ext="$(echo "${file##*.}" | tr '[:upper:]' '[:lower:]')" - ext_dir="$out_dir/$ext" - if [ "${file##*.}" = "$file" ]; then - ext_dir="$out_dir/_MISC_" - elif [ "$ext" = "jpg" ] && [ "${file:0:1}" = "t" ]; then - ext_dir="$out_dir/jpg-thumbnail" - fi - #echo " $file -> $ext_dir" - [ -d "$ext_dir" ] || mkdir -p "$ext_dir" - ln "$src" "$ext_dir" - done - popd >/dev/null - else - echo "ERROR: '$d' not a directory" - fi -done - -## Check the files output by photorec for corruption -pushd "$out_dir" >/dev/null - -# Check archives with 7-Zip -#for d in 7z bz2 gz lzh lzo rar tar xz zip; do -# if [ -d "$d" ]; then -# echo "Checking $d files" -# pushd "$d" >/dev/null -# for f in *; do -# if ! 7z t "$f" >/dev/null 2>&1; then -# #echo " BAD: $f" -# [ -d "$bad_dir/$d" ] || mkdir -p "$bad_dir/$d" -# mv -n "$f" "$bad_dir/$d/$f" -# fi -# done -# popd >/dev/null -# fi -#done - -# Check Audio/Video files with ffprobe -for d in avi flac flv m4a m4p m4v mkv mid mov mp2 mp3 mp4 mpg mpg2 ogg ts vob wav; do - if [ -d "$d" ]; then - echo "Checking $d files" - pushd "$d" >/dev/null - for f in *; do - if ! ffprobe "$f" >/dev/null 2>&1; then - #echo " BAD: $f" - [ -d "$bad_dir/$d" ] || mkdir -p "$bad_dir/$d" - mv -n "$f" "$bad_dir/$d/$f" - fi - done - popd >/dev/null - fi -done - -# Check .doc files with antiword -if [ -d "doc" ]; then - echo "Checking doc files" - pushd "doc" >/dev/null - for f in *doc; do - if ! antiword "$f" >/dev/null 2>&1; then - #echo " BAD: $f" - [ -d "$bad_dir/doc" ] || mkdir -p "$bad_dir/doc" - mv -n "$f" "$bad_dir/doc/$f" - fi - done - popd >/dev/null -fi - -# Check .docx files with 7z and grep -if [ -d "docx" ]; then - echo "Checking docx files" - pushd "docx" >/dev/null - for f in *docx; do - if ! 7z l "$f" | grep -q -s "word/document.xml"; then - #echo " BAD: $f" - [ -d "$bad_dir/docx" ] || mkdir -p "$bad_dir/docx" - mv -n "$f" "$bad_dir/docx/$f" - fi - done - popd >/dev/null -fi - -# Sort pictures by date (only for common camera formats) -for d in jpg mrw orf raf raw rw2 tif x3f; do - if [ -d "$d" ]; then - echo "Sorting $d files by date" - pushd "$d" >/dev/null - for f in *; do - date_dir="$(date -d "$(stat -c %y "$f")" +"%F")" - [ -d "$date_dir" ] || mkdir "$date_dir" - mv -n "$f" "$date_dir/" - done - popd >/dev/null - fi -done - -# Sort mov files by encoded date -if [ -d "mov" ]; then - echo "Sorting mov files by date" - pushd "mov" >/dev/null - for f in *mov; do - enc_date="$(mediainfo "$f" | grep -i "Encoded date" | head -1 | sed -r 's/.*: //')" - date_dir="$(date -d "$enc_date" +"%F")" - echo "$date_dir" | grep -E -q -s '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' || date_dir="Unknown Date" - [ -d "$date_dir" ] || mkdir "$date_dir" - mv -n "$f" "$date_dir/" - done - popd >/dev/null -fi - -## sort audio files by tags - -## sort matroska files by metadata - -## return to original dir -popd >/dev/null -