2 Command-line interface to the Nominatim functions for import, update,
3 database administration and querying.
9 class CommandlineParser:
10 """ Wraps some of the common functions for parsing the command line
11 and setting up subcommands.
13 def __init__(self, prog, description):
14 self.parser = argparse.ArgumentParser(
16 description=description,
17 formatter_class=argparse.RawDescriptionHelpFormatter)
19 self.subs = self.parser.add_subparsers(title='available commands',
22 # Arguments added to every sub-command
23 self.default_args = argparse.ArgumentParser(add_help=False)
24 group = self.default_args.add_argument_group('Default arguments')
25 group.add_argument('-h', '--help', action='help',
26 help='Show this help message and exit')
27 group.add_argument('-q', '--quiet', action='store_const', const=0,
28 dest='verbose', default=1,
29 help='Print only error messages')
30 group.add_argument('-v', '--verbose', action='count', default=1,
31 help='Increase verboseness of output')
32 group.add_argument('--project-dir', metavar='DIR',
33 help='Base directory of the Nominatim installation (default:.)')
34 group.add_argument('-j', '--threads', metavar='NUM', type=int,
35 help='Number of parallel threads to use')
38 def add_subcommand(self, name, cmd):
39 """ Add a subcommand to the parser. The subcommand must be a class
40 with a function add_args() that adds the parameters for the
41 subcommand and a run() function that executes the command.
43 parser = self.subs.add_parser(name, parents=[self.default_args],
44 help=cmd.__doc__.split('\n', 1)[0],
45 description=cmd.__doc__,
46 formatter_class=argparse.RawDescriptionHelpFormatter,
48 parser.set_defaults(command=cmd)
52 """ Parse the command line arguments of the program and execute the
53 appropriate subcommand.
55 args = self.parser.parse_args()
57 if args.subcommand is None:
58 self.parser.print_help()
60 logging.basicConfig(stream=sys.stderr,
61 format='%(asctime)s %(levelname)s: %(message)s',
62 datefmt='%Y-%m-%d %H:%M:%S',
63 level=max(4 - args.verbose, 1) * 10)
64 args.command.run(args)
69 Create a new Nominatim database from an OSM file.
74 group_name = parser.add_argument_group('Required arguments')
75 group = group_name.add_mutually_exclusive_group(required=True)
76 group.add_argument('--osm-file',
77 help='OSM file to be imported.')
78 group.add_argument('--continue', nargs=1,
79 choices=['load-data', 'indexing', 'db-postprocess'],
80 help='Continue an import that was interrupted')
81 group = parser.add_argument_group('Optional arguments')
82 group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
83 help='Size of cache to be used by osm2pgsql (in MB)')
84 group.add_argument('--reverse-only', action='store_true',
85 help='Do not create tables and indexes for searching')
86 group.add_argument('--enable-debug-statements', action='store_true',
87 help='Include debug warning statements in SQL code')
88 group.add_argument('--no-partitions', action='store_true',
89 help="""Do not partition search indices
90 (speeds up import of single country extracts)""")
91 group.add_argument('--no-updates', action='store_true',
92 help="""Do not keep tables that are only needed for
93 updating the database later""")
94 group = parser.add_argument_group('Expert options')
95 group.add_argument('--ignore-errors', action='store_true',
96 help='Continue import even when errors in SQL are present')
97 group.add_argument('--disable-token-precalc', action='store_true',
98 help='Disable name precalculation')
99 group.add_argument('--index-noanalyse', action='store_true',
100 help='Do not perform analyse operations during index')
105 print("TODO: ./utils/setup.php", args)
110 Make database read-only.
112 About half of data in the Nominatim database is kept only to be able to
113 keep the data up-to-date with new changes made in OpenStreetMap. This
114 command drops all this data and only keeps the part needed for geocoding
117 This command has the same effect as the `--no-updates` option for imports.
121 def add_args(parser):
126 print("TODO: setup drop", args)
129 class SetupSpecialPhrases:
131 Maintain special phrases.
135 def add_args(parser):
136 group = parser.add_argument_group('Input arguments')
137 group.add_argument('--from-wiki', action='store_true',
138 help='Pull special phrases from the OSM wiki.')
139 group = parser.add_argument_group('Output arguments')
140 group.add_argument('-o', '--output', default='-',
141 type=argparse.FileType('w', encoding='UTF-8'),
142 help="""File to write the preprocessed phrases to.
143 If omitted, it will be written to stdout.""")
147 print("./utils/specialphrases.php --from-wiki", args)
150 class UpdateReplication:
152 Update the database using an online replication service.
156 def add_args(parser):
157 group = parser.add_argument_group('Arguments for initialisation')
158 group.add_argument('--init', action='store_true',
159 help='Initialise the update process')
160 group.add_argument('--no-update-functions', dest='update_functions',
161 action='store_false',
162 help="""Do not update the trigger function to
163 support differential updates.""")
164 group = parser.add_argument_group('Arguments for updates')
165 group.add_argument('--check-for-updates', action='store_true',
166 help='Check if new updates are available and exit')
167 group.add_argument('--once', action='store_true',
168 help="""Download and apply updates only once. When
169 not set, updates are continuously applied""")
170 group.add_argument('--no-index', action='store_false', dest='do_index',
171 help="""Do not index the new data. Only applicable
172 together with --once""")
177 print('./utils/update.php --init-updates', args)
179 print('./utils/update.php --import-osmosis(-all)', args)
184 Add additional data from a file or an online source.
186 Data is only imported, not indexed. You need to call `nominatim-update index`
187 to complete the process.
191 def add_args(parser):
192 group_name = parser.add_argument_group('Source')
193 group = group_name.add_mutually_exclusive_group(required=True)
194 group.add_argument('--file', metavar='FILE',
195 help='Import data from an OSM file')
196 group.add_argument('--diff', metavar='FILE',
197 help='Import data from an OSM diff file')
198 group.add_argument('--node', metavar='ID', type=int,
199 help='Import a single node from the API')
200 group.add_argument('--way', metavar='ID', type=int,
201 help='Import a single way from the API')
202 group.add_argument('--relation', metavar='ID', type=int,
203 help='Import a single relation from the API')
204 group.add_argument('--tiger-data', metavar='DIR',
205 help='Add housenumbers from the US TIGER census database.')
206 group = parser.add_argument_group('Extra arguments')
207 group.add_argument('--use-main-api', action='store_true',
208 help='Use OSM API instead of Overpass to download objects')
212 print('./utils/update.php --import-*', args)
217 Reindex all new and modified data.
221 def add_args(parser):
226 print('./utils/update.php --index', args)
231 Recompute auxillary data used by the indexing process.
233 These functions must not be run in parallel with other update commands.
237 def add_args(parser):
238 group = parser.add_argument_group('Data arguments')
239 group.add_argument('--postcodes', action='store_true',
240 help='Update postcode centroid table')
241 group.add_argument('--word-counts', action='store_true',
242 help='Compute frequency of full-word search terms')
243 group.add_argument('--address-levels', action='store_true',
244 help='Reimport address level configuration')
245 group.add_argument('--importance', action='store_true',
246 help='Recompute place importances')
247 group.add_argument('--functions', action='store_true',
248 help='Update the PL/pgSQL functions in the database')
249 group.add_argument('--wiki-data',
250 help='Update Wikipedia/data importance numbers.')
251 group.add_argument('--website', action='store_true',
252 help='Refresh the directory that serves the scripts for the web API')
253 group = parser.add_argument_group('Arguments for function refresh')
254 group.add_argument('--no-diff-updates', action='store_false', dest='diffs',
255 help='Do not enable code for propagating updates')
259 print('./utils/update.php', args)
262 class AdminCheckDatabase:
264 Check that the database is complete and operational.
268 def add_args(parser):
273 print("TODO: ./utils/check_import_finished.php", args)
278 Warm database caches for search and reverse queries.
282 def add_args(parser):
283 group = parser.add_argument_group('Target arguments')
284 group.add_argument('--search-only', action='store_const', dest='target',
286 help="Only pre-warm tables for search queries")
287 group.add_argument('--reverse-only', action='store_const', dest='target',
289 help="Only pre-warm tables for reverse queries")
293 print("TODO: ./utils/warm.php", args)
298 Export addresses as CSV file from a Nominatim database.
302 def add_args(parser):
303 group = parser.add_argument_group('Output arguments')
304 group.add_argument('--output-type', default='street',
305 choices=('continent', 'country', 'state', 'county',
306 'city', 'suburb', 'street', 'path'),
307 help='Type of places to output (default: street)')
308 group.add_argument('--output-format',
309 default='street;suburb;city;county;state;country',
310 help="""Semicolon-separated list of address types
311 (see --output-type). Multiple ranks can be
312 merged into one column by simply using a
313 comma-separated list.""")
314 group.add_argument('--output-all-postcodes', action='store_true',
315 help="""List all postcodes for address instead of
316 just the most likely one""")
317 group.add_argument('--language',
318 help="""Preferred language for output
319 (use local name, if omitted)""")
320 group = parser.add_argument_group('Filter arguments')
321 group.add_argument('--restrict-to-country', metavar='COUNTRY_CODE',
322 help='Export only objects within country')
323 group.add_argument('--restrict-to-osm-node', metavar='ID', type=int,
324 help='Export only children of this OSM node')
325 group.add_argument('--restrict-to-osm-way', metavar='ID', type=int,
326 help='Export only children of this OSM way')
327 group.add_argument('--restrict-to-osm-relation', metavar='ID', type=int,
328 help='Export only children of this OSM relation')
333 print("TODO: ./utils/export.php", args)
341 def add_args(parser):
345 print("TODO: searching")
348 def nominatim(**kwargs):
350 Command-line tools for importing, updating, administrating and
351 querying the Nominatim database.
353 parser = CommandlineParser('nominatim', nominatim.__doc__)
355 parser.add_subcommand('import', SetupAll)
356 parser.add_subcommand('freeze', SetupFreeze)
357 parser.add_subcommand('replication', UpdateReplication)
359 parser.add_subcommand('check-database', AdminCheckDatabase)
360 parser.add_subcommand('warm', AdminWarm)
362 parser.add_subcommand('special-phrases', SetupSpecialPhrases)
364 parser.add_subcommand('add-data', UpdateAddData)
365 parser.add_subcommand('index', UpdateIndex)
366 parser.add_subcommand('refresh', UpdateRefresh)
368 parser.add_subcommand('export', QueryExport)
369 parser.add_subcommand('search', QueryTodo)
370 parser.add_subcommand('reverse', QueryTodo)
371 parser.add_subcommand('lookup', QueryTodo)
372 parser.add_subcommand('details', QueryTodo)
373 parser.add_subcommand('status', QueryTodo)