Skip to content
Snippets Groups Projects
Commit a3a77458 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-parser' into 'dev'

ENH: allow using the parser as cmd line tool

See merge request !50
parents 6de42175 b48796e2
No related branches found
No related tags found
2 merge requests!54REL: Release 0.5.0,!50ENH: allow using the parser as cmd line tool
Pipeline #27055 passed with warnings
...@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## ## [Unreleased] ##
### Added ### ### Added ###
- You can now use `python -m caosadvancedtools.models.parser model_file` to
parse and potentially synchronize data models.
### Changed ### ### Changed ###
......
...@@ -36,6 +36,7 @@ Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs ...@@ -36,6 +36,7 @@ Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs
to be a list with the names. Here, NO NEW entities can be defined. to be a list with the names. Here, NO NEW entities can be defined.
""" """
import json import json
import argparse
import re import re
import sys import sys
import yaml import yaml
...@@ -796,5 +797,25 @@ class JsonSchemaParser(Parser): ...@@ -796,5 +797,25 @@ class JsonSchemaParser(Parser):
if __name__ == "__main__": if __name__ == "__main__":
model = parse_model_from_yaml('data_model.yml') parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("data_model",
help="Path name of the data model file (yaml or json) to be used.")
parser.add_argument("--sync", action="store_true",
help="Whether or not to sync the data model with the server.")
parser.add_argument("--noquestion", action="store_true",
help="Whether or not to ask questions during synchronization.")
parser.add_argument("--print", action="store_true",
help="Whether or not to print the data model.")
args = parser.parse_args()
if args.data_model.endswith(".json"):
model = parse_model_from_json_schema(args.data_model)
elif args.data_model.endswith(".yml") or args.data_model.endswith(".yaml"):
model = parse_model_from_yaml(args.data_model)
else:
RuntimeError("did not recognize file ending")
if args.print:
print(model) print(model)
if args.sync:
model.sync_data_model(noquestion=args.noquestion)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment