Skip to content

Commit

Permalink
More pathlib like syntax support
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Feb 6, 2017
1 parent c0efd51 commit 7a79f6f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plumbum/path/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ def _glob(self, pattern, fn):
results.extend(fn(single_pattern))
return sorted(list(set(results)))

def resolve(strict=False):
"""Added to allow pathlib like syntax. Does nothing since
plubmum paths are always absolute. Does not (currently) resolve
symlinks."""
# TODO: Resolve symlinks here
return self

@property
def parents(self):
"""Pathlib like sequence of ancestors"""
join = lambda x,y: self.__class__(x) / y
as_list = (reduce(join,self.parts[:i],self.parts[0]) for i in range(len(self.parts)-1,0,-1))
return tuple(as_list)

@property
def parent(self):
"""Pathlib like parent of the path."""
return self.parents[0]


class RelativePath(object):
Expand Down

0 comments on commit 7a79f6f

Please sign in to comment.