Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_file(name):


PROJECT = 'skeleton'
VERSION = '0.6'
VERSION = '0.6-ypr'
URL = 'http://dinoboff.github.com/skeleton'
AUTHOR = 'Damien Lebrun'
AUTHOR_EMAIL = 'dinoboff@gmail.com'
Expand Down
3 changes: 2 additions & 1 deletion skeleton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def write(self, dst_dir, run_dry=False):

for dir_path, dir_names, file_names in os.walk(real_src):
rel_dir_path = dir_path[real_src_len:].lstrip(r'\/')
rel_dir_path = self._format_file_name(rel_dir_path, real_src)

#copy files
for file_name in file_names:
Expand All @@ -300,7 +301,7 @@ def write(self, dst_dir, run_dry=False):
dst = os.path.join(
dst_dir,
rel_dir_path,
self.template_formatter(dir_name))
self._format_file_name(dir_name, dir_path))
self._mkdir(dst, like=src)

def run(self, dst_dir, run_dry=False):
Expand Down
1 change: 1 addition & 0 deletions skeleton/tests/skeletons/dynamic-dir-name/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
1 change: 1 addition & 0 deletions skeleton/tests/skeletons/dynamic-dir-name/{bar}/baz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baz
36 changes: 36 additions & 0 deletions skeleton/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class DynamicContent(Static):
]


class DynamicDirName(Static):
"""Skeleton with a dynamic directory name ({bar})"""
src = 'skeletons/dynamic-dir-name'


class DynamicFileName(Static):
"""Skeleton with a dynamic file name (bar/${baz}.txt)"""
src = 'skeletons/dynamic-file-name'
Expand All @@ -64,6 +69,12 @@ class MissingVariable(DynamicContent):
variables = []


class MissingVariableForDirName(DynamicDirName):
"""We forgot to declare the variable "baz"
"""
variables = []


class MissingVariableForFileName(DynamicFileName):
"""We forgot to declare the variable "baz"
"""
Expand Down Expand Up @@ -233,6 +244,31 @@ def test_write_dynamic_content(self):
'foo <replaced> bar'
)

def test_write_dynamic_dir_names(self):
"""Tests Skeleton.write() with dynamic dir name"""
skel = DynamicDirName(bar="replaced-name")
with TempDir() as tmp_dir:
skel.write(tmp_dir.path)
self.assertEqual(
open(tmp_dir.join('foo.txt')).read().strip(),
'foo'
)
self.assertEqual(
open(tmp_dir.join('replaced-name/baz.txt')).read().strip(),
'baz'
)

def test_write_dir_name_fails(self):
"""Tests Skeleton.write() with dynamic directory name fails"""
skel = MissingVariableForDirName()
with TempDir() as tmp_dir:
try:
skel.write(tmp_dir.path)
self.fail("An exception should be raised")
except (FileNameKeyError,), exc:
self.assertTrue(exc.file_path.endswith('{bar}'))
self.assertEqual(exc.variable_name, 'bar')

def test_write_dynamic_file_names(self):
"""Tests Skeleton.write() with dynamic file name"""
skel = DynamicFileName(baz="replaced-name")
Expand Down