-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added URL support for template {function}
- Loading branch information
Showing
7 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Temporary directory for osxphotos session""" | ||
|
||
from __future__ import annotations | ||
|
||
import pathlib | ||
import tempfile | ||
|
||
_TEMPDIR = tempfile.TemporaryDirectory(prefix="osxphotos_") | ||
TEMPDIR = pathlib.Path(_TEMPDIR.name) | ||
|
||
|
||
def tempdir(subdir: str | None = None): | ||
"""Return path to temporary directory that exists for the duration of the osxphotos session | ||
Args: | ||
subdir: optional subdirectory to create in temporary directory | ||
Returns: pathlib.Path to temporary directory | ||
""" | ||
if subdir: | ||
tmp = TEMPDIR / subdir | ||
tmp.mkdir(parents=True, exist_ok=True) | ||
return tmp | ||
else: | ||
return TEMPDIR | ||
|
||
|
||
def cleanup(): | ||
"""Cleanup temporary directory""" | ||
_TEMPDIR.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Test tempdir module.""" | ||
|
||
from osxphotos.tempdir import cleanup, tempdir | ||
|
||
|
||
def test_tempdir(): | ||
"""Test tempdir() and cleanup()""" | ||
tmp = tempdir() | ||
assert tmp.exists() | ||
|
||
tmp2 = tempdir() | ||
assert tmp2.exists() | ||
|
||
assert tmp == tmp2 | ||
|
||
cleanup() | ||
assert not tmp.exists() | ||
|
||
|
||
def test_tempdir(): | ||
"""Test tempdir() and cleanup() with subdir""" | ||
tmp = tempdir("foo") | ||
assert tmp.exists() | ||
|
||
tmp2 = tempdir("foo") | ||
assert tmp2.exists() | ||
|
||
assert tmp == tmp2 | ||
|
||
cleanup() | ||
assert not tmp.exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters