Skip to content

Commit

Permalink
Add convenience methods onto FileSystemFileDesc to perform common act…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
Matthew Wardrop committed Jan 26, 2018
1 parent d7692eb commit 1e76e0b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions omniduct/filesystems/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,27 @@ def as_dict(self):
d.update(self.extra)
return d

# Convenience methods

def open(self, mode='rt'):
assert self.type == 'file', "`.open(...)` is only appropriate for files."
return self.fs.open(self.path, mode=mode)

def dir(self):
assert self.type == 'directory', "`.dir(...)` is only appropriate for directories."
return self.fs.dir(self.path)

def listdir(self):
assert self.type == 'directory', "`.listdir(...)` is only appropriate for directories."
return self.fs.listdir(self.path)

def showdir(self):
assert self.type == 'directory', "`.showdir(...)` is only appropriate for directories."
return self.fs.showdir(self.path)

def find(self, **attrs):
assert self.type == 'directory', "`.find(...)` is only appropriate for directories."
return self.fs.find(self.path, **attrs)

def download(self, dest=None, overwrite=False, fs=None):
return self.fs.download(self.path, dest=dest, overwrite=overwrite, fs=fs)

0 comments on commit 1e76e0b

Please sign in to comment.