forked from XRPLF/xrpl-dev-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_file_consistency.py
executable file
·76 lines (61 loc) · 2.01 KB
/
check_file_consistency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import os
import os.path
import ruamel.yaml
yaml = ruamel.yaml.YAML(typ="safe")
def should_include(fname):
"""
Return True if the given file/folder name should be checked.
Otherwise return False.
"""
if fname == "node_modules":
return False
if fname[:1] == "_":
return False
if ".git" in fname:
return False
return True
def list_mds(content_dir):
all_mds = []
for dirpath, dirnames, filenames in os.walk(content_dir, topdown=True):
dirnames[:] = [d for d in dirnames if should_include(d)]
filenames[:] = [f for f in filenames if should_include(f)]
for filename in filenames:
if filename[-3:] == ".md":
all_mds.append(os.path.relpath(os.path.join(dirpath,filename), content_dir))
return all_mds
def list_mds_in_dactyl_config(config_file):
with open(config_file, "r", encoding="utf-8") as f:
cfg = yaml.load(f)
# Config can contain the same file multiple times (e.g. variants across targets). De-dupe.
all_mds = list(set(pg["md"] for pg in cfg["pages"] if "md" in pg.keys()))
return all_mds
def report_mismatches(fs_mds, cfg_mds):
"""
Print a list of paths that aren't present in one or the other list
"""
fs_mds.sort()
cfg_mds.sort()
total_files = len(fs_mds)
total_pages = len(cfg_mds)
f_i = 0
p_i = 0
while f_i < total_files and p_i < total_pages:
fname = fs_mds[f_i]
pname = cfg_mds[p_i]
if fname == pname:
# print("Match:", fname)
f_i += 1
p_i += 1
elif fname < pname:
print("Missing from config:", fname)
f_i += 1
elif fname > pname:
print("Missing from filesystem:", pname)
p_i += 1
else:
print("Unexpected case:", fname, pname)
if __name__ == "__main__":
fs_mds = list_mds("./content/")
cfg_mds = list_mds_in_dactyl_config("dactyl-config.yml")
report_mismatches(fs_mds, cfg_mds)