119def partition_delete_temporal(apdb_config: str, time: str, after: bool, force: bool) -> int:
120 """Delete some temporal partitions.
121
122 Parameters
123 ----------
124 apdb_config : `str`
125 URL for APDB configuration file.
126 time : `str`
127 Timestamps in ISOT format and TAI scale. Partition that includes this
128 time is not deleted.
129 after : `bool`
130 If `True` then delete partitions after the specified time. Default is
131 to delete partitions before this time.
132 force : `bool`
133 If `True` then do not ask confirmation.
134 """
135 try:
136 astro_time = astropy.time.Time(time, format="isot", scale="tai")
137 except ValueError as exc:
138 print(f"ERROR: {exc}", file=sys.stderr)
139 return 1
140
141 apdb = Apdb.from_uri(apdb_config)
142 if not isinstance(apdb, ApdbCassandra):
143 print("ERROR: Non-Cassandra APDB does not use time-partitioned tables.", file=sys.stderr)
144 return 1
145
146 admin = apdb.admin
147 try:
148 result = admin.delete_time_partitions(
149 astro_time, after=after, confirm=None if force else _confirm_delete
150 )
151 except (TypeError, ValueError) as exc:
152 print(f"ERROR: {exc}", file=sys.stderr)
153 return 1
154
155 part_range = admin.time_partitions()
156 start_time, _ = admin.partitioner.partition_period(part_range.start)
157 _, end_time = admin.partitioner.partition_period(part_range.end)
158
159 if result:
160 print(
161 "Time partitions succesfully deleted.\n"
162 f"New time partition range: {part_range.start} - {part_range.end} "
163 f"[{start_time.tai.isot}, {end_time.tai.isot})"
164 )
165 else:
166 print(
167 "Time partitions were not deleted.\n"
168 f"Current time partition range: {part_range.start} - {part_range.end} "
169 f"[{start_time.tai.isot}, {end_time.tai.isot})"
170 )
171
172 return 0
173
174