Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
ENH: Ignore files next to device dir (#175)
Browse files Browse the repository at this point in the history
* ignore files in path_to_garmin_device

* Update tests, Add autorun file in path_to_garmin_device like in block device

* Allow multiple directories

* CLN: Remove unused variables
  • Loading branch information
gotiniens authored Jul 5, 2021
1 parent bc8c3e2 commit a2ea990
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
* Add support for mounting devices which identify as block device.
* Add `check-for-update` command to `wkz` CLI.
### Changed
* When looking for activities on device allow files next to device dir.
### Fixed
* Test for mounting devices fails sometimes, because it was not ready for block device mounting.

Expand Down
6 changes: 5 additions & 1 deletion tests/db_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def __init__(self, mount_path: LocalPath, device_dir, activity_dir: str, activit
self.mount_path = mount_path
self.device_path = self.mount_path / device_dir
self.activity_path_on_device = self.device_path / activity_dir
self.auto_run_file = self.mount_path / "AUTORUN.INF"
self.extra_directory_path_on_device = self.mount_path / "random_extra_dir"
self.mounted = False
self.activity_files = activity_files

Expand All @@ -178,6 +180,8 @@ def mount(self):
if not self.mounted:
print("mounting fake device...")
self.activity_path_on_device.mkdir(parents=True)
self.extra_directory_path_on_device.mkdir()
self.auto_run_file.write_text("EMPTY")
if self.activity_files:
# copy activity files into activity dir
copy_demo_fit_files_to_track_dir(
Expand All @@ -190,7 +194,7 @@ def mount(self):
def unmount(self):
if self.mounted:
print("unmounting fake device...")
shutil.rmtree(self.device_path)
shutil.rmtree(self.mount_path)
self.mounted = False


Expand Down
2 changes: 2 additions & 0 deletions tests/db_tests/test_watchdogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def test_fake_device(db, fake_device, device_dir, activity_dir, fit_file):
# now mount the fake device, which should also contain a fit file
device.mount()

assert (mount_path / "AUTORUN.INF").is_file()
assert (mount_path / "random_extra_dir").is_dir()
assert (mount_path / device_dir).is_dir()
assert (mount_path / device_dir / activity_dir).is_dir()
assert (mount_path / device_dir / activity_dir / fit_file).is_file()
Expand Down
11 changes: 5 additions & 6 deletions wkz/watchdogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ def trigger_device_watchdog():


def _watch_for_device(path_to_garmin_device: str, path_to_trace_dir: str, delete_files_after_import: bool):
device_mounted = False
if Path(path_to_garmin_device).is_dir():
sub_dirs = os.listdir(path_to_garmin_device)
if len(sub_dirs) == 1 and not device_mounted:
device_mounted = True
sub_dirs = []
for filename in os.listdir(path_to_garmin_device):
if (Path(path_to_garmin_device) / filename).is_dir():
sub_dirs.append(sub_dirs)
if len(sub_dirs) > 0:
log.info(f"Found mounted device at {path_to_garmin_device}, triggering fit collector...")
fit_collector = FitCollector(
path_to_garmin_device=path_to_garmin_device,
target_location=path_to_trace_dir,
delete_files_after_import=delete_files_after_import,
)
fit_collector.copy_fit_files()
elif len(sub_dirs) == 0:
device_mounted = False
else:
log.warning(f"Device Watchdog: {path_to_garmin_device} is not a valid directory.")

0 comments on commit a2ea990

Please sign in to comment.