Merge branch 'project-overhaul' into dev

This commit is contained in:
2Shirt 2020-01-30 13:30:16 -07:00
commit da4b50afb4
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
10 changed files with 44 additions and 31 deletions

View file

@ -2,6 +2,12 @@
#
## Wizard Kit: TMUX Launcher
# Live macOS env workaround
tmux_args=()
if [[ -e "/.wk-live-macos" ]]; then
tmux_args=(-f "/etc/tmux.conf" -S "$(mktemp).socket")
fi
function ask() {
while :; do
read -p "$1 [Y/N] " -r answer
@ -25,24 +31,24 @@ function launch_in_tmux() {
[[ -n "${TMUX_CMD:-}" ]] || return $(err "Required variable missing (TMUX_CMD)")
# Check for running session
if tmux list-session | grep -q "$SESSION_NAME"; then
if tmux "${tmux_args[@]}" list-session | grep -q "$SESSION_NAME"; then
echo "WARNING: tmux session $SESSION_NAME already exists."
echo ""
if ask "Connect to current session?"; then
if [[ -n "${TMUX:-}" ]]; then
# Running inside TMUX, switch to session
tmux switch-client -t "$SESSION_NAME"
tmux "${tmux_args[@]}" switch-client -t "$SESSION_NAME"
if ! jobs %% >/dev/null 2>&1; then
# No running jobs, try exiting abandoned tmux session
exit 0
fi
else
# Running outside TMUX, attach to session
tmux attach-session -t "$SESSION_NAME"
tmux "${tmux_args[@]}" attach-session -t "$SESSION_NAME"
fi
return 0
elif ask "Kill current session and start new session?"; then
tmux kill-session -t "$SESSION_NAME" || \
tmux "${tmux_args[@]}" kill-session -t "$SESSION_NAME" || \
die "Failed to kill session: $SESSION_NAME"
else
echo "Aborted."
@ -53,16 +59,16 @@ function launch_in_tmux() {
# Start session
if [[ -n "${TMUX:-}" ]]; then
# Running inside TMUX, save current session/window names
ORIGINAL_SESSION_NAME="$(tmux display-message -p '#S')"
ORIGINAL_WINDOW_NAME="$(tmux display-message -p '#W')"
tmux rename-session "$SESSION_NAME"
tmux rename-window "$WINDOW_NAME"
ORIGINAL_SESSION_NAME="$(tmux "${tmux_args[@]}" display-message -p '#S')"
ORIGINAL_WINDOW_NAME="$(tmux "${tmux_args[@]}" display-message -p '#W')"
tmux "${tmux_args[@]}" rename-session "$SESSION_NAME"
tmux "${tmux_args[@]}" rename-window "$WINDOW_NAME"
"$TMUX_CMD" "$@"
# Restore previous session/window names
tmux rename-session "${ORIGINAL_SESSION_NAME}"
tmux rename-window "${ORIGINAL_WINDOW_NAME}"
tmux "${tmux_args[@]}" rename-session "${ORIGINAL_SESSION_NAME}"
tmux "${tmux_args[@]}" rename-window "${ORIGINAL_WINDOW_NAME}"
else
# Running outside TMUX, start/attach to session
tmux new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$TMUX_CMD" "$@"
tmux "${tmux_args[@]}" new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$TMUX_CMD" "$@"
fi
}

View file

@ -3,6 +3,7 @@
import json
import logging
import os
import re
import subprocess
@ -77,6 +78,10 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
'shell': shell,
}
# Strip sudo if appropriate
if cmd[0] == 'sudo' and os.name == 'posix' and os.geteuid() == 0:
cmd.pop(0)
# Add additional kwargs if applicable
for key in 'check cwd encoding errors stderr stdin stdout'.split():
if key in kwargs:

View file

@ -198,7 +198,11 @@ class State():
)
else:
# No blocking errors encountered, check for minor attribute failures
if not disk.check_attributes(only_blocking=False):
if ('Disk Attributes' in disk.tests
and not disk.tests['Disk Attributes'].failed
and not disk.check_attributes(only_blocking=False)):
# Mid-diag failure detected
LOG.warning('Disk attributes failure detected during diagnostics')
disk.tests['Disk Attributes'].failed = True
disk.tests['Disk Attributes'].set_status('Failed')
@ -383,7 +387,6 @@ def audio_test():
"""Run an OS-specific audio test."""
if PLATFORM == 'Linux':
audio_test_linux()
# TODO: Add tests for other OS
def audio_test_linux():
@ -431,10 +434,10 @@ def build_menu(cli_mode=False, quick_mode=False):
# Compatibility checks
if PLATFORM != 'Linux':
for name in ('Audio Test', 'Keyboard Test', 'Network Test'):
for name in ('Audio Test', 'Keyboard Test'):
menu.actions[name]['Disabled'] = True
if PLATFORM not in ('Darwin', 'Linux'):
for name in ('Matrix', 'Tubes'):
for name in ('Matrix', 'Network Test', 'Tubes'):
menu.actions[name]['Disabled'] = True
# Done

