Add Clock Sync option to HW-Diags menu under macOS
This commit is contained in:
parent
61f2b00a2a
commit
9478000cdf
1 changed files with 34 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ MENU_ACTIONS = (
|
||||||
'Audio Test',
|
'Audio Test',
|
||||||
'Keyboard Test',
|
'Keyboard Test',
|
||||||
'Network Test',
|
'Network Test',
|
||||||
|
'Clock Sync',
|
||||||
'Start',
|
'Start',
|
||||||
'Quit')
|
'Quit')
|
||||||
MENU_ACTIONS_SECRET = (
|
MENU_ACTIONS_SECRET = (
|
||||||
|
|
@ -367,6 +368,17 @@ class State():
|
||||||
with open(f'{debug_dir}/smc.data', 'a') as _f:
|
with open(f'{debug_dir}/smc.data', 'a') as _f:
|
||||||
_f.write('\n'.join(data))
|
_f.write('\n'.join(data))
|
||||||
|
|
||||||
|
def update_clock(self):
|
||||||
|
"""Update 'Started' pane following clock sync."""
|
||||||
|
tmux.respawn_pane(
|
||||||
|
pane_id=self.panes['Started'],
|
||||||
|
text=std.color_string(
|
||||||
|
['Started', time.strftime("%Y-%m-%d %H:%M %Z")],
|
||||||
|
['BLUE', None],
|
||||||
|
sep='\n',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def update_progress_pane(self):
|
def update_progress_pane(self):
|
||||||
"""Update progress pane."""
|
"""Update progress pane."""
|
||||||
report = []
|
report = []
|
||||||
|
|
@ -421,6 +433,7 @@ def audio_test_linux():
|
||||||
|
|
||||||
|
|
||||||
def build_menu(cli_mode=False, quick_mode=False):
|
def build_menu(cli_mode=False, quick_mode=False):
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
"""Build main menu, returns wk.std.Menu."""
|
"""Build main menu, returns wk.std.Menu."""
|
||||||
menu = std.Menu(title=None)
|
menu = std.Menu(title=None)
|
||||||
|
|
||||||
|
|
@ -456,6 +469,13 @@ def build_menu(cli_mode=False, quick_mode=False):
|
||||||
for name in ('Matrix', 'Network Test', 'Tubes'):
|
for name in ('Matrix', 'Network Test', 'Tubes'):
|
||||||
menu.actions[name]['Disabled'] = True
|
menu.actions[name]['Disabled'] = True
|
||||||
|
|
||||||
|
# Live macOS actions
|
||||||
|
if os.path.exists('.wk-live-macos'):
|
||||||
|
menu.actions['Clock Sync']['Separator'] = True
|
||||||
|
else:
|
||||||
|
menu.actions['Clock Sync']['Disabled'] = True
|
||||||
|
menu.actions['Clock Sync']['Hidden'] = True
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
|
|
@ -1149,6 +1169,8 @@ def main():
|
||||||
action = keyboard_test
|
action = keyboard_test
|
||||||
elif 'Network Test' in selection:
|
elif 'Network Test' in selection:
|
||||||
action = network_test
|
action = network_test
|
||||||
|
elif 'Clock Sync' in selection:
|
||||||
|
action = sync_clock
|
||||||
|
|
||||||
# Run simple test
|
# Run simple test
|
||||||
if action:
|
if action:
|
||||||
|
|
@ -1159,6 +1181,8 @@ def main():
|
||||||
std.print_warning('Aborted.')
|
std.print_warning('Aborted.')
|
||||||
std.print_standard('')
|
std.print_standard('')
|
||||||
std.pause('Press Enter to return to main menu...')
|
std.pause('Press Enter to return to main menu...')
|
||||||
|
if 'Clock Sync' in selection:
|
||||||
|
state.update_clock()
|
||||||
|
|
||||||
# Secrets
|
# Secrets
|
||||||
if 'Matrix' in selection:
|
if 'Matrix' in selection:
|
||||||
|
|
@ -1406,5 +1430,15 @@ def stop_mprime(proc_mprime):
|
||||||
set_apple_fan_speed('auto')
|
set_apple_fan_speed('auto')
|
||||||
|
|
||||||
|
|
||||||
|
def sync_clock():
|
||||||
|
"""Sync clock under macOS using sntp."""
|
||||||
|
cmd = ['sudo', 'sntp', '-Ss', 'us.pool.ntp.org']
|
||||||
|
proc = exe.run_program(cmd, check=False)
|
||||||
|
if proc.returncode:
|
||||||
|
# Assuming we're running under an older version of macOS
|
||||||
|
cmd[2] = '-s'
|
||||||
|
exe.run_program(cmd, check=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print("This file is not meant to be called directly.")
|
print("This file is not meant to be called directly.")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue