-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape_code.py
More file actions
49 lines (35 loc) · 1.58 KB
/
scrape_code.py
File metadata and controls
49 lines (35 loc) · 1.58 KB
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
import os
folder_to_scrape = "../libdebug"
out_folder = "./from_pydoc/generated"
if os.path.exists(out_folder):
os.system(f"rm -rf {out_folder}")
def create_if_not_exists(folder):
if not os.path.exists(folder):
os.makedirs(folder)
def md_rename(file):
return file.replace(".py", ".md")
for root, dirs, files in os.walk(folder_to_scrape):
for file in files:
# Skip init files and such
if file.startswith("_"):
continue
# Only scrape .py, .c, and .h files
if file.endswith(".py"):
file_path = os.path.join(root, file)
print(f"File path: {file_path}")
# File path relative to libdebug/libdebug
file_path = file_path.replace(folder_to_scrape + "/", "")
print(f"Scraping {file_path}")
if "/" in file_path:
folder_to_create = os.path.join(out_folder, file_path[:file_path.rfind("/")])
else:
folder_to_create = out_folder
create_if_not_exists(folder_to_create)
print(f"Creating folder {folder_to_create}")
new_file_path = os.path.join(folder_to_create, md_rename(file))
print(f"Creating {new_file_path}")
# Write the file, including a yml header to avoid search priority problems
with open(new_file_path, "w") as f:
module_name = "libdebug." + file_path.split(".")[0].replace("/", ".")
what_to_write = f"---\ntitle: {module_name}\nboost: 0.5\n---\n# {module_name}\n::: {module_name}\n"
f.write(what_to_write)