forked from RafaelKuebler/PyToUML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
68 lines (51 loc) · 2.02 KB
/
run.py
File metadata and controls
68 lines (51 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys
import json
import logging
import datetime
from os import walk
from typing import List
from pathlib import Path
from desc import ClassDesc
from source_to_desc import analyze_py_file
from desc_to_uml import desc_to_uml
def main():
configure_logger()
all_classes: List[ClassDesc] = []
if not os.path.exists("output"):
os.makedirs("output")
# in_path = input("Please provide the path to search in: ")
in_path = Path(".")
for dir_path, dir_names, file_names in walk(in_path):
logging.info(f"Searching sources in {dir_path}")
for file_name in file_names:
if not file_name.endswith(".py"):
continue
file_path = Path(dir_path) / Path(file_name)
logging.info(f"Analyzing file {file_path}...")
classes = analyze_py_file(file_path)
# export_json_file(classes, Path(f"./output/{file_name[:-3]}.json"))
all_classes += classes
desc_to_uml(all_classes, Path("./output/plantuml.txt"))
#####
# no more os.startfile.... at least on macos, cross platform solution possible:
# https://stackoverflow.com/questions/17317219/is-there-an-platform-independent-equivalent-of-os-startfile
os.startfile(Path("./output/plantuml.png"))
def configure_logger():
if not os.path.exists('logs'):
os.makedirs('logs')
log_filename = datetime.date.today()
logging.basicConfig(filename=f'logs/{log_filename}.log',
filemode='w',
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s')
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
def export_json_file(classes: List[ClassDesc], out_path: Path) -> None:
logging.info(f"Exporting json to {out_path}")
with out_path.open('w') as output:
json.dump(classes, output, cls=MyEncoder, indent=2)
class MyEncoder(json.JSONEncoder):
def default(self, o):
return o.__dict__
if __name__ == "__main__":
main()