Coverage for python/lsst/daf/butler/cli/cmd/_remove_runs.py: 41%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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 <http://www.gnu.org/licenses/>.
23import click
24from typing import Mapping, Sequence
26from ..utils import (
27 ButlerCommand,
28)
29from ..opt import (
30 collection_argument,
31 confirm_option,
32 options_file_option,
33 repo_argument,
34)
35from ... import script
38# messages emitted by remove-runs, defined separately for use in unit
39# tests.
40noRunCollectionsMsg = "No RUN collections were found."
41willRemoveRunsMsg = "The following RUN collections will be removed:"
42willRemoveDatasetsMsg = "The following datasets will be removed:"
43didRemoveRunsMsg = "The following RUN collections were removed:"
44didRemoveDatasetsMsg = "The following datasets were removed:"
45removedRunsMsg = "Removed collections"
46abortedMsg = "Aborted."
49def _print_remove(will: bool, runs: Sequence[str], datasets: Mapping[str, int]):
50 """Print the formatted remove statement.
52 Parameters
53 ----------
54 will : bool
55 True if remove "will" happen, False if the remove "did" happen.
56 runs : Sequence[str]
57 The RUNs that will be or were removed.
58 datasets : Mapping[str, int]
59 The dataset types & count that will be or were removed.
60 """
61 print(willRemoveRunsMsg if will else didRemoveRunsMsg)
62 print(", ".join(runs))
63 print(willRemoveDatasetsMsg if will else didRemoveDatasetsMsg)
64 print(", ".join([f"{i[0]}({i[1]})" for i in datasets.items()]))
67@click.command(cls=ButlerCommand)
68@repo_argument(required=True)
69@collection_argument(
70 help="COLLECTION is a glob-style expression that identifies the RUN collection(s) to remove."
71)
72@confirm_option()
73@options_file_option()
74def remove_runs(**kwargs):
75 """Remove one or more RUN collections.
77 This command can be used to remove RUN collections and the datasets within
78 them.
79 """
80 confirm = kwargs.pop("confirm")
81 result = script.removeRuns(**kwargs)
82 canRemoveRuns = len(result.runs)
83 if not canRemoveRuns:
84 print(noRunCollectionsMsg)
85 return
86 if confirm:
87 _print_remove(True, result.runs, result.datasets)
88 doContinue = click.confirm("Continue?", default=False)
89 if doContinue:
90 result.onConfirmation()
91 print(removedRunsMsg)
92 else:
93 print(abortedMsg)
94 else:
95 result.onConfirmation()
96 _print_remove(False, result.runs, result.datasets)