Loading [MathJax]/extensions/tex2jax.js
LSST Applications 28.0.0,g1653933729+a8ce1bb630,g1a997c3884+a8ce1bb630,g28da252d5a+5bd70b7e6d,g2bbee38e9b+638fca75ac,g2bc492864f+638fca75ac,g3156d2b45e+07302053f8,g347aa1857d+638fca75ac,g35bb328faa+a8ce1bb630,g3a166c0a6a+638fca75ac,g3e281a1b8c+7bbb0b2507,g4005a62e65+17cd334064,g414038480c+5b5cd4fff3,g41af890bb2+4ffae9de63,g4e1a3235cc+0f1912dca3,g6249c6f860+3c3976f90c,g80478fca09+46aba80bd6,g82479be7b0+77990446f6,g858d7b2824+78ba4d1ce1,g89c8672015+f667a5183b,g9125e01d80+a8ce1bb630,ga5288a1d22+2a6264e9ca,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc22bb204ba+78ba4d1ce1,gc28159a63d+638fca75ac,gcf0d15dbbd+32ddb6096f,gd6b7c0dfd1+3e339405e9,gda3e153d99+78ba4d1ce1,gda6a2b7d83+32ddb6096f,gdaeeff99f8+1711a396fd,gdd5a9049c5+b18c39e5e3,ge2409df99d+a5e4577cdc,ge33fd446bb+78ba4d1ce1,ge79ae78c31+638fca75ac,gf0baf85859+64e8883e75,gf5289d68f6+e1b046a8d7,gfa443fc69c+91d9ed1ecf,gfda6b12a05+8419469a56
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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