View file

@ -368,13 +368,9 @@ class Disk(BaseObj):
try:
details = self.smartctl['ata_smart_data']['self_test']
except (KeyError, TypeError):
# Assuming disk lacks SMART support, ignore and return nearly empty dict.
# Assuming disk lacks SMART support, ignore and return empty dict.
pass
# Ensure status is present even if empty
if 'status' not in details:
details['status'] = {}
# Done
return details
@ -385,7 +381,6 @@ class Disk(BaseObj):
aligned = is_4k_aligned_macos(self.details)
elif PLATFORM == 'Linux':
aligned = is_4k_aligned_linux(self.path, self.details['phy-sec'])
#TODO: Add checks for other OS
return aligned
@ -502,11 +497,11 @@ class Disk(BaseObj):
_f.write(f'{header_str}\nSMART self-test status:\n {status_str}')
# Check if finished
if 'remaining_percent' not in test_details['status']:
if 'remaining_percent' not in test_details.get('status', {}):
finished = True
break
elif 'remaining_percent' in test_details['status']:
elif 'remaining_percent' in test_details.get('status', {}):
started = True
# Check result

View file

@ -1,8 +1,5 @@
"""WizardKit: UFD Functions"""
# vim: sts=2 sw=2 ts=2
# TODO: Replace some lsblk usage with hw_obj?
# TODO: Reduce imports if possible
# TODO: Needs testing
import logging
import os

View file

@ -13,7 +13,10 @@ from wk.io import non_clobber_path
# STATIC VARIABLES
if os.name == 'nt':
if os.path.exists('/.wk-live-macos'):
# Workaround for live macOS env
DEFAULT_LOG_DIR = '/var/log/WizardKit'
elif os.name == 'nt':
# Example: "C:\WK\1955-11-05\WizardKit"
DEFAULT_LOG_DIR = (
f'{os.environ.get("SYSTEMDRIVE", "C:")}/'

View file

@ -181,7 +181,6 @@ def share_is_mounted(details):
if row['source'] == f'//{details["Address"]}/{details["Share"]}':
mounted = True
break
#TODO: Check mount status under Windows
#elif PLATFORM == 'Windows':
# Done

View file

@ -179,7 +179,6 @@ def running_as_root():
def scan_corestorage_container(container, timeout=300):
"""Scan CoreStorage container for inner volumes, returns list."""
# TODO: Test Scanning CoreStorage containers
detected_volumes = {}
inner_volumes = []
log_path = format_log_path(log_name=f'{container.path.name}_testdisk')

View file

@ -15,7 +15,7 @@ from wk.std import GenericError, GenericWarning, sleep
# STATIC VARIABLES
LOG = logging.getLogger(__name__)
OS_VERSION = float(platform.win32_ver()[0]) # TODO: Check if Win8.1 returns '8'
OS_VERSION = float(platform.win32_ver()[0])
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
SLMGR = pathlib.Path(f'{os.environ.get("SYSTEMROOT")}/System32/slmgr.vbs')

View file

@ -134,6 +134,8 @@ class Menu():
checkmark = '*'
if 'DISPLAY' in os.environ or PLATFORM == 'Darwin':
checkmark = ''
if os.path.exists('/.wk-live-macos'):
checkmark = '*'
display_name = f'{index if index else name[:1].upper()}: '
if not (index and index >= 10):
display_name = f' {display_name}'
@ -726,7 +728,11 @@ def choice(choices, prompt='答えろ!'):
def clear_screen():
"""Simple wrapper for clear/cls."""
cmd = 'cls' if os.name == 'nt' else 'clear'
subprocess.run(cmd, check=False, shell=True, stderr=subprocess.PIPE)
proc = subprocess.run(cmd, check=False, shell=True, stderr=subprocess.PIPE)
# Workaround for live macOS env
if proc.returncode != 0:
print('\033c')
def color_string(strings, colors, sep=' '):