From 443b678d8a56531edccd0ca05560c2c54bd9baaa Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Tue, 2 May 2017 14:54:18 -0400 Subject: [PATCH 1/2] Add power off detection --- confluent_client/bin/confetty | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 64764a5e..f53649e6 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -576,7 +576,7 @@ def conserver_command(filehandle, localcommand): tlvdata.send(session.connection, {'operation': 'break', 'path': currconsole}) print("break sent]\r") - elif localcommand[0] == 'p': # print + elif localcommand[0] == 'p': # power cmdlen += 1 localcommand = get_command_bytes(filehandle, localcommand, cmdlen) @@ -651,6 +651,12 @@ def conserver_command(filehandle, localcommand): else: print("Unknown power state.]\r") + global powerstate + powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] + powertime = time.time() + if powerstate == 'off': + sys.stdout.write("\r\n[powered off]\r\n") + elif localcommand[0] == '?': print("help]\r") print(". disconnect\r") @@ -757,6 +763,8 @@ elif shellargs: do_command(command, netserver) quitconfetty(fullexit=True, fixterm=False) +powerstate = None +powertime = None while inconsole or not doexit: if inconsole: rdylist, _, _ = select.select( @@ -810,6 +818,11 @@ while inconsole or not doexit: myinput = check_escape_seq(myinput, fh) if myinput: tlvdata.send(session.connection, myinput) + if powerstate is None or powertime < time.time() - 60: # Check powerstate every 60 seconds + powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] + powertime = time.time() + if powerstate == 'off': + sys.stdout.write("\r\n[powered off]\r\n") else: currcommand = prompt() try: From f4c191c280b26c85dfbc278fe0748a6ed8967e41 Mon Sep 17 00:00:00 2001 From: Amanda Duffy Date: Tue, 2 May 2017 15:30:39 -0400 Subject: [PATCH 2/2] Fix power off detection --- confluent_client/bin/confetty | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index f53649e6..89296ff6 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -651,11 +651,7 @@ def conserver_command(filehandle, localcommand): else: print("Unknown power state.]\r") - global powerstate - powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] - powertime = time.time() - if powerstate == 'off': - sys.stdout.write("\r\n[powered off]\r\n") + check_power_state() elif localcommand[0] == '?': print("help]\r") @@ -765,6 +761,25 @@ elif shellargs: powerstate = None powertime = None + + +def check_power_state(): + global powerstate, powertime + for rsp in session.read('/nodes/' + consolename + '/power/state'): + if type(rsp) == dict and 'state' in rsp: + powerstate = rsp['state']['value'] + powertime = time.time() + if powerstate == 'off': + sys.stdout.write("\r\n[powered off]\r\n") + elif type(rsp) == dict and '_requestdone' in rsp: + break + elif type(rsp) == dict: + updatestatus(rsp) + else: + sys.stdout.write(rsp) + sys.stdout.flush() + + while inconsole or not doexit: if inconsole: rdylist, _, _ = select.select( @@ -819,10 +834,8 @@ while inconsole or not doexit: if myinput: tlvdata.send(session.connection, myinput) if powerstate is None or powertime < time.time() - 60: # Check powerstate every 60 seconds - powerstate = list(session.read('/nodes/' + consolename + '/power/state'))[0]['state']['value'] - powertime = time.time() - if powerstate == 'off': - sys.stdout.write("\r\n[powered off]\r\n") + check_power_state() + else: currcommand = prompt() try: