From c6b3e11e04c089b9d0e489f98886f1785414c3f4 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Sun, 20 Oct 2019 18:29:36 +0200 Subject: [PATCH] new: new --skip-session for manual mode to skip session parsing --- bin/pwnagotchi | 23 +++++++++++++---------- pwnagotchi/log.py | 41 ++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/bin/pwnagotchi b/bin/pwnagotchi index a5412f3..cb9d982 100755 --- a/bin/pwnagotchi +++ b/bin/pwnagotchi @@ -21,6 +21,9 @@ if __name__ == '__main__': help='If this file exists, configuration will be merged and this will override default values.') parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.") + parser.add_argument('--skip-session', dest="skip_session", action="store_true", default=False, + help="Skip last session parsing in manual mode.") + parser.add_argument('--clear', dest="do_clear", action="store_true", default=False, help="Clear the ePaper display and exit.") @@ -49,16 +52,16 @@ if __name__ == '__main__': elif args.do_manual: logging.info("entering manual mode ...") - agent.last_session.parse() - - logging.info( - "the last session lasted %s (%d completed epochs, trained for %d), average reward:%s (min:%s max:%s)" % ( - agent.last_session.duration_human, - agent.last_session.epochs, - agent.last_session.train_epochs, - agent.last_session.avg_reward, - agent.last_session.min_reward, - agent.last_session.max_reward)) + agent.last_session.parse(args.skip_session) + if not args.skip_session: + logging.info( + "the last session lasted %s (%d completed epochs, trained for %d), average reward:%s (min:%s max:%s)" % ( + agent.last_session.duration_human, + agent.last_session.epochs, + agent.last_session.train_epochs, + agent.last_session.avg_reward, + agent.last_session.min_reward, + agent.last_session.max_reward)) while True: display.on_manual_mode(agent.last_session) diff --git a/pwnagotchi/log.py b/pwnagotchi/log.py index f5c235e..dda28e0 100644 --- a/pwnagotchi/log.py +++ b/pwnagotchi/log.py @@ -167,30 +167,33 @@ class LastSession(object): self.duration_human = ', '.join(self.duration_human) self.avg_reward /= (self.epochs if self.epochs else 1) - def parse(self): - logging.debug("parsing last session logs ...") + def parse(self, skip=False): + if skip: + logging.debug("skipping parsing of the last session logs ...") + else: + logging.debug("parsing last session logs ...") - lines = [] + lines = [] - if os.path.exists(self.path): - with FileReadBackwards(self.path, encoding="utf-8") as fp: - for line in fp: - line = line.strip() - if line != "" and line[0] != '[': - continue - lines.append(line) - if LastSession.START_TOKEN in line: - break - lines.reverse() + if os.path.exists(self.path): + with FileReadBackwards(self.path, encoding="utf-8") as fp: + for line in fp: + line = line.strip() + if line != "" and line[0] != '[': + continue + lines.append(line) + if LastSession.START_TOKEN in line: + break + lines.reverse() - if len(lines) == 0: - lines.append("Initial Session"); + if len(lines) == 0: + lines.append("Initial Session"); - self.last_session = lines - self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest() - self.last_saved_session_id = self._get_last_saved_session_id() + self.last_session = lines + self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest() + self.last_saved_session_id = self._get_last_saved_session_id() - self._parse_stats() + self._parse_stats() self.parsed = True def is_new(self):