Skip to content

Commit

Permalink
[python] Add tags mode for dump_mwm
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana-yan authored and gmoryes committed Feb 6, 2020
1 parent 04e2eea commit 5c53720
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tools/python/mwm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def dump_mwm():
parser.add_argument("--path", type=str, required=True,
help="Path to mwm.")
parser.add_argument("--format", type=str, default="meta",
choices=("meta", "features"),
choices=("meta", "features", "tags"),
help="Output format.")
args = parser.parse_args(sys.argv[2:])
dump_mwm(args.path, args.format)
Expand Down
9 changes: 5 additions & 4 deletions tools/python/mwm/dump_mwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ def dump_mwm(path, format):
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]),
"..", "..", "..", "data", "types.txt"))
header = mwm.read_header()
fts = list(mwm.iter_features())

if format == "meta":
if format == "meta" or format == "tags":
print("Tags:")
tvv = sorted([(k, v[0], v[1]) for k, v in mwm.tags.items()], key=lambda x: x[1])
for tv in tvv:
print(" {0:<8}: offs {1:9} len {2:8}".format(tv[0], tv[1], tv[2]))

if format == "meta":
v = mwm.read_version()
print("Format: {0}, version: {1}".format(v["fmt"], v["date"].strftime("%Y-%m-%d %H:%M")))
print("Header: {0}".format(header))
print("Region Info: {0}".format(mwm.read_region_info()))
print("Metadata count: {0}".format(len(mwm.read_metadata())))
print("Feature count: {0}".format(len(fts)))
print("Feature count: {0}".format(len(list(mwm.iter_features()))))
cross = mwm.read_crossmwm()
if cross:
print("Outgoing points: {0}, incoming: {1}".format(len(cross["out"]), len(cross["in"])))
print("Outgoing regions: {0}".format(set(cross["neighbours"])))

elif format == "features":
fts = list(mwm.iter_features())
print("Features:")
for ft in fts:
print(json.dumps(ft, ensure_ascii=False))

0 comments on commit 5c53720

Please sign in to comment.