From 4d23bde906825ce5fc51c86c1463c0acda8dde3e Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 15 Jun 2023 18:44:22 +0200 Subject: [PATCH] Check that inputs from command line exist Check that the inputs specified on the command line (i.e. with the option '-i' or '--input') exist and print a warning when they don't. If no valid inputs are found, exit. --- simple_backup/__init__.py | 2 +- simple_backup/simple_backup.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/simple_backup/__init__.py b/simple_backup/__init__.py index 8b6e509..773d4e5 100644 --- a/simple_backup/__init__.py +++ b/simple_backup/__init__.py @@ -1,3 +1,3 @@ """Init.""" -__version__ = '3.4.0' +__version__ = '3.4.1' diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index c6496d9..583e535 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -186,12 +186,28 @@ class Backup: self.create_backup_dir() _, self._inputs_path = mkstemp(prefix='tmp_inputs', text=True) - _, self._exclude_path = mkstemp(prefix='tmp_exclude', text=True) + count = 0 with open(self._inputs_path, 'w') as fp: for i in self.inputs: - fp.write(i) - fp.write('\n') + if not os.path.exists(i): + logger.warning(f'Input {i} not found. Skipping') + else: + fp.write(i) + fp.write('\n') + count += 1 + + if count == 0: + logger.info('No existing files or directories specified for backup. Nothing to do') + + try: + notify('Backup finished. No files copied') + except NameError: + pass + + return 1 + + _, self._exclude_path = mkstemp(prefix='tmp_exclude', text=True) with open(self._exclude_path, 'w') as fp: if self.exclude is not None: