Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
2Shirt 2019-06-12 16:01:03 -06:00
commit 8f792ac76d
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
8 changed files with 94 additions and 78 deletions

View file

@ -2,42 +2,10 @@
# #
## Wizard Kit: ddrescue TUI Launcher ## Wizard Kit: ddrescue TUI Launcher
source launch-in-tmux
SESSION_NAME="ddrescue-tui" SESSION_NAME="ddrescue-tui"
WINDOW_NAME="ddrescue TUI" WINDOW_NAME="ddrescue TUI"
MENU="ddrescue-tui-menu" TMUX_CMD="ddrescue-tui-menu"
function ask() {
while :; do
read -p "$1 " -r answer
if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then
return 0
elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then
return 1
fi
done
}
die () {
echo "$0:" "$@" >&2
exit 1
}
# Check for running session
if tmux list-session | grep -q "$SESSION_NAME"; then
echo "WARNING: tmux session $SESSION_NAME already exists."
echo ""
if ask "Kill current session?"; then
tmux kill-session -t "$SESSION_NAME" || \
die "Failed to kill session: $SESSION_NAME"
else
echo "Aborted."
echo ""
echo -n "Press Enter to exit... "
read -r
exit 0
fi
fi
# Start session
tmux new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$MENU" $*
launch_in_tmux "$@"

View file

@ -45,6 +45,7 @@ if __name__ == '__main__':
# Done # Done
print_standard('\nDone.') print_standard('\nDone.')
pause("Press Enter to exit...") pause("Press Enter to exit...")
tmux_switch_client()
exit_script() exit_script()
except GenericAbort: except GenericAbort:
abort() abort()
@ -55,6 +56,7 @@ if __name__ == '__main__':
print_error(msg) print_error(msg)
abort() abort()
except SystemExit as sys_exit: except SystemExit as sys_exit:
tmux_switch_client()
exit_script(sys_exit.code) exit_script(sys_exit.code)
except: except:
major_exception() major_exception()

View file

@ -281,6 +281,7 @@ class RecoveryState():
raise GenericError('Unsupported mode') raise GenericError('Unsupported mode')
self.get_smart_source() self.get_smart_source()
self.set_working_dir() self.set_working_dir()
os.makedirs(global_vars['LogDir'], exist_ok=True)
def add_block_pair(self, source, dest): def add_block_pair(self, source, dest):
"""Run safety checks and append new BlockPair to internal list.""" """Run safety checks and append new BlockPair to internal list."""
@ -930,7 +931,7 @@ def menu_ddrescue(source_path, dest_path, run_mode):
pause('Press Enter to exit... ') pause('Press Enter to exit... ')
# Done # Done
run_program(['tmux', 'kill-window']) tmux_kill_all_panes()
exit_script() exit_script()

View file

