diff options
-rwxr-xr-x | src/op_mode/powerctrl.py | 4 | ||||
-rwxr-xr-x | src/op_mode/show_ipsec_sa.py | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py index a6188ec74..d4c6d47f7 100755 --- a/src/op_mode/powerctrl.py +++ b/src/op_mode/powerctrl.py @@ -97,7 +97,7 @@ def execute_shutdown(time, reboot = True, ask=True): elif len(time) == 1: # Assume the argument is just time ts = parse_time(time[0]) - if ts: + if ts is not None: cmd = check_output(["/sbin/shutdown", action, time[0]], stderr=STDOUT) else: sys.exit("Invalid time \"{0}\". The valid format is HH:MM".format(time[0])) @@ -105,7 +105,7 @@ def execute_shutdown(time, reboot = True, ask=True): # Assume it's date and time ts = parse_time(time[0]) ds = parse_date(time[1]) - if ts and ds: + if ts is not None and ds: t = datetime.combine(ds, ts) td = t - datetime.now() t2 = 1 + int(td.total_seconds())//60 # Get total minutes diff --git a/src/op_mode/show_ipsec_sa.py b/src/op_mode/show_ipsec_sa.py index 4e65daf1e..9955dead9 100755 --- a/src/op_mode/show_ipsec_sa.py +++ b/src/op_mode/show_ipsec_sa.py @@ -7,6 +7,13 @@ import subprocess import tabulate import hurry.filesize + +def convert(text): + return int(text) if text.isdigit() else text.lower() + +def alphanum_key(key): + return [convert(c) for c in re.split('([0-9]+)', str(key))] + def parse_conn_spec(s): try: # Example: ESTABLISHED 14 seconds ago, 10.0.0.2[foo]...10.0.0.1[10.0.0.1] @@ -85,6 +92,7 @@ for conn in connections: status_line = list(map(lambda x: "N/A" if x is None else x, status_line)) status_data.append(status_line) +status_data = sorted(status_data, key=alphanum_key) headers = ["Connection", "State", "Up", "Bytes In/Out", "Remote address", "Remote ID", "Proposal"] output = tabulate.tabulate(status_data, headers) print(output) |