Skip to content

Commit

Permalink
added force rescan to resource loader
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 21, 2023
1 parent 5379c1f commit 36809f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions neetbox/integrations/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def __new__(
file_types: [str] = [],
sub_dirs=True,
verbose=False,
force_rescan=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:
if _id in _loader_pool and not force_rescan:
logger.info(
"ResourceLoader with same path and same file types already exists. Returning the old one."
)
Expand All @@ -70,6 +71,7 @@ def __init__(
sub_dirs=True,
async_scan=False,
verbose=False,
force_rescan=False,
):
"""ResourceLoader scans given file type(s) in given place(s)
Expand All @@ -79,6 +81,7 @@ def __init__(
sub_dirs (bool, optional): scan sub-folder(s)?. Defaults to True.
async_scan (bool, optional): run scan traks in a new thread. Defaults to False.
verbose (bool, optional): verbose output. Defaults to False.
force_rescan (bool, optional): rescan the folder even the same file type(s) was scanned here before. Default to False.
"""
super().__init__()
self.path = os.path.abspath(folder)
Expand Down Expand Up @@ -123,9 +126,6 @@ def perform_scan():
f"Resource loader '{self.path}' ready with {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."
)
# call to scan
if self._async_scan:
threading.Thread(target=perform_scan).start()
Expand Down

0 comments on commit 36809f4

Please sign in to comment.