From 48923c22192e1b0c728fe60f2a89ec7b5bac6805 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 20 Sep 2024 09:36:03 +0000 Subject: [PATCH] autosign, led: improve no sudo handling --- mmgen/autosign.py | 15 ++++++++------- mmgen/led.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index b902c4bf..3a37114e 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -48,9 +48,9 @@ class SwapMgrBase: return ret def disable(self, quiet=False): - self.cfg._util.qmsg_r(f'Disabling {self.desc}...') + self.cfg._util.qmsg_r(f'Attempting to disable {self.desc}...') ret = self.do_disable() - self.cfg._util.qmsg('done') + self.cfg._util.qmsg('success') if not quiet: self.cfg._util.qmsg( f'{capfirst(self.desc)} successfully disabled ({fmt_list(ret, fmt="no_quotes")})' @@ -66,13 +66,14 @@ class SwapMgrBase: for cmd in cmds: run(cmd.split(), check=True) else: - nl = '\n' if op == 'disable' else '' - fs = blue('{a} {b} by executing the following command{c}:\n{d}') - m = nl + fs.format( - a = 'Before continuing, please disable' if op == 'disable' else 'Enable', + pre = 'failure\n' if op == 'disable' else '' + fs = blue('{a} {b} manually by executing the following command{c}:\n{d}') + post = orange('[To prevent this message in the future, enable sudo without a password]') + m = pre + fs.format( + a = 'Please disable' if op == 'disable' else 'Enable', b = self.desc, c = suf(cmds), - d = fmt_list(cmds, indent=' ', fmt='col')) + d = fmt_list(cmds, indent=' ', fmt='col')) + '\n' + post msg(m) if not self.cfg.test_suite: sys.exit(1) diff --git a/mmgen/led.py b/mmgen/led.py index 3ae3ac8f..96fee2f7 100755 --- a/mmgen/led.py +++ b/mmgen/led.py @@ -20,12 +20,12 @@ led: Control the LED on a single-board computer """ -import os,threading +import sys, os, threading from collections import namedtuple from subprocess import run from .util import msg, msg_r, fmt, die, have_sudo -from .color import orange +from .color import blue, orange class LEDControl: @@ -100,9 +100,12 @@ class LEDControl: run(cmd.split(), check=True) write_init_val(init_val) else: - die(2, - f'\nYou do not have access to the {desc} file\n' - f'To allow access, run the following command:\n\n {cmd}') + msg('\n{}\n{}\n{}'.format( + blue(f'You do not have access to the {desc} file'), + blue(f'To allow access, run the following command:\n\n {cmd}'), + orange('[To prevent this message in the future, enable sudo without a password]') + )) + sys.exit(1) check_access(board.status,desc='status LED control')