Skip to content

Commit

Permalink
check folder structure for correct format
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov committed Aug 22, 2024
1 parent acde800 commit 6ba257d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- fix: use a-z for sms mfa index to disambiguate with mfa code with leading zeros [#925](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/925)
- fix: report proper error on bad `--folder-structure` value [#937](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/937)

## 1.23.0 (2024-07-25)

Expand Down
7 changes: 7 additions & 0 deletions src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ def main(
print("Webui must be the last --password-provider")
sys.exit(2)

if folder_structure != "none":
try:
folder_structure.format(datetime.datetime.now())
except: # noqa E722
print("Format specified in --folder-structure is incorrect")
sys.exit(2)

status_exchange = StatusExchange()
config = Config(
directory=directory,
Expand Down
35 changes: 35 additions & 0 deletions tests/test_folder_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,38 @@ def test_folder_structure_de_posix(self) -> None:
assert os.path.exists(
os.path.join(data_dir, os.path.normpath(file_name))
), f"File {file_name} expected, but does not exist"

def test_folder_structure_bad_format(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

files_to_create: List[Tuple[str, str, int]] = []
files_to_download: List[Tuple[str, str]] = []

# Note - This test uses the same cassette as test_download_photos.py
data_dir, result = run_icloudpd_test(
self.assertEqual,
self.vcr_path,
base_dir,
"listing_photos.yml",
files_to_create,
files_to_download,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"5",
"--only-print-filenames",
"--folder-structure={%Y}{%Y}",
"--no-progress-bar",
"--threads-num",
"1",
],
)

assert result.exit_code == 2

messages = result.output.splitlines()

self.assertTrue("Format specified in --folder-structure is incorrect" in messages)

0 comments on commit 6ba257d

Please sign in to comment.