diff options
author | kballou <kballou@devnulllabs.io> | 2014-11-30 01:16:05 -0700 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2014-11-30 01:16:05 -0700 |
commit | 249e002f809d5c0fcdf8a19398b65271d816fcf0 (patch) | |
tree | f034fd67b2c6e84828a0ce49bcaec6d20938118a | |
parent | b5be3f2b75ec07db67fe5f17f8fcf832da23c7cd (diff) | |
download | xnt-249e002f809d5c0fcdf8a19398b65271d816fcf0.tar.gz xnt-249e002f809d5c0fcdf8a19398b65271d816fcf0.tar.xz |
Refactor copy: `src` can be file _or_ directory
`__copy__`'s `srcdir` parameter is renamed to `src` and can be either a
file or a directory; now in-line with the original behaviour.
-rw-r--r-- | xnt/tasks/core_tasks.py | 15 | ||||
-rw-r--r-- | xnt/tests/taskcopytests.py | 6 |
2 files changed, 12 insertions, 9 deletions
diff --git a/xnt/tasks/core_tasks.py b/xnt/tasks/core_tasks.py index cce67e3..034347d 100644 --- a/xnt/tasks/core_tasks.py +++ b/xnt/tasks/core_tasks.py @@ -45,28 +45,31 @@ def __expandpath__(path_pattern): return glob.iglob(kwargs['path_pattern']) return ((__execute__, {'path_pattern': path_pattern}),) -def __copy__(srcdir=None, dstdir=None, files=None): - """Copy `srcdir` to `dstdir` or copy `files` to `dstdir` +def __copy__(src=None, dstdir=None, files=None): + """Copy `src` to `dstdir` or copy `files` to `dstdir` Copy a file or folder to a different file/folder If no `srcdir` file is specified, will attempt to copy `files` to `dstdir` *Notice*, elements of `files` will not be expanded before copying. - :param srcdir: source directory or file + :param src: source directory or file :param dstdir: destination file or folder (in the case of `files`) :param files: list of files (strings) to copy to `src` """ def __execute__(**kwargs): """Perform copy""" assert 'dstdir' in kwargs - if 'srcdir' in kwargs: - shutil.copytree(kwargs['srcdir'], kwargs['dstdir']) + if 'src' in kwargs: + if os.path.isfile(kwargs['src']): + shutil.copyfile(kwargs['src'], kwargs['dstdir']) + else: + shutil.copytree(kwargs['src'], kwargs['dstdir']) elif 'files' in kwargs: for srcfile in kwargs['files']: shutil.copy(srcfile, kwargs['dstdir']) return ( - (__execute__, {'srcdir': srcdir, 'dstdir': dstdir, 'files': files,}), + (__execute__, {'src': src, 'dstdir': dstdir, 'files': files,}), ) def __move__(src, dst): diff --git a/xnt/tests/taskcopytests.py b/xnt/tests/taskcopytests.py index c203197..f451595 100644 --- a/xnt/tests/taskcopytests.py +++ b/xnt/tests/taskcopytests.py @@ -27,10 +27,10 @@ class TaskCopyTests(unittest.TestCase): def test_cp(self): """Test default use of cp""" - result = __copy__(srcdir="test0", dstdir="test1") + result = __copy__(src="test0", dstdir="test1") assert_basic_assumptions(self, result) - self.assertTrue('srcdir' in result[0][1]) - self.assertEqual('test0', result[0][1]['srcdir']) + self.assertTrue('src' in result[0][1]) + self.assertEqual('test0', result[0][1]['src']) self.assertTrue('dstdir' in result[0][1]) self.assertEqual('test1', result[0][1]['dstdir']) |