2 Implementation of the 'add-data' subcommand.
 
   8 # Do not repeat documentation of subcommand classes.
 
   9 # pylint: disable=C0111
 
  10 # Using non-top-level imports to avoid eventually unused imports.
 
  11 # pylint: disable=E0012,C0415
 
  13 LOG = logging.getLogger()
 
  17     Add additional data from a file or an online source.
 
  19     This command allows to add or update the search data in the database.
 
  20     The data can come either from an OSM file or single OSM objects can
 
  21     directly be downloaded from the OSM API. This function only loads the
 
  22     data into the database. Afterwards it still needs to be integrated
 
  23     in the search index. Use the `nominatim index` command for that.
 
  25     The command can also be used to add external non-OSM data to the
 
  26     database. At the moment the only supported format is TIGER housenumber
 
  27     data. See the online documentation at
 
  28     https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us
 
  34         group_name = parser.add_argument_group('Source')
 
  35         group = group_name.add_mutually_exclusive_group(required=True)
 
  36         group.add_argument('--file', metavar='FILE',
 
  37                            help='Import data from an OSM file or diff file')
 
  38         group.add_argument('--diff', metavar='FILE',
 
  39                            help='Import data from an OSM diff file (deprecated: use --file)')
 
  40         group.add_argument('--node', metavar='ID', type=int,
 
  41                            help='Import a single node from the API')
 
  42         group.add_argument('--way', metavar='ID', type=int,
 
  43                            help='Import a single way from the API')
 
  44         group.add_argument('--relation', metavar='ID', type=int,
 
  45                            help='Import a single relation from the API')
 
  46         group.add_argument('--tiger-data', metavar='DIR',
 
  47                            help='Add housenumbers from the US TIGER census database')
 
  48         group = parser.add_argument_group('Extra arguments')
 
  49         group.add_argument('--use-main-api', action='store_true',
 
  50                            help='Use OSM API instead of Overpass to download objects')
 
  51         group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
 
  52                            help='Size of cache to be used by osm2pgsql (in MB)')
 
  53         group.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60,
 
  54                            help='Set timeout for file downloads')
 
  58         from nominatim.tokenizer import factory as tokenizer_factory
 
  59         from nominatim.tools import tiger_data, add_osm_data
 
  62             tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
 
  63             return tiger_data.add_tiger_data(args.tiger_data,
 
  65                                              args.threads or psutil.cpu_count()  or 1,
 
  68         osm2pgsql_params = args.osm2pgsql_options(default_cache=1000, default_threads=1)
 
  69         if args.file or args.diff:
 
  70             return add_osm_data.add_data_from_file(args.file or args.diff,
 
  74             return add_osm_data.add_osm_object('node', args.node,
 
  79             return add_osm_data.add_osm_object('way', args.way,
 
  84             return add_osm_data.add_osm_object('relation', args.relation,