From b69520a65440480485719e5f98ef6f2d08ff803e Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Sun, 18 Sep 2011 21:38:38 +0200 Subject: [PATCH 1/2] dynamic dir names --- skeleton/core.py | 3 +- .../tests/skeletons/dynamic-dir-name/foo.txt | 1 + .../skeletons/dynamic-dir-name/{bar}/baz.txt | 1 + skeleton/tests/test_core.py | 36 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 skeleton/tests/skeletons/dynamic-dir-name/foo.txt create mode 100644 skeleton/tests/skeletons/dynamic-dir-name/{bar}/baz.txt diff --git a/skeleton/core.py b/skeleton/core.py index 7189dfb..5c071b8 100644 --- a/skeleton/core.py +++ b/skeleton/core.py @@ -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: @@ -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): diff --git a/skeleton/tests/skeletons/dynamic-dir-name/foo.txt b/skeleton/tests/skeletons/dynamic-dir-name/foo.txt new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/skeleton/tests/skeletons/dynamic-dir-name/foo.txt @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/skeleton/tests/skeletons/dynamic-dir-name/{bar}/baz.txt b/skeleton/tests/skeletons/dynamic-dir-name/{bar}/baz.txt new file mode 100644 index 0000000..3f95386 --- /dev/null +++ b/skeleton/tests/skeletons/dynamic-dir-name/{bar}/baz.txt @@ -0,0 +1 @@ +baz \ No newline at end of file diff --git a/skeleton/tests/test_core.py b/skeleton/tests/test_core.py index 3530018..8990327 100644 --- a/skeleton/tests/test_core.py +++ b/skeleton/tests/test_core.py @@ -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' @@ -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" """ @@ -233,6 +244,31 @@ def test_write_dynamic_content(self): 'foo 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") From d88a4f3ae109adf03904801198d01d75c84fb5fe Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 20 Sep 2011 11:39:00 +0200 Subject: [PATCH 2/2] version post-release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d73a0fa..fd09479 100755 --- a/setup.py +++ b/setup.py @@ -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'