[python] Add tags mode for dump_mwm

This commit is contained in:
tatiana-yan 2020-02-06 12:37:49 +03:00 committed by gmoryes
parent 04e2eea992
commit 5c537200ca
2 changed files with 6 additions and 5 deletions

View file

@ -48,7 +48,7 @@ The most commonly used mwm commands are:
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)

View file

@ -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))