Browse Source

Move check_or_create_dir to the utils module.

pull/70/merge
Simon Conseil 12 years ago
parent
commit
3426a1b404
  1. 9
      sigal/gallery.py
  2. 7
      sigal/utils.py
  3. 15
      tests/test_utils.py

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

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

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

Loading…
Cancel
Save