Skip to content

Commit 9977ece

Browse files
committed
For lpsdata files. If there are no uploaded directories preceeded by digits will create an Uploaded directory as a subdirectory to the source directory
1 parent 997238d commit 9977ece

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

mokelumne/util/file_transfer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ def manifest_entry_matches_file(
202202

203203
def _all_subdirs(upload_dir: Path) -> list:
204204
"""get a list of all subdirectories for a given path"""
205-
all_subdirs = [x for x in upload_dir.rglob("*") if x.is_dir()]
206-
205+
#all_subdirs = [x for x in upload_dir.rglob("*") if x.is_dir()]
206+
all_subdirs = [x for x in upload_dir.iterdir() if x.is_dir()]
207207
return all_subdirs
208208

209209
def _get_next_subdir_index(parent_dir: Path) -> int:
@@ -251,11 +251,13 @@ def move_to_uploaded(source_dir: str) -> tuple[str, int]:
251251
# If there is no uploaded directory we need to create one.
252252
# It needs to be prefixed with the next number in the queue.
253253
# e.g. if there's a directory 03_Files_to_Review.
254-
# It would be 04_Uploaded
254+
# It would be 04_Uploaded. If they are not preceded by
255+
# by numbers it will create an Uploaded directory
256+
# as a subdirectory to source_dir
255257
if not uploaded_dir:
256258
highest = _get_next_subdir_index(parent_dir)
257259
if highest is None:
258-
uploaded_dir = f"{parent_dir}/Uploaded"
260+
uploaded_dir = f"{source_dir}/Uploaded"
259261
else:
260262
uploaded_dir = f"{parent_dir}/{highest:02}_Uploaded"
261263

test/unit/test_file_transfer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ def test_move_to_uploaded_creates_new_uploaded_directory(
232232
result_path, moved_count = file_transfer.move_to_uploaded(str(source_dir))
233233

234234
# Verify outcomes using the parameterized target name
235-
expected_uploaded_dir = parent_dir / expected_uploaded_name
236-
235+
if existing_dir_name == "No_Digits_Here":
236+
expected_uploaded_dir = source_dir / expected_uploaded_name
237+
else:
238+
expected_uploaded_dir = parent_dir / expected_uploaded_name
239+
237240
assert result_path == str(expected_uploaded_dir)
238241
assert moved_count == 1
239242
assert not source_file.exists()

0 commit comments

Comments
 (0)