-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_examples.py
executable file
·43 lines (30 loc) · 1.06 KB
/
load_examples.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
#!/usr/bin/env python3
import os
import examples
import py_asciirast as asciirast
def iter_submodules(module):
import pkgutil
import importlib
for _, module_name, _ in pkgutil.walk_packages(
module.__path__, module.__name__ + "."
):
yield importlib.import_module(module_name)
if is_windows := os.name == "nt":
from colorama import just_fix_windows_console
just_fix_windows_console()
if not os.path.exists(asciirast.get_libfile_path()):
print(f"Cannot file {asciirast.get_libfile_path()}. Please specify file path:")
asciirast.set_libfile_path(input())
if not os.path.exists(asciirast.get_libfile_path()):
raise Exception(
"Cannot find file. Try building the library before running this script."
)
l = list(iter_submodules(examples))
for i, module in enumerate(l):
print(f"{i} : {module.__name__.split('.')[1]}")
if not (inp := input()).isdigit():
print(f"{inp} is not a integer.")
elif not 0 <= int(inp) < len(l):
print(f"{inp} is not a valid index!")
else:
l[int(inp)].main()