diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index c887e9f0..c9d09ad4 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: +- changes: + - action: Updated + details: + - "`#143`: moban shall report permission error and continue the rest of the copying task." + date: unreleased + version: 0.3.6 - changes: - action: Updated details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index d537e6cc..d687f1e5 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,8 +3,8 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.5 -current_version: 0.3.5 +version: 0.3.6 +current_version: 0.3.6 release: 0.3.5 branch: master command_line_interface: "moban" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8827534d..febb1196 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.3.6 - unreleased +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#143 `_: moban shall report + permission error and continue the rest of the copying task. + 0.3.5 - 10-12-2018 -------------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index 79766cbb..229f8b79 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ # The short X.Y version version = u'0.3.5' # The full version, including alpha/beta/rc tags -release = u'0.3.5' +release = u'0.3.6' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index a33da8fe..64fcab11 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.5" +__version__ = "0.3.6" __author__ = "C. W." diff --git a/moban/copier.py b/moban/copier.py index 15b2d8d9..832f7708 100644 --- a/moban/copier.py +++ b/moban/copier.py @@ -1,10 +1,15 @@ import os +import sys import shutil import moban.utils as utils import moban.reporter as reporter from moban.hashstore import HASH_STORE +PY2 = sys.version_info[0] == 2 +if PY2: + PermissionError = IOError + class Copier(object): def __init__(self, template_dirs): @@ -88,8 +93,11 @@ def _copy(self, src_path, dest): if dest_folder: utils.mkdir_p(dest_folder) reporter.report_copying(src_path, dest) - shutil.copy(src_path, dest) - self._count = self._count + 1 + try: + shutil.copy(src_path, dest) + self._count = self._count + 1 + except PermissionError: + reporter.report_error_message("No permission to write %s" % dest) def _increment_file_count(self): self._file_count += 1 diff --git a/moban/utils.py b/moban/utils.py index d517018e..7d542909 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -103,8 +103,8 @@ def expand_directories(file_list, template_dirs): break if os.path.isdir(true_template_file): for file_name in os.listdir(true_template_file): - template_file = '/'.join([template_file, file_name]) - template_file = template_file.replace('\\', '/') + template_file = "/".join([template_file, file_name]) + template_file = template_file.replace("\\", "/") base_output_name, _ = os.path.splitext(file_name) yield ( ( diff --git a/setup.py b/setup.py index 72553f21..98b3dadb 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ NAME = 'moban' AUTHOR = 'C. W.' -VERSION = '0.3.5' +VERSION = '0.3.6' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'MIT' ENTRY_POINTS = { diff --git a/tests/test_copier.py b/tests/test_copier.py index df8d6cd8..71cd906f 100644 --- a/tests/test_copier.py +++ b/tests/test_copier.py @@ -1,4 +1,5 @@ import os +import sys import shutil from mock import patch @@ -7,6 +8,10 @@ from moban.copier import Copier from moban.mobanfile import handle_copy +PY2 = sys.version_info[0] == 2 +if PY2: + PermissionError = IOError + class TestCopier: def setUp(self): @@ -32,6 +37,16 @@ def test_copy_files_file_not_found(self, reporter): "copier-test-not-found.csv cannot be found" ) + @patch("moban.reporter.report_error_message") + def test_no_permission_to_write(self, reporter): + copier = Copier([os.path.join("tests", "fixtures")]) + file_list = [{"/tmp/test_cannot_write": "copier-test01.csv"}] + self.fake_copy.side_effect = PermissionError + copier.copy_files(file_list) + reporter.assert_called_with( + "No permission to write /tmp/test_cannot_write" + ) + def test_number_of_files(self): copier = Copier([os.path.join("tests", "fixtures")]) file_list = [{"/tmp/test": "copier-test04.csv"}] diff --git a/tests/test_hash_store.py b/tests/test_hash_store.py index 1671def5..659b3b5b 100644 --- a/tests/test_hash_store.py +++ b/tests/test_hash_store.py @@ -1,9 +1,10 @@ import os import sys -from moban.hashstore import HashStore from nose import SkipTest +from moban.hashstore import HashStore + class TestHashStore: def setUp(self): @@ -79,8 +80,8 @@ def test_dest_file_file_permision_changed(self): Save as above, but this time, the generated file had file permision change """ - if sys.platform == 'win32': - raise SkipTest('No actual chmod on windows') + if sys.platform == "win32": + raise SkipTest("No actual chmod on windows") hs = HashStore() flag = hs.is_file_changed(*self.fixture) if flag: diff --git a/tests/test_utils.py b/tests/test_utils.py index 707f7427..13176cc7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,8 +4,9 @@ from shutil import rmtree from mock import patch -from nose.tools import eq_, raises from nose import SkipTest +from nose.tools import eq_, raises + from moban.utils import ( mkdir_p, get_repo_name, @@ -27,8 +28,8 @@ def create_file(test_file, permission): def test_file_permission_copy(): - if sys.platform == 'win32': - raise SkipTest('No actual chmod on windows') + if sys.platform == "win32": + raise SkipTest("No actual chmod on windows") test_source = "test_file_permission_copy1" test_dest = "test_file_permission_copy2" create_file(test_source, 0o046) @@ -48,8 +49,8 @@ def test_file_permissions_file_not_found(): def test_file_permission_copy_symlink(): - if sys.platform == 'win32': - raise SkipTest('No symlink on windows') + if sys.platform == "win32": + raise SkipTest("No symlink on windows") test_source = "test_file_permission_copy1" test_dest = "test_file_permission_copy2" test_symlink = "test_file_permission_symlink" @@ -98,13 +99,7 @@ def test_expand_dir(): file_list = [("template-tests", "abc", "abc")] template_dirs = [os.path.join("tests", "fixtures")] results = list(expand_directories(file_list, template_dirs)) - expected = [ - ( - "template-tests/a.jj2", - "abc", - os.path.join("abc", "a"), - ) - ] + expected = [("template-tests/a.jj2", "abc", os.path.join("abc", "a"))] eq_(results, expected)