LSST Applications 24.1.6,g063fba187b+e7121a6b04,g0f08755f38+4e0faf0f7f,g12f32b3c4e+7915c4de30,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+94d9f37a33,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+9e154f3e8d,g6b1c1869cb+adc49b6f1a,g781aacb6e4+a8ce1bb630,g7af13505b9+3363a39af3,g7f202ee025+406ba613a5,g80478fca09+8fbba356e2,g82479be7b0+0d223595df,g858d7b2824+4e0faf0f7f,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+32d6120315,gacef1a1666+7f85da65db,gb58c049af0+d64f4d3760,gbcfae0f0a0+a8c62e8bb6,gc28159a63d+ae03bbfc84,gcf0d15dbbd+412a8a6f35,gda6a2b7d83+412a8a6f35,gdaeeff99f8+1711a396fd,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+4e0faf0f7f,gfa999e8aa5+17cd334064,gfb92a5be7c+4e0faf0f7f
LSST Data Management Base Package
Loading...
Searching...
No Matches
apdb_cli.py
Go to the documentation of this file.
1# This file is part of dax_apdb
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22from __future__ import annotations
23
24__all__ = ["main"]
25
26import argparse
27from collections.abc import Sequence
28
29from .. import scripts
30from . import options
31from .logging_cli import LoggingCli
32
33
34def main(args: Sequence[str] | None = None) -> None:
35 """APDB command line tools."""
36 parser = argparse.ArgumentParser(description="APDB command line tools")
37 log_cli = LoggingCli(parser)
38
39 subparsers = parser.add_subparsers(title="available subcommands", required=True)
40 _create_sql_subcommand(subparsers)
44 _list_index_subcommand(subparsers)
45 _metadata_subcommand(subparsers)
46
47 parsed_args = parser.parse_args(args)
48 log_cli.process_args(parsed_args)
49
50 kwargs = vars(parsed_args)
51 # Strip keywords not understood by scripts.
52 method = kwargs.pop("method")
53 method(**kwargs)
54
55
56def _create_sql_subcommand(subparsers: argparse._SubParsersAction) -> None:
57 parser = subparsers.add_parser("create-sql", help="Create new APDB instance in SQL database.")
58 parser.add_argument("db_url", help="Database URL in SQLAlchemy format for APDB instance.")
59 parser.add_argument("output_config", help="Name of the new configuration file for created APDB instance.")
62 parser.add_argument(
63 "--drop", help="If True then drop existing tables.", default=False, action="store_true"
64 )
65 parser.set_defaults(method=scripts.create_sql)
66
67
68def _create_cassandra_subcommand(subparsers: argparse._SubParsersAction) -> None:
69 parser = subparsers.add_parser("create-cassandra", help="Create new APDB instance in Cassandra cluster.")
70 parser.add_argument("host", help="One or more host names for Cassandra cluster.", nargs="+")
71 parser.add_argument(
72 "keyspace", help="Cassandra keyspace name for APDB tables, will be created if does not exist."
73 )
74 parser.add_argument("output_config", help="Name of the new configuration file for created APDB instance.")
77 parser.add_argument(
78 "--drop", help="If True then drop existing tables.", default=False, action="store_true"
79 )
80 parser.set_defaults(method=scripts.create_cassandra)
81
82
83def _list_cassandra_subcommand(subparsers: argparse._SubParsersAction) -> None:
84 parser = subparsers.add_parser("list-cassandra", help="List APDB instances in Cassandra cluster.")
85 parser.add_argument("host", help="One of the host names for Cassandra cluster.")
86 parser.add_argument(
87 "-v",
88 "--verbose",
89 help="Provide full list of roles and associated permissions.",
90 default=False,
91 action="store_true",
92 )
93 parser.set_defaults(method=scripts.list_cassandra)
94
95
96def _delete_cassandra_subcommand(subparsers: argparse._SubParsersAction) -> None:
97 parser = subparsers.add_parser("delete-cassandra", help="Delete APDB instance from Cassandra cluster.")
98 parser.add_argument("host", help="One of the host names for Cassandra cluster.")
99 parser.add_argument("keyspace", help="Cassandra keyspace name for APDB tables.")
100 parser.add_argument(
101 "-y",
102 "--confirm",
103 help="Assume 'yes' answer for confirmation.",
104 default=False,
105 action="store_true",
106 )
107 parser.set_defaults(method=scripts.delete_cassandra)
108
109
110def _list_index_subcommand(subparsers: argparse._SubParsersAction) -> None:
111 parser = subparsers.add_parser("list-index", help="List contents of APDB index file.")
112 parser.add_argument(
113 "index_path", help="Location of index file, if missing then $DAX_APDB_INDEX_URI is used.", nargs="?"
114 )
115 parser.set_defaults(method=scripts.list_index)
116
117
118def _metadata_subcommand(subparsers: argparse._SubParsersAction) -> None:
119 parser = subparsers.add_parser("metadata", help="Operations with APDB metadata table.")
120 subparsers = parser.add_subparsers(title="available subcommands", required=True)
121 _metadata_set_subcommand(subparsers)
122 _metadata_get_subcommand(subparsers)
123 _metadata_show_subcommand(subparsers)
125
126
127def _metadata_show_subcommand(subparsers: argparse._SubParsersAction) -> None:
128 parser = subparsers.add_parser("show", help="Show contents of APDB metadata table.")
129 parser.add_argument(
130 "-j",
131 "--json",
132 dest="use_json",
133 help="Dump metadata in JSON format.",
134 default=False,
135 action="store_true",
136 )
137 parser.add_argument("config", help="Path or URI of APDB configuration file.")
138 parser.set_defaults(method=scripts.metadata_show)
139
140
141def _metadata_get_subcommand(subparsers: argparse._SubParsersAction) -> None:
142 parser = subparsers.add_parser("get", help="Print value of the metadata item.")
143 parser.add_argument("config", help="Path or URI of APDB configuration file.")
144 parser.add_argument("key", help="Metadata key, arbitrary string.")
145 parser.set_defaults(method=scripts.metadata_get)
146
147
148def _metadata_set_subcommand(subparsers: argparse._SubParsersAction) -> None:
149 parser = subparsers.add_parser("set", help="Add or update metadata item.")
150 parser.add_argument(
151 "-f",
152 "--force",
153 help="Force update of the existing key.",
154 default=False,
155 action="store_true",
156 )
157 parser.add_argument("config", help="Path or URI of APDB configuration file.")
158 parser.add_argument("key", help="Metadata key, arbitrary string.")
159 parser.add_argument("value", help="Corresponding metadata value.")
160 parser.set_defaults(method=scripts.metadata_set)
161
162
163def _metadata_delete_subcommand(subparsers: argparse._SubParsersAction) -> None:
164 parser = subparsers.add_parser("delete", help="Delete metadata item.")
165 parser.add_argument("config", help="Path or URI of APDB configuration file.")
166 parser.add_argument("key", help="Metadata key, arbitrary string.")
167 parser.set_defaults(method=scripts.metadata_delete)
None _create_sql_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:56
None _metadata_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:118
None _metadata_get_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:141
None _list_cassandra_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:83
None main(Sequence[str]|None args=None)
Definition apdb_cli.py:34
None _delete_cassandra_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:96
None _create_cassandra_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:68
None _list_index_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:110
None _metadata_delete_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:163
None _metadata_set_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:148
None _metadata_show_subcommand(argparse._SubParsersAction subparsers)
Definition apdb_cli.py:127
None common_apdb_options(argparse.ArgumentParser parser)
Definition options.py:54
None cassandra_config_options(argparse.ArgumentParser parser)
Definition options.py:87
None sql_config_options(argparse.ArgumentParser parser)
Definition options.py:67