From 346773f7902b45280568cf1e8913e7aad815c8c9 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Tue, 5 Nov 2019 18:02:36 +0100 Subject: [PATCH] Add max_tries param --- pwnagotchi/defaults.yml | 1 + pwnagotchi/plugins/default/auto-backup.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml index 0d7f9f7..688b416 100644 --- a/pwnagotchi/defaults.yml +++ b/pwnagotchi/defaults.yml @@ -28,6 +28,7 @@ main: auto-backup: enabled: false interval: 1 # every day + max_tries: 0 # 0=infinity files: - /root/brain.nn - /root/brain.json diff --git a/pwnagotchi/plugins/default/auto-backup.py b/pwnagotchi/plugins/default/auto-backup.py index 9b15efc..a033e05 100644 --- a/pwnagotchi/plugins/default/auto-backup.py +++ b/pwnagotchi/plugins/default/auto-backup.py @@ -13,20 +13,14 @@ class AutoBackup(plugins.Plugin): def __init__(self): self.ready = False + self.tries = 0 self.status = StatusFile('/root/.auto-backup') def on_loaded(self): - if 'files' not in self.options or ('files' in self.options and self.options['files'] is None): - logging.error("AUTO-BACKUP: No files to backup.") - return - - if 'interval' not in self.options or ('interval' in self.options and self.options['interval'] is None): - logging.error("AUTO-BACKUP: Interval is not set.") - return - - if 'commands' not in self.options or ('commands' in self.options and self.options['commands'] is None): - logging.error("AUTO-BACKUP: No commands given.") - return + for opt in ['files', 'interval', 'commands', 'max_tries']: + if opt not in self.options or (opt in self.options and self.options[opt] is None): + logging.error(f"AUTO-BACKUP: Option {opt} is not set.") + return self.ready = True logging.info("AUTO-BACKUP: Successfully loaded.") @@ -35,6 +29,9 @@ class AutoBackup(plugins.Plugin): if not self.ready: return + if self.options['max_tries'] and self.tries >= self.options['max_tries']: + return + if self.status.newer_then_days(self.options['interval']): return @@ -62,6 +59,7 @@ class AutoBackup(plugins.Plugin): display.update() self.status.update() except OSError as os_e: + self.tries += 1 logging.info(f"AUTO-BACKUP: Error: {os_e}") display.set('status', 'Backup failed!') display.update()