add ignore_errors to local.remove()
--HG-- branch : trunk
This commit is contained in:
parent
10b8de060a
commit
c1d0fc9aaf
|
@ -12,6 +12,7 @@ Bug fixes / Maintenance
|
||||||
- streamline py.path.local.mkdtemp implementation and usage
|
- streamline py.path.local.mkdtemp implementation and usage
|
||||||
- don't print empty lines when showing junitxml-filename
|
- don't print empty lines when showing junitxml-filename
|
||||||
- fix py.code.compile(source) to generate unique filenames
|
- fix py.code.compile(source) to generate unique filenames
|
||||||
|
- add optional boolean ignore_errors parameter to py.path.local.remove
|
||||||
|
|
||||||
Changes between 1.3.0 and 1.3.1
|
Changes between 1.3.0 and 1.3.1
|
||||||
==================================================
|
==================================================
|
||||||
|
|
|
@ -157,14 +157,18 @@ class LocalPath(FSBase):
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return str(self) < str(other)
|
return str(self) < str(other)
|
||||||
|
|
||||||
def remove(self, rec=1):
|
def remove(self, rec=1, ignore_errors=False):
|
||||||
""" remove a file or directory (or a directory tree if rec=1). """
|
""" remove a file or directory (or a directory tree if rec=1).
|
||||||
|
if ignore_errors is True, errors while removing directories will
|
||||||
|
be ignored.
|
||||||
|
"""
|
||||||
if self.check(dir=1, link=0):
|
if self.check(dir=1, link=0):
|
||||||
if rec:
|
if rec:
|
||||||
# force remove of readonly files on windows
|
# force remove of readonly files on windows
|
||||||
if iswin32:
|
if iswin32:
|
||||||
self.chmod(448, rec=1) # octcal 0700
|
self.chmod(448, rec=1) # octcal 0700
|
||||||
py.error.checked_call(py.std.shutil.rmtree, self.strpath)
|
py.error.checked_call(py.std.shutil.rmtree, self.strpath,
|
||||||
|
ignore_errors=ignore_errors)
|
||||||
else:
|
else:
|
||||||
py.error.checked_call(os.rmdir, self.strpath)
|
py.error.checked_call(os.rmdir, self.strpath)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -60,6 +60,17 @@ class TestLocalPath(common.CommonFSTests):
|
||||||
readonly_dir.remove()
|
readonly_dir.remove()
|
||||||
assert not readonly_dir.check(exists=1)
|
assert not readonly_dir.check(exists=1)
|
||||||
|
|
||||||
|
def test_remove_routes_ignore_errors(self, tmpdir, monkeypatch):
|
||||||
|
l = []
|
||||||
|
monkeypatch.setattr(py.std.shutil, 'rmtree',
|
||||||
|
lambda *args, **kwargs: l.append(kwargs))
|
||||||
|
tmpdir.remove()
|
||||||
|
assert not l[0]['ignore_errors']
|
||||||
|
for val in (True, False):
|
||||||
|
l[:] = []
|
||||||
|
tmpdir.remove(ignore_errors=val)
|
||||||
|
assert l[0]['ignore_errors'] == val
|
||||||
|
|
||||||
def test_initialize_curdir(self):
|
def test_initialize_curdir(self):
|
||||||
assert str(local()) == py.std.os.getcwd()
|
assert str(local()) == py.std.os.getcwd()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue