Skip to content

Commit

Permalink
Add makedirs_p to cross-compatible API (#60)
Browse files Browse the repository at this point in the history
This is a no-op directory methods for swift paths
  • Loading branch information
jtratner authored Jan 20, 2018
1 parent abfcbcc commit 5cbdde0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
=============

v1.5.4
------

* Add ``stor.makedirs_p(path, mode=0o777)`` to cross-compatible API. This does
nothing on OBS-paths (just there for convenience).

v1.5.3
------

Expand Down
1 change: 1 addition & 0 deletions stor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def wrapper(path, *args, **kwargs):
islink = _delegate_to_path('islink')
ismount = _delegate_to_path('ismount')
getsize = _delegate_to_path('getsize')
makedirs_p = _delegate_to_path('makedirs_p')
remove = _delegate_to_path('remove')
rmtree = _delegate_to_path('rmtree')
walkfiles = _delegate_to_path('walkfiles')
Expand Down
5 changes: 5 additions & 0 deletions stor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ def rmtree(self):
See shutil.rmtree"""
raise NotImplementedError

def makedirs_p(self, mode=0o777):
""" Like :func:`os.makedirs`, but does not raise an exception if the
directory already exists. """
raise NotImplementedError

def walkfiles(self, pattern=None):
"""Iterate over files recursively.
Expand Down
6 changes: 6 additions & 0 deletions stor/obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def islink(self):
def ismount(self):
return True

# NOTE: we only have makedirs_p() because the other mkdir/mkdir_p/makedirs methods are expected
# to raise errors if directories exist or intermediate directories don't exist.
def makedirs_p(self, mode=0o777):
"""No-op (no directories on OBS)"""
return

def getsize(self):
"""Returns size, in bytes of path."""
raise NotImplementedError
Expand Down
4 changes: 4 additions & 0 deletions stor/tests/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def setUp(self):
super(TestSwiftFile, self).setUp()
settings.update({'swift': {'num_retries': 5}})

def test_makedirs_p_does_nothing(self):
# dumb test... but why not?
SwiftPath('swift://tenant/container/obj').makedirs_p()

def test_invalid_buffer_mode(self):
swift_f = SwiftPath('swift://tenant/container/obj').open()
swift_f.mode = 'invalid'
Expand Down

0 comments on commit 5cbdde0

Please sign in to comment.