From 635c3010fb79e75def166b4c0fc97617e22815b0 Mon Sep 17 00:00:00 2001 From: visualdust Date: Wed, 15 Nov 2023 09:57:55 +0000 Subject: [PATCH] resource loader now default to scan all files when no file type is given --- neetbox/integrations/resource.py | 17 +++++++---------- tests/test_integrations.py | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/neetbox/integrations/resource.py b/neetbox/integrations/resource.py index 96e74e3b..e0d546ee 100644 --- a/neetbox/integrations/resource.py +++ b/neetbox/integrations/resource.py @@ -44,20 +44,17 @@ class ResourceLoader: def __new__( cls, - folder, - file_types: [str] = [], + folder: str = ".", + file_types=["*"], sub_dirs=True, verbose=False, *args, **kwargs, ): - if not file_types or not len(file_types): - logger.err("Please specify file type(s) so that I can scan.") - raise Exception("No file type(s) specified") _id = folder + str(file_types) + "_R" if sub_dirs else "" if _id in _loader_pool: logger.info( - "ResourceLoader with same path and same file types already exists. Returning the old one." + "ResourceLoader with same path and same file type(s) already exists. Returning the old one." ) else: _loader_pool[_id] = super(ResourceLoader, cls).__new__(cls) @@ -65,8 +62,8 @@ def __new__( def __init__( self, - folder, - file_types=[], + folder: str = ".", + file_types=["*"], sub_dirs=True, async_scan=False, verbose=False, @@ -120,11 +117,11 @@ def perform_scan(): if not self._initialized: self._initialized = True logger.ok( - f"Resource loader '{self.path}' ready with {len(self._file_types)} file types({len(self.file_path_list)} files)." + f"Resource loader '{self.path}' ready with {'all' if '*' in self._file_types else len(self._file_types)} file types({len(self.file_path_list)} files)." ) logger.log( - f"Scanning started at '{self.path}' for {len(self._file_types)} file types." + f"Scanning started at '{self.path}' for {'all' if '*' in self._file_types else len(self._file_types)} file types." ) # call to scan if self._async_scan: diff --git a/tests/test_integrations.py b/tests/test_integrations.py index cdcf83b2..71988b47 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -17,7 +17,7 @@ def test_resource_loader(): import time print("testing resource loader") md_loader = ResourceLoader('./',['md']) - py_loader_async = ResourceLoader('./',['py'],async_scan=True,verbose=True) + py_loader_async = ResourceLoader('./', async_scan=True,verbose=True) while not py_loader_async.ready: print("waiting resource loader") time.sleep(1)