mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Explain crawling and partially explain downloading
This commit is contained in:
parent
9cb2b68f09
commit
62f0f7bfc5
@ -220,9 +220,14 @@ class Crawler(ABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def crawl(self, path: PurePath) -> Optional[CrawlToken]:
|
async def crawl(self, path: PurePath) -> Optional[CrawlToken]:
|
||||||
|
log.explain_topic(f"Decision: Crawl {path}")
|
||||||
|
|
||||||
if self._transformer.transform(path) is None:
|
if self._transformer.transform(path) is None:
|
||||||
|
log.explain("Answer: No")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
log.explain("Answer: Yes")
|
||||||
|
|
||||||
desc = f"[bold bright_cyan]Crawling[/] {escape(str(path))}"
|
desc = f"[bold bright_cyan]Crawling[/] {escape(str(path))}"
|
||||||
return CrawlToken(self._limiter, desc)
|
return CrawlToken(self._limiter, desc)
|
||||||
|
|
||||||
@ -233,26 +238,32 @@ class Crawler(ABC):
|
|||||||
redownload: Optional[Redownload] = None,
|
redownload: Optional[Redownload] = None,
|
||||||
on_conflict: Optional[OnConflict] = None,
|
on_conflict: Optional[OnConflict] = None,
|
||||||
) -> Optional[DownloadToken]:
|
) -> Optional[DownloadToken]:
|
||||||
|
log.explain_topic(f"Decision: Download {path}")
|
||||||
|
|
||||||
transformed_path = self._transformer.transform(path)
|
transformed_path = self._transformer.transform(path)
|
||||||
if transformed_path is None:
|
if transformed_path is None:
|
||||||
|
log.explain("Answer: No")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fs_token = await self._output_dir.download(transformed_path, mtime, redownload, on_conflict)
|
fs_token = await self._output_dir.download(transformed_path, mtime, redownload, on_conflict)
|
||||||
if fs_token is None:
|
if fs_token is None:
|
||||||
|
log.explain("Answer: No")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
log.explain("Answer: Yes")
|
||||||
|
|
||||||
desc = f"[bold bright_cyan]Downloading[/] {escape(str(path))}"
|
desc = f"[bold bright_cyan]Downloading[/] {escape(str(path))}"
|
||||||
return DownloadToken(self._limiter, fs_token, desc)
|
return DownloadToken(self._limiter, fs_token, desc)
|
||||||
|
|
||||||
async def _cleanup(self) -> None:
|
async def _cleanup(self) -> None:
|
||||||
log.explain_topic("Decision: Clean up files?")
|
log.explain_topic("Decision: Clean up files")
|
||||||
if self.error_free:
|
if self.error_free:
|
||||||
log.explain("No warnings or errors occurred during this run")
|
log.explain("No warnings or errors occurred during this run")
|
||||||
log.explain("Cleaning up files")
|
log.explain("Answer: Yes")
|
||||||
await self._output_dir.cleanup()
|
await self._output_dir.cleanup()
|
||||||
else:
|
else:
|
||||||
log.explain("Warnings or errors occurred during this run")
|
log.explain("Warnings or errors occurred during this run")
|
||||||
log.explain("Not cleaning up files")
|
log.explain("Answer: No")
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -317,16 +317,22 @@ class Transformer:
|
|||||||
for i, line in enumerate(rules.split("\n")):
|
for i, line in enumerate(rules.split("\n")):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
self._rules.append(parse_rule(Line(line, i)))
|
rule = parse_rule(Line(line, i))
|
||||||
|
self._rules.append((line, rule))
|
||||||
|
|
||||||
def transform(self, path: PurePath) -> Optional[PurePath]:
|
def transform(self, path: PurePath) -> Optional[PurePath]:
|
||||||
for rule in self._rules:
|
for i, (line, rule) in enumerate(self._rules):
|
||||||
|
log.explain(f"Testing rule {i}: {line}")
|
||||||
|
|
||||||
result = rule.transform(path)
|
result = rule.transform(path)
|
||||||
if isinstance(result, PurePath):
|
if isinstance(result, PurePath):
|
||||||
|
log.explain(f"Match! Transformed to {result}")
|
||||||
return result
|
return result
|
||||||
elif result: # Exclamation mark
|
elif result: # Exclamation mark
|
||||||
|
log.explain("Match! Ignored")
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
log.explain("No rule matched, path is unchanged")
|
||||||
return path
|
return path
|
||||||
|
Loading…
Reference in New Issue
Block a user