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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
import argparse
import logging
import sys
from mwm.decode_id import decode_id
from mwm.dump_mwm import dump_mwm
from mwm.find_feature import find_and_print_features
from mwm.ft2osm import ft2osm
from mwm.mwm_feature_compare import compare_mwm
logger = logging.getLogger("mwm")
logger.setLevel(logging.ERROR)
class Mwm:
def __init__(self):
parser = argparse.ArgumentParser(
description="Mwm utils",
usage="""mwm <command> [<args>]
The most commonly used mwm commands are:
decode_id Unpacks maps.me OSM id to an OSM object link.
dump_mwm Dumps some MWM structures.
find_feature Finds features in an mwm file based on a query.
ft2osm Finds an OSM object for a given feature id.
mwm_feature_compare Compares feature count in .mwm files.
""",
)
parser.add_argument("command", help="Subcommand to run")
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
print(f"Unrecognized command {args.command}")
parser.print_help()
exit(1)
getattr(self, args.command)()
@staticmethod
def decode_id():
parser = argparse.ArgumentParser(
description="Unpacks maps.me OSM id to an OSM object link."
)
parser.add_argument(
"--id", type=str, required=True, help="OsmId or url from osm.org."
)
args = parser.parse_args(sys.argv[2:])
id = decode_id(args.id)
if id is None:
print("Decode id error.")
exit(1)
print(id)
@staticmethod
def dump_mwm():
parser = argparse.ArgumentParser(description="Dumps some MWM structures.")
parser.add_argument("--path", type=str, required=True, help="Path to mwm.")
parser.add_argument(
"--format",
type=str,
default="str",
choices=("str", "json"),
help="Output format.",
)
parser.add_argument(
"--need_features", action="store_true", help="Need to dump features."
)
args = parser.parse_args(sys.argv[2:])
dump_mwm(args.path, args.format, args.need_features)
@staticmethod
def find_feature():
parser = argparse.ArgumentParser(
description="Finds features in an mwm file based on a query."
)
parser.add_argument("--path", type=str, required=True, help="Path to mwm.")
parser.add_argument(
"--type",
type=str,
required=True,
choices=["t", "et", "n", "m", "id"],
help="""Type:
t for inside types ("t hwtag" will find all hwtags-*)
et for exact type ("et shop" won\'t find shop-chemist)
n for names, case-sensitive ("n Starbucks" fo r all starbucks)
m for metadata keys ("m flats" for features with flats
id for feature id ("id 1234" for feature #1234""",
)
parser.add_argument(
"--str", type=str, required=True, help="String to find in mwm"
)
args = parser.parse_args(sys.argv[2:])
find_and_print_features(args.path, args.type, args.str)
@staticmethod
def ft2osm():
parser = argparse.ArgumentParser(
description="Finds features in an mwm file based on a query."
)
parser.add_argument(
"--path", type=str, required=True, help="Path to osm to feature mapping."
)
parser.add_argument("--id", type=str, required=True, help="Feature id.")
args = parser.parse_args(sys.argv[2:])
id = ft2osm(args.path, args.id)
if id is None:
print("Error: id not found.")
exit(1)
print(id)
@staticmethod
def mwm_feature_compare():
parser = argparse.ArgumentParser(
description="Compares feature count in .mwm files."
)
parser.add_argument(
"-n", "--new", help="New mwm files path", type=str, required=True
)
parser.add_argument(
"-o", "--old", help="Old mwm files path", type=str, required=True
)
parser.add_argument(
"-f", "--feature", help="Feature name to count", type=str, required=True
)
parser.add_argument(
"-t",
"--threshold",
help="Threshold in percent to warn",
type=int,
default=20,
)
args = parser.parse_args(sys.argv[2:])
compare_mwm(args.old, args.new, args.feature, args.threshold)
Mwm()
|