]>
git.ipfire.org Git - people/ms/libloc.git/blob - src/python/location-importer.in
2 ###############################################################################
4 # libloc - A library to determine the location of someone on the Internet #
6 # Copyright (C) 2020 IPFire Development Team <info@ipfire.org> #
8 # This library is free software; you can redistribute it and/or #
9 # modify it under the terms of the GNU Lesser General Public #
10 # License as published by the Free Software Foundation; either #
11 # version 2.1 of the License, or (at your option) any later version. #
13 # This library is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
16 # Lesser General Public License for more details. #
18 ###############################################################################
24 # Load our location module
26 import location
.database
27 import location
.importer
28 from location
.i18n
import _
31 log
= logging
.getLogger("location.importer")
36 parser
= argparse
.ArgumentParser(
37 description
=_("Location Importer Command Line Interface"),
40 # Global configuration flags
41 parser
.add_argument("--debug", action
="store_true",
42 help=_("Enable debug output"))
45 parser
.add_argument("--version", action
="version",
46 version
="%(prog)s @VERSION@")
49 parser
.add_argument("--database-host", required
=True,
50 help=_("Database Hostname"), metavar
=_("HOST"))
51 parser
.add_argument("--database-name", required
=True,
52 help=_("Database Name"), metavar
=_("NAME"))
53 parser
.add_argument("--database-username", required
=True,
54 help=_("Database Username"), metavar
=_("USERNAME"))
55 parser
.add_argument("--database-password", required
=True,
56 help=_("Database Password"), metavar
=_("PASSWORD"))
58 args
= parser
.parse_args()
60 # Enable debug logging
62 log
.setLevel(logging
.DEBUG
)
67 # Parse command line arguments
68 args
= self
.parse_cli()
71 db
= self
._setup
_database
(args
)
74 ret
= self
.handle_import(db
, args
)
76 # Return with exit code
83 def _setup_database(self
, ns
):
85 Initialise the database
88 db
= location
.database
.Connection(
89 host
=ns
.database_host
, database
=ns
.database_name
,
90 user
=ns
.database_username
, password
=ns
.database_password
,
93 with db
.transaction():
95 CREATE TABLE IF NOT EXISTS asnums(number integer, name text);
96 CREATE UNIQUE INDEX IF NOT EXISTS asnums_number ON asnums(number);
101 def handle_import(self
, db
, ns
):
106 # Run the command line interface