diff --git a/sigal/gallery.py b/sigal/gallery.py index be9d9ce..c8e2647 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -39,7 +39,7 @@ from pprint import pformat from . import compat from .image import process_image from .log import colored, BLUE -from .utils import copy +from .utils import copy, check_or_create_dir from .video import process_video from .writer import Writer @@ -356,13 +356,6 @@ def get_metadata(path): return meta -def check_or_create_dir(path): - "Create the directory if it does not exist" - - if not os.path.isdir(path): - os.makedirs(path) - - def zip_files(archive_path, filepaths): archive = zipfile.ZipFile(archive_path, 'w') diff --git a/sigal/utils.py b/sigal/utils.py index 4a40b16..99328cf 100644 --- a/sigal/utils.py +++ b/sigal/utils.py @@ -10,3 +10,10 @@ def copy(src, dst, symlink=False): if symlink and os.path.lexists(dst): os.remove(dst) func(src, dst) + + +def check_or_create_dir(path): + "Create the directory if it does not exist" + + if not os.path.isdir(path): + os.makedirs(path) diff --git a/tests/test_utils.py b/tests/test_utils.py index a87ee3f..4ecbad3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os -from sigal.utils import copy +from sigal.utils import copy, check_or_create_dir CURRENT_DIR = os.path.dirname(__file__) SAMPLE_DIR = os.path.join(CURRENT_DIR, 'sample') @@ -19,3 +19,16 @@ def test_copy(tmpdir): dst = str(tmpdir.join(filename)) copy(src, dst, symlink=True) assert os.path.islink(dst) + assert os.readlink(dst) == src + + filename = 'exo20101028-b-full.jpg' + src = os.path.join(SAMPLE_DIR, 'pictures', 'dir2', filename) + copy(src, dst, symlink=True) + assert os.path.islink(dst) + assert os.readlink(dst) == src + + +def test_check_or_create_dir(tmpdir): + path = str(tmpdir.join('new_directory')) + check_or_create_dir(path) + assert os.path.isdir(path)