Skip to content

Commit e94b260

Browse files
committed
add backend functionality to exclude drive from browser
1 parent 8089a33 commit e94b260

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

jupyter_drives/handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ def initialize(self, logger: logging.Logger, manager: JupyterDrivesManager):
5252
@tornado.web.authenticated
5353
async def post(self):
5454
body = self.get_json_body()
55-
result = self._manager.set_listing_limit(**body)
55+
if 'new_limit' in body:
56+
result = self._manager.set_listing_limit(**body)
57+
if 'exclude_drive_name' in body:
58+
result = self._manager.exclude_drive(**body)
5659
self.finish(result)
5760

5861
class ListJupyterDrivesHandler(JupyterDrivesAPIHandler):

jupyter_drives/manager.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self, config: traitlets.config.Config) -> None:
5353
self._max_files_listed = 1025
5454
self._drives = None
5555
self._external_drives = {}
56+
self._excluded_drives = set()
5657

5758
# instate fsspec file system
5859
self._file_system = fsspec.filesystem(self._config.provider, asynchronous=True)
@@ -171,6 +172,22 @@ def set_listing_limit(self, new_limit):
171172

172173
return
173174

175+
def exclude_drive(self, exclude_drive_name):
176+
"""Exclude drive from listing.
177+
178+
Args:
179+
exclude_bucket_name: drive to exclude
180+
"""
181+
try:
182+
self._excluded_drives.add(exclude_drive_name);
183+
except Exception as e:
184+
raise tornado.web.HTTPError(
185+
status_code= httpx.codes.BAD_REQUEST,
186+
reason= f"The following error occured when excluding the drive: {e}"
187+
)
188+
189+
return
190+
174191
async def list_drives(self):
175192
"""Get list of available drives.
176193
@@ -196,15 +213,16 @@ async def list_drives(self):
196213
)
197214

198215
for result in results:
199-
data.append(
200-
{
201-
"name": result.name,
202-
"region": self._config.region_name,
203-
"creationDate": result.extra["creation_date"],
204-
"mounted": False if result.name not in self._content_managers else True,
205-
"provider": self._config.provider
206-
}
207-
)
216+
if result.name not in self._excluded_drives:
217+
data.append(
218+
{
219+
"name": result.name,
220+
"region": self._config.region_name,
221+
"creationDate": result.extra["creation_date"],
222+
"mounted": False if result.name not in self._content_managers else True,
223+
"provider": self._config.provider
224+
}
225+
)
208226

209227
if len(self._external_drives) != 0:
210228
for drive in self._external_drives.values():

0 commit comments

Comments
 (0)