Move check_or_create_dir to the utils module.

This commit is contained in:
Simon Conseil
2014-01-16 00:16:01 +01:00
parent d5aa560932
commit 3426a1b404
3 changed files with 22 additions and 9 deletions

View File

@@ -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')

View File

@@ -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)

View File

@@ -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)