2 Implementation of the 'index' subcommand.
6 from ..db import status
7 from ..db.connection import connect
9 # Do not repeat documentation of subcommand classes.
10 # pylint: disable=C0111
11 # Using non-top-level imports to avoid eventually unused imports.
12 # pylint: disable=E0012,C0415
14 def _num_system_cpus():
16 cpus = len(os.sched_getaffinity(0))
17 except NotImplementedError:
20 return cpus or os.cpu_count()
25 Reindex all new and modified data.
30 group = parser.add_argument_group('Filter arguments')
31 group.add_argument('--boundaries-only', action='store_true',
32 help="""Index only administrative boundaries.""")
33 group.add_argument('--no-boundaries', action='store_true',
34 help="""Index everything except administrative boundaries.""")
35 group.add_argument('--minrank', '-r', type=int, metavar='RANK', default=0,
36 help='Minimum/starting rank')
37 group.add_argument('--maxrank', '-R', type=int, metavar='RANK', default=30,
38 help='Maximum/finishing rank')
42 from ..indexer.indexer import Indexer
44 indexer = Indexer(args.config.get_libpq_dsn(),
45 args.threads or _num_system_cpus() or 1)
47 if not args.no_boundaries:
48 indexer.index_boundaries(args.minrank, args.maxrank)
49 if not args.boundaries_only:
50 indexer.index_by_rank(args.minrank, args.maxrank)
52 if not args.no_boundaries and not args.boundaries_only \
53 and args.minrank == 0 and args.maxrank == 30:
54 conn = connect(args.config.get_libpq_dsn())
55 status.set_indexed(conn, True)