Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/scanner.py
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | ) -> None: | ||||
Args: | Args: | ||||
root: the root path to scan | root: the root path to scan | ||||
api_url: url for the API request | api_url: url for the API request | ||||
""" | """ | ||||
async def _scan(root, session, api_url, source_tree, exclude_patterns): | async def _scan(root, session, api_url, source_tree, exclude_patterns): | ||||
for path, pid, found in await parse_path( | for path, pid, known in await parse_path( | ||||
root, session, api_url, exclude_patterns | root, session, api_url, exclude_patterns | ||||
): | ): | ||||
obj_type = parse_persistent_identifier(pid).object_type | obj_type = parse_persistent_identifier(pid).object_type | ||||
if obj_type == CONTENT: | if obj_type == CONTENT: | ||||
source_tree.addNode(path, pid if found else None) | source_tree.addNode(path, pid, known) | ||||
elif obj_type == DIRECTORY and directory_filter(path, exclude_patterns): | elif obj_type == DIRECTORY and directory_filter(path, exclude_patterns): | ||||
if found: | source_tree.addNode(path, pid, known) | ||||
source_tree.addNode(path, pid) | if not known: | ||||
else: | |||||
source_tree.addNode(path) | |||||
await _scan(path, session, api_url, source_tree, exclude_patterns) | await _scan(path, session, api_url, source_tree, exclude_patterns) | ||||
async with aiohttp.ClientSession() as session: | async with aiohttp.ClientSession() as session: | ||||
await _scan(root, session, api_url, source_tree, exclude_patterns) | await _scan(root, session, api_url, source_tree, exclude_patterns) |