Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/benchmark_algos.py
Show First 20 Lines • Show All 293 Lines • ▼ Show 20 Lines | |||||
def load_source(root, sre_patterns): | def load_source(root, sre_patterns): | ||||
""" | """ | ||||
Load the source code inside the Tree data structure | Load the source code inside the Tree data structure | ||||
""" | """ | ||||
def _scan(root_path, source_tree, sre_patterns): | def _scan(root_path, source_tree, sre_patterns): | ||||
dirpath, dnames, fnames = next(os.walk(root_path, followlinks=False)) | files = [] | ||||
dirpath = Path(dirpath) | dirs = [] | ||||
for elem in os.listdir(root_path): | |||||
cnt = Path(root_path).joinpath(elem) | |||||
if not os.path.islink(cnt): | |||||
if os.path.isfile(cnt): | |||||
files.append(cnt) | |||||
zack: if you want to avoid symlinks, these doesn't work, because doc (for both) says:
"This follows… | |||||
Not Done Inline Actionsactually, you probably do not want to ignore symlinks completely (I think?, it depends on how your tree is then used) if you want to keep them, probably you should just avoid listing root_path if *it* is a symlink, so using islink() on it before invoking listdir on it() zack: actually, you probably do not want to ignore symlinks completely (I think?, it depends on how… | |||||
elif os.path.isdir(cnt): | |||||
dirs.append(cnt) | |||||
if fnames: | if files: | ||||
files = [dirpath.joinpath(fname) for fname in fnames] | |||||
parsed_file_swhids = dict(get_swhids(files, sre_patterns)) | parsed_file_swhids = dict(get_swhids(files, sre_patterns)) | ||||
for path, swhid_ in parsed_file_swhids.items(): | for path, swhid_ in parsed_file_swhids.items(): | ||||
source_tree.add_node(Path(path), swhid_) | source_tree.add_node(Path(path), swhid_) | ||||
if dnames: | if dirs: | ||||
dirs = [dirpath.joinpath(dname) for dname in dnames] | |||||
parsed_dirs_swhids = dict(get_swhids(dirs, sre_patterns)) | parsed_dirs_swhids = dict(get_swhids(dirs, sre_patterns)) | ||||
for path, swhid_ in parsed_dirs_swhids.items(): | for path, swhid_ in parsed_dirs_swhids.items(): | ||||
if not directory_filter(path, sre_patterns): | if not directory_filter(path, sre_patterns): | ||||
continue | continue | ||||
source_tree.add_node(Path(path), swhid_) | source_tree.add_node(Path(path), swhid_) | ||||
_scan(path, source_tree, sre_patterns) | _scan(path, source_tree, sre_patterns) | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
if you want to avoid symlinks, these doesn't work, because doc (for both) says:
"This follows symbolic links, so both islink() and isfile() can be true for the same path."
you want to avoid a test before either of these like: "if os.path.islink(...): ... continue ..."