Add wk.kit.tools
For code related to downloading, finding, and running tools on the kit.
This commit is contained in:
parent
65cb8481bc
commit
b8335188ce
3 changed files with 96 additions and 10 deletions
|
|
@ -3,5 +3,7 @@
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
from wk.kit import tools
|
||||||
|
|
||||||
if platform.system() == 'Linux':
|
if platform.system() == 'Linux':
|
||||||
from wk.kit import ufd
|
from wk.kit import ufd
|
||||||
|
|
|
||||||
79
scripts/wk/kit/tools.py
Normal file
79
scripts/wk/kit/tools.py
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
"""WizardKit: Tool Functions"""
|
||||||
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import pathlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from wk.exe import popen_program, run_program
|
||||||
|
|
||||||
|
|
||||||
|
# STATIC VARIABLES
|
||||||
|
ARCH = '64' if sys.maxsize > 2**32 else '32'
|
||||||
|
|
||||||
|
|
||||||
|
# "GLOBAL" VARIABLES
|
||||||
|
CACHED_DIRS = {}
|
||||||
|
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
def find_kit_dir(name=None):
|
||||||
|
"""Find folder in kit, returns pathlib.Path.
|
||||||
|
|
||||||
|
Search is performed in the script's path and then recursively upwards.
|
||||||
|
If name is given then search for that instead."""
|
||||||
|
cur_path = pathlib.Path(__file__).resolve().parent
|
||||||
|
search = name if name else '.bin'
|
||||||
|
|
||||||
|
# Search
|
||||||
|
if name in CACHED_DIRS:
|
||||||
|
return CACHED_DIRS[name]
|
||||||
|
while not cur_path.match(cur_path.anchor):
|
||||||
|
if cur_path.joinpath(search).exists():
|
||||||
|
break
|
||||||
|
cur_path = cur_path.parent
|
||||||
|
|
||||||
|
# Check
|
||||||
|
if cur_path.match(cur_path.anchor):
|
||||||
|
raise FileNotFoundError(f'Failed to find kit dir, {name=}')
|
||||||
|
if name:
|
||||||
|
cur_path = cur_path.joinpath(name)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
CACHED_DIRS[name] = cur_path
|
||||||
|
return cur_path
|
||||||
|
|
||||||
|
|
||||||
|
def get_tool_path(folder, name):
|
||||||
|
"""Get tool path, returns pathlib.Path"""
|
||||||
|
bin_dir = find_kit_dir('.bin')
|
||||||
|
|
||||||
|
# "Search"
|
||||||
|
tool_path = bin_dir.joinpath(f'{folder}/{name}{ARCH}.exe')
|
||||||
|
if not tool_path.exists():
|
||||||
|
tool_path = tool_path.with_stem(name)
|
||||||
|
|
||||||
|
# Missing?
|
||||||
|
if not tool_path.exists():
|
||||||
|
raise FileNotFoundError(f'Failed to find tool, {folder=}, {name=}')
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return tool_path
|
||||||
|
|
||||||
|
|
||||||
|
def run_tool(folder, name, *args, popen=False):
|
||||||
|
"""Run tool from kit."""
|
||||||
|
cmd = [get_tool_path(folder, name), *args]
|
||||||
|
proc = None
|
||||||
|
|
||||||
|
# Run
|
||||||
|
if popen:
|
||||||
|
proc = popen_program(cmd)
|
||||||
|
else:
|
||||||
|
proc = run_program(cmd, check=False)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return proc
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print("This file is not meant to be called directly.")
|
||||||
|
|
@ -7,16 +7,21 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from wk.cfg.main import KIT_NAME_FULL
|
from wk.cfg.main import KIT_NAME_FULL
|
||||||
from wk.exe import get_procs, run_program, popen_program, wait_for_procs
|
from wk.exe import get_procs, run_program, popen_program, wait_for_procs
|
||||||
from wk.log import format_log_path, update_log_path
|
from wk.kit.tools import run_tool
|
||||||
from wk.os.win import * # pylint: disable=wildcard-import
|
from wk.log import format_log_path, update_log_path
|
||||||
from wk.std import (
|
from wk.os.win import reg_delete_value, reg_read_value, reg_set_value
|
||||||
GenericError, GenericWarning, TryAndPrint,
|
from wk.std import (
|
||||||
|
GenericError,
|
||||||
|
GenericWarning,
|
||||||
|
TryAndPrint,
|
||||||
abort,
|
abort,
|
||||||
clear_screen, print_info,
|
clear_screen,
|
||||||
pause, sleep,
|
pause,
|
||||||
|
print_info,
|
||||||
set_title,
|
set_title,
|
||||||
|
sleep,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -43,7 +48,7 @@ def end_session():
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
# Disable Autologon
|
# Disable Autologon
|
||||||
# TODO: Run Autologon
|
run_tool('Sysinternals', 'Autologon')
|
||||||
reg_set_value(
|
reg_set_value(
|
||||||
'HKLM', r'Software\Microsoft\Windows NT\CurrentVersion\Winlogon',
|
'HKLM', r'Software\Microsoft\Windows NT\CurrentVersion\Winlogon',
|
||||||
'AutoAdminLogon', '0', 'SZ',
|
'AutoAdminLogon', '0', 'SZ',
|
||||||
|
|
@ -111,7 +116,7 @@ def init_session():
|
||||||
# One-time tasks
|
# One-time tasks
|
||||||
# TODO: Backup Registry
|
# TODO: Backup Registry
|
||||||
# TODO: Enable and create restore point
|
# TODO: Enable and create restore point
|
||||||
# TODO: Run Autologon
|
run_tool('Sysinternals', 'Autologon')
|
||||||
# TODO: Disable Windows updates
|
# TODO: Disable Windows updates
|
||||||
# TODO: Reset Windows updates
|
# TODO: Reset Windows updates
|
||||||
reboot()
|
reboot()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue