Skip to content

Commit

Permalink
add get_file accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
tyarkoni committed Oct 8, 2018
1 parent af68f5f commit c994761
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions grabbit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@ def as_data_frame(self, **kwargs):
data.insert(0, 'path', [f.path for f in files])
return data

def get_file(self, f):
''' Return File object for the specified path. '''
return self.files[f]

def get_nearest(self, path, return_type='file', strict=True, all_=False,
ignore_strict_entities=None, full_search=False, **kwargs):
''' Walk up the file tree from the specified path and return the
Expand Down Expand Up @@ -878,7 +882,7 @@ def get_nearest(self, path, return_type='file', strict=True, all_=False,
folders = defaultdict(list)

for filename in results:
f = self.files[filename]
f = self.get_file(filename)
folders[f.dirname].append(f)

def count_matches(f):
Expand Down Expand Up @@ -968,7 +972,7 @@ def build_path(self, source, path_patterns=None, strict=False,
if source not in self.files:
source = join(self.root, source)

source = self.files[source]
source = self.get_file(source)

if isinstance(source, File):
source = source.entities
Expand Down

0 comments on commit c994761

Please sign in to comment.