@ -1277,7 +1277,9 @@ def run_hw_tests(state):
print_standard(' ') print_standard(' ')
# Upload for review # Upload for review
if ENABLED_UPLOAD_DATA and ask('Upload results for review?'): if (ENABLED_UPLOAD_DATA
and DEBUG_MODE
and ask('Upload results for review?')):
try_and_print( try_and_print(
message='Saving debug reports...', message='Saving debug reports...',
function=save_debug_reports, function=save_debug_reports,

View file

@ -141,6 +141,18 @@ def tmux_split_window(
return result.stdout.decode().strip() return result.stdout.decode().strip()
def tmux_switch_client(target_session=None):
"""Switch to target tmux session, or previous if none specified."""
cmd = ['tmux', 'switch-client']
if target_session:
cmd.extend(['-t', target_session])
else:
# Switch to previous instead
cmd.append('-p')
run_program(cmd, check=False)
def tmux_update_pane( def tmux_update_pane(
pane_id, command=None, working_dir=None, pane_id, command=None, working_dir=None,
text=None, watch=None, watch_cmd='cat'): text=None, watch=None, watch_cmd='cat'):

View file

@ -1,46 +1,11 @@
#!/bin/bash #!/bin/bash
# #
## Wizard Kit: HW Diagnostics - Menu Launcher ## Wizard Kit: HW Diagnostics Launcher
source launch-in-tmux
SESSION_NAME="hw-diags" SESSION_NAME="hw-diags"
WINDOW_NAME="Hardware Diagnostics" WINDOW_NAME="Hardware Diagnostics"
MENU="hw-diags-menu" TMUX_CMD="hw-diags-menu"
function ask() {
while :; do
read -p "$1 [Y/N] " -r answer
if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then
return 0
elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then
return 1
fi
done
}
die () {
echo "$0:" "$@" >&2
exit 1
}
# Check for running session
if tmux list-session | grep -q "$SESSION_NAME"; then
echo "WARNING: tmux session $SESSION_NAME already exists."
echo ""
if ask "Connect to current session?"; then
# Do nothing, the command below will attach/connect
echo ""
elif ask "Kill current session and start new session?"; then
tmux kill-session -t "$SESSION_NAME" || \
die "Failed to kill session: $SESSION_NAME"
else
echo "Aborted."
echo ""
echo -n "Press Enter to exit... "
read -r
exit 0
fi
fi
# Start session
tmux new-session -A -s "$SESSION_NAME" -n "$WINDOW_NAME" "$MENU" $*
launch_in_tmux "$@"

View file

@ -23,6 +23,7 @@ if __name__ == '__main__':
sleep(1) sleep(1)
pause('Press Enter to exit...') pause('Press Enter to exit...')
except SystemExit as sys_exit: except SystemExit as sys_exit:
tmux_switch_client()
exit_script(sys_exit.code) exit_script(sys_exit.code)
except: except:
# Cleanup # Cleanup
@ -59,6 +60,7 @@ if __name__ == '__main__':
# Done # Done
tmux_kill_all_panes() tmux_kill_all_panes()
tmux_switch_client()
exit_script() exit_script()
# vim: sts=2 sw=2 ts=2 # vim: sts=2 sw=2 ts=2

64
.bin/Scripts/launch-in-tmux Executable file
View file

@ -0,0 +1,64 @@
#!/bin/bash
#
## Wizard Kit: TMUX Launcher
function ask() {
while :; do
read -p "$1 [Y/N] " -r answer
if echo "$answer" | grep -Eiq '^(y|yes|sure)$'; then
return 0
elif echo "$answer" | grep -Eiq '^(n|no|nope)$'; then
return 1
fi
done
}
die () {
echo "$0:" "$@" >&2
exit 1
}
function launch_in_tmux() {
# Check for required vars
[[ -n "${SESSION_NAME:-}" ]] || die "Required variable missing (SESSION_NAME)"
[[ -n "${WINDOW_NAME:-}" ]] || die "Required variable missing (WINDOW_NAME)"
[[ -n "${TMUX_CMD:-}" ]] || die "Required variable missing (TMUX_CMD)"
# Check for running session
if tmux 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"
else
# Running outside TMUX, attach to session
tmux attach-session -t "$SESSION_NAME"
fi
exit 0
elif ask "Kill current session and start new session?"; then
tmux kill-session -t "$SESSION_NAME" || \
die "Failed to kill session: $SESSION_NAME"
else
echo "Aborted."
echo ""
echo -n "Press Enter to exit... "
read -r
exit 0
fi
fi
# Start/Rename session
if [[ -n "${TMUX:-}" ]]; then
# Running inside TMUX, rename session/window and open the menu
tmux rename-session "$SESSION_NAME"
tmux rename-window "$WINDOW_NAME"
"$TMUX_CMD" "$@"
tmux rename-session "${SESSION_NAME}_DONE"
tmux rename-window "${WINDOW_NAME}_DONE"
else
# Running outside TMUX, start/attach to session
tmux new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$TMUX_CMD" "$@"
fi
}