From 382613f69ad00a4e2c3d8657a713bb5dbdc7ca2d Mon Sep 17 00:00:00 2001 From: Andy Wood Date: Mon, 12 Feb 2024 16:03:17 +0000 Subject: [PATCH] Fix mistake in backup log logic --- config.rc.travis | 4 ++-- ui/initial_state.py | 8 ++++++-- ui/main.py | 10 ++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/config.rc.travis b/config.rc.travis index 03d4289..0e3d98e 100644 --- a/config.rc.travis +++ b/config.rc.travis @@ -1,7 +1,7 @@ [files] # relative path to where log is kept -log_file = canute.log -media_dir = ~/canute-media +log_file = 'canute.log' +media_dir = '~/canute-media' # Book Directories # Additional books made available on the USB ports will be made visible diff --git a/ui/initial_state.py b/ui/initial_state.py index 8b6f422..2281850 100644 --- a/ui/initial_state.py +++ b/ui/initial_state.py @@ -31,10 +31,14 @@ def configured_source_dirs(): return config.get('files', {}).get('library', []) -def mounted_source_paths(media_dir): +def mounted_source_paths(media_dir, only_mounted=False): + """ + return mounted mount points and, by default, any non-mountpoint paths + """ for source_dir in configured_source_dirs(): source_path = os.path.join(media_dir, source_dir.get('path')) - if not source_dir.get('mountpoint', False) or os.path.ismount(source_path): + if (source_dir.get('mountpoint', False) and os.path.ismount(source_path)) or \ + (not only_mounted and not source_dir.get('mountpoint', False)): yield source_path, source_dir.get('swappable', False) diff --git a/ui/main.py b/ui/main.py index f47ac49..6741b0b 100644 --- a/ui/main.py +++ b/ui/main.py @@ -317,11 +317,13 @@ async def handle_hardware(driver, state, media_dir): def backup_log(config): - mounted_dirs = initial_state.mounted_source_paths() - if len(mounted_dirs) > 0: + media_dir = config.get('files', {}).get('media_dir') + log_file = config.get('files', {}).get('log_file') + source_paths = initial_state.mounted_source_paths(media_dir, only_mounted=True) + for source_path, swappable in source_paths: # make a filename based on the date and save to first path - backup_file = os.path.join(mounted_dirs[0][0], time.strftime('%Y%m%d%M_log.txt')) - log.debug('backing up log to USB stick: {}'.format(backup_file)) + backup_file = os.path.join(source_path, time.strftime('%Y%m%d%M_log.txt')) + log.info(f'backing up log to USB stick: {backup_file}') try: import shutil shutil.copyfile(log_file, backup_file)