added option to list path to mytools dir

This commit is contained in:
Ranomier 2024-12-13 20:19:44 +01:00
parent 692845b707
commit 5eb91c6806

21
mytools
View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# docstring=lists all tools and their docstrings # docstring=lists all tools and their docstrings
import argparse
import os import os
import os.path as path import os.path as path
@ -7,6 +8,8 @@ CFG = {
"max_lines": 20, "max_lines": 20,
"offset": 20 "offset": 20
} }
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
def parse_docstring(file_path, max_lines=CFG["max_lines"]): def parse_docstring(file_path, max_lines=CFG["max_lines"]):
""" """
@ -38,15 +41,14 @@ def offset(element, offset=CFG["offset"]):
return " " * (offset - element_length) return " " * (offset - element_length)
def main(): def list_tools():
""" """
lists all tools and their docstring from the same directory this sits in lists all tools and their docstring from the same directory this sits in
""" """
script_path = os.path.dirname(os.path.realpath(__file__)) list_dir = sorted(os.listdir(SCRIPT_PATH))
list_dir = sorted(os.listdir(script_path))
for element in list_dir: for element in list_dir:
element_path = path.join(script_path, element) element_path = path.join(SCRIPT_PATH, element)
if path.isfile(element_path): if path.isfile(element_path):
print(element, end="") print(element, end="")
docstring = parse_docstring(element_path) docstring = parse_docstring(element_path)
@ -55,5 +57,16 @@ def main():
print() print()
def main():
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", help="output path to tools directory", action="store_true")
args = ap.parse_args()
if args.path:
print(SCRIPT_PATH)
else:
list_tools()
if __name__ == "__main__": if __name__ == "__main__":
main() main()