]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/nominatim.py
move indexing function into its own Python module
[nominatim.git] / nominatim / nominatim.py
1 #! /usr/bin/env python3
2 #-----------------------------------------------------------------------------
3 # nominatim - [description]
4 #-----------------------------------------------------------------------------
5 #
6 # Indexing tool for the Nominatim database.
7 #
8 # Based on C version by Brian Quinion
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 #-----------------------------------------------------------------------------
24 from argparse import ArgumentParser, RawDescriptionHelpFormatter
25 import logging
26 import sys
27 import getpass
28
29 from indexer.indexer import Indexer
30
31 def nominatim_arg_parser():
32     """ Setup the command-line parser for the tool.
33     """
34     parser = ArgumentParser(description="Indexing tool for Nominatim.",
35                             formatter_class=RawDescriptionHelpFormatter)
36
37     parser.add_argument('-d', '--database',
38                         dest='dbname', action='store', default='nominatim',
39                         help='Name of the PostgreSQL database to connect to.')
40     parser.add_argument('-U', '--username',
41                         dest='user', action='store',
42                         help='PostgreSQL user name.')
43     parser.add_argument('-W', '--password',
44                         dest='password_prompt', action='store_true',
45                         help='Force password prompt.')
46     parser.add_argument('-H', '--host',
47                         dest='host', action='store',
48                         help='PostgreSQL server hostname or socket location.')
49     parser.add_argument('-P', '--port',
50                         dest='port', action='store',
51                         help='PostgreSQL server port')
52     parser.add_argument('-b', '--boundary-only',
53                         dest='boundary_only', action='store_true',
54                         help='Only index administrative boundaries (ignores min/maxrank).')
55     parser.add_argument('-r', '--minrank',
56                         dest='minrank', type=int, metavar='RANK', default=0,
57                         help='Minimum/starting rank.')
58     parser.add_argument('-R', '--maxrank',
59                         dest='maxrank', type=int, metavar='RANK', default=30,
60                         help='Maximum/finishing rank.')
61     parser.add_argument('-t', '--threads',
62                         dest='threads', type=int, metavar='NUM', default=1,
63                         help='Number of threads to create for indexing.')
64     parser.add_argument('-v', '--verbose',
65                         dest='loglevel', action='count', default=0,
66                         help='Increase verbosity')
67
68     return parser
69
70 if __name__ == '__main__':
71     OPTIONS = nominatim_arg_parser().parse_args(sys.argv[1:])
72
73     logging.basicConfig(stream=sys.stderr, format='%(levelname)s: %(message)s',
74                         level=max(3 - OPTIONS.loglevel, 0) * 10)
75
76     OPTIONS.password = None
77     if OPTIONS.password_prompt:
78         PASSWORD = getpass.getpass("Database password: ")
79         OPTIONS.password = PASSWORD
80
81     if OPTIONS.boundary_only:
82         Indexer(OPTIONS).index_boundaries()
83     else:
84         Indexer(OPTIONS).index_by_rank()