Skip to content

Commit

Permalink
Fix mistake in backup log logic
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcoder committed Feb 12, 2024
1 parent ea15e4e commit 382613f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config.rc.travis
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions ui/initial_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
10 changes: 6 additions & 4 deletions ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 382613f

Please sign in to comment.