Skip to content

Commit

Permalink
resource loader now default to scan all files when no file type is given
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 15, 2023
1 parent 0ccd692 commit 635c301
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions neetbox/integrations/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,26 @@ 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)
return _loader_pool[_id]

def __init__(
self,
folder,
file_types=[],
folder: str = ".",
file_types=["*"],
sub_dirs=True,
async_scan=False,
verbose=False,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 635c301

Please sign in to comment.