forked from maykinmedia/imvertor-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imvertorlite.py
72 lines (62 loc) · 1.82 KB
/
imvertorlite.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
import sys
import click
from parsers import EnterpriseArchitect, AmsterdamSchema
PARSERS = {
"enterprise_architect": EnterpriseArchitect,
"amsterdam_schema": AmsterdamSchema,
}
@click.command()
@click.option(
"file_name",
"--file",
"-f",
required=True,
help="Specify the name of the input file.",
)
@click.option(
"class_name", "--name", "-n", help="The UML class name of the object to export."
)
@click.option(
"encoding", "--encoding", "-e", help="Specify the encoding of the XML file (optional).",
)
@click.option(
"parser", "--parser", "-p", help=f"Supported parsers: {', '.join(PARSERS)}.",
)
@click.option(
"readme_template", "--readme-template", "-t",
help=f"The README template to be autogenerated from the output schema.",
)
@click.option(
"postfix", "--postfix", "-x",
help=f"Provide a postfix for the automatically generated files.",
)
def convert(file_name,
class_name=None,
encoding=None,
parser=None,
readme_template=None,
postfix=None,
):
"""
Exports one or more UML classes from an Enterprise Architect XML export to
JSON Schema.
"""
if parser in PARSERS:
parser = PARSERS[parser]
elif file_name.endswith(".json"):
parser = PARSERS['amsterdam_schema']
elif file_name.endswith(".xml"):
parser = PARSERS['enterprise_architect']
else:
print("Unsupported format.")
sys.exit(1)
p = parser(
readme_template=readme_template,
postfix=postfix,
)
p.process(file_name=file_name, class_name=class_name, encoding=encoding)
sys.exit(0)
if __name__ == "__main__":
import logging.config
logging.config.fileConfig("logging.conf")
convert()