Skip to content

Commit fc074ce

Browse files
authored
Merge pull request #7 from IBM/notebooks
Notebooks
2 parents 316cb35 + 8aa4bad commit fc074ce

File tree

4 files changed

+221
-183
lines changed

4 files changed

+221
-183
lines changed

doframework/core/storage.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616

1717
from dataclasses import dataclass, field
18+
from typing import Optional
19+
from itertools import islice
1820
import os
1921
import json
2022
from pathlib import Path
@@ -151,4 +153,27 @@ def count(self,bucket,extension):
151153
objects = [f for f in Path(bucket).rglob('*') if Path(f).suffix in [f'.{extension}']]
152154
n = len(objects)
153155

154-
return n
156+
return n
157+
158+
def get_all(self,bucket,extension,limit: Optional[int]=None):
159+
assert bucket in self.storage_buckets.values(), \
160+
'The bucket you provided is not on the storage bucket list. Find the list by running storage.buckets().'
161+
assert extension in ['json','csv'], \
162+
'get_all method retrieves either json or csv files in given bucket. provide either extension=`json` or extension=`csv`.'
163+
164+
objects = []
165+
166+
if bucket in self.storage_buckets.values():
167+
if 's3' in self.configs:
168+
if limit:
169+
objects = [f for f in _get_s3_object(self.configs).Bucket(bucket).objects.all().limit(limit) if f.key.endswith(extension)]
170+
else:
171+
objects = [f for f in _get_s3_object(self.configs).Bucket(bucket).objects.all() if f.key.endswith(extension)]
172+
if 'local' in self.configs:
173+
if limit:
174+
objects = [f for f in islice(Path(bucket).iterdir(),limit) if Path(f).suffix in [f'.{extension}']]
175+
else:
176+
objects = [f for f in Path(bucket).rglob('*') if Path(f).suffix in [f'.{extension}']]
177+
178+
return objects
179+

0 commit comments

Comments
 (0)