Coverage for dak/process_policy.py: 81%

330 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-11-21 08:51 +0000

1"""Handles packages from policy queues 

2 

3@contact: Debian FTP Master <ftpmaster@debian.org> 

4@copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org> 

5@copyright: 2009 Joerg Jaspert <joerg@debian.org> 

6@copyright: 2009 Frank Lichtenheld <djpig@debian.org> 

7@copyright: 2009 Mark Hymers <mhy@debian.org> 

8@license: GNU General Public License version 2 or later 

9""" 

10 

11# This program is free software; you can redistribute it and/or modify 

12# it under the terms of the GNU General Public License as published by 

13# the Free Software Foundation; either version 2 of the License, or 

14# (at your option) any later version. 

15 

16# This program is distributed in the hope that it will be useful, 

17# but WITHOUT ANY WARRANTY; without even the implied warranty of 

18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19# GNU General Public License for more details. 

20 

21# You should have received a copy of the GNU General Public License 

22# along with this program; if not, write to the Free Software 

23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

24 

25################################################################################ 

26 

27# <mhy> So how do we handle that at the moment? 

28# <stew> Probably incorrectly. 

29 

30################################################################################ 

31 

32import datetime 

33import functools 

34import os 

35import re 

36import sys 

37import traceback 

38from collections.abc import Callable 

39from typing import NoReturn 

40 

41import apt_pkg 

42from sqlalchemy import select, sql 

43 

44import daklib.announce 

45import daklib.upload 

46import daklib.utils 

47from daklib import daklog, utils 

48from daklib.archive import ArchiveTransaction, source_component_from_package_list 

49from daklib.config import Config 

50from daklib.dbconn import ( 

51 ArchiveFile, 

52 Component, 

53 DBBinary, 

54 DBChange, 

55 DBConn, 

56 DBSource, 

57 Override, 

58 OverrideType, 

59 PolicyQueue, 

60 PolicyQueueUpload, 

61 PoolFile, 

62 get_mapped_component, 

63 get_suite_by_name, 

64) 

65from daklib.externalsignature import check_upload_for_external_signature_request 

66from daklib.packagelist import PackageList 

67from daklib.urgencylog import UrgencyLog 

68 

69# Globals 

70Options: apt_pkg.Configuration 

71Logger: daklog.Logger 

72 

73################################################################################ 

74 

75ProcessingCallable = Callable[ 

76 [PolicyQueueUpload, PolicyQueue, str, ArchiveTransaction], None 

77] 

78 

79 

80def do_comments( 

81 dir: str, 

82 srcqueue: PolicyQueue, 

83 opref: str, 

84 npref: str, 

85 line: str, 

86 fn: ProcessingCallable, 

87 transaction: ArchiveTransaction, 

88) -> None: 

89 session = transaction.session 

90 actions: list[tuple[PolicyQueueUpload, str]] = [] 

91 for comm in [x for x in os.listdir(dir) if x.startswith(opref)]: 

92 with open(os.path.join(dir, comm)) as fd: 

93 lines = fd.readlines() 

94 if len(lines) == 0 or lines[0] != line + "\n": 94 ↛ 95line 94 didn't jump to line 95 because the condition on line 94 was never true

95 continue 

96 

97 # If the ACCEPT includes a _<arch> we only accept that .changes. 

98 # Otherwise we accept all .changes that start with the given prefix 

99 changes_prefix = comm[len(opref) :] 

100 if changes_prefix.count("_") < 2: 

101 changes_prefix = changes_prefix + "_" 

102 else: 

103 changes_prefix = changes_prefix + ".changes" 

104 

105 uploads = session.scalars( 

106 select(PolicyQueueUpload) 

107 .filter_by(policy_queue=srcqueue) 

108 .join(PolicyQueueUpload.changes) 

109 .where(DBChange.changesname.startswith(changes_prefix, autoescape=True)) 

110 .order_by(PolicyQueueUpload.source_id) 

111 ) 

112 reason = "".join(lines[1:]) 

113 actions.extend((u, reason) for u in uploads) 

114 

115 if opref != npref: 

116 newcomm = npref + comm[len(opref) :] 

117 newcomm = utils.find_next_free(os.path.join(dir, newcomm)) 

118 transaction.fs.move(os.path.join(dir, comm), newcomm) 

119 

120 actions.sort() 

121 

122 for u, reason in actions: 

123 print("Processing changes file: {0}".format(u.changes.changesname)) 

124 fn(u, srcqueue, reason, transaction) 

125 

126 

127################################################################################ 

128 

129 

130def try_or_reject(function: ProcessingCallable) -> ProcessingCallable: 

131 @functools.wraps(function) 

132 def wrapper( 

133 upload: PolicyQueueUpload, 

134 srcqueue: PolicyQueue, 

135 comments: str, 

136 transaction: ArchiveTransaction, 

137 ) -> None: 

138 try: 

139 function(upload, srcqueue, comments, transaction) 

140 except Exception: 

141 comments = "An exception was raised while processing the package:\n{0}\nOriginal comments:\n{1}".format( 

142 traceback.format_exc(), comments 

143 ) 

144 try: 

145 transaction.rollback() 

146 real_comment_reject(upload, srcqueue, comments, transaction) 

147 except Exception: 

148 comments = "In addition an exception was raised while trying to reject the upload:\n{0}\nOriginal rejection:\n{1}".format( 

149 traceback.format_exc(), comments 

150 ) 

151 transaction.rollback() 

152 real_comment_reject( 

153 upload, srcqueue, comments, transaction, notify=False 

154 ) 

155 if not Options["No-Action"]: 155 ↛ 158line 155 didn't jump to line 158 because the condition on line 155 was always true

156 transaction.commit() 

157 else: 

158 transaction.rollback() 

159 

160 return wrapper 

161 

162 

163################################################################################ 

164 

165 

166@try_or_reject 

167def comment_accept( 

168 upload: PolicyQueueUpload, 

169 srcqueue: PolicyQueue, 

170 comments: str, 

171 transaction: ArchiveTransaction, 

172) -> None: 

173 for byhand in upload.byhand: 173 ↛ 174line 173 didn't jump to line 174 because the loop on line 173 never started

174 path = os.path.join(srcqueue.path, byhand.filename) 

175 if os.path.exists(path): 

176 raise Exception( 

177 "E: cannot ACCEPT upload with unprocessed byhand file {0}".format( 

178 byhand.filename 

179 ) 

180 ) 

181 

182 cnf = Config() 

183 

184 fs = transaction.fs 

185 session = transaction.session 

186 changesname = upload.changes.changesname 

187 allow_tainted = srcqueue.suite.archive.tainted 

188 

189 # We need overrides to get the target component 

190 overridesuite = upload.target_suite 

191 if overridesuite.overridesuite is not None: 

192 overridesuite = get_suite_by_name(overridesuite.overridesuite, session) 

193 

194 def binary_component_func(db_binary: DBBinary) -> Component: 

195 section = db_binary.proxy["Section"] 

196 component_name = "main" 

197 if section.find("/") != -1: 

198 component_name = section.split("/", 1)[0] 

199 component = get_mapped_component(component_name, session=session) 

200 assert component is not None 

201 return component 

202 

203 def is_debug_binary(db_binary: DBBinary) -> bool: 

204 return daklib.utils.is_in_debug_section(db_binary.proxy) 

205 

206 def has_debug_binaries(upload: PolicyQueueUpload) -> bool: 

207 return any(is_debug_binary(x) for x in upload.binaries) 

208 

209 def source_component_func(db_source: DBSource) -> Component: 

210 package_list = PackageList(db_source.proxy) 

211 component = source_component_from_package_list( 

212 package_list, upload.target_suite 

213 ) 

214 if component is not None: 214 ↛ 220line 214 didn't jump to line 220

215 component = get_mapped_component(component.component_name, session=session) 

216 assert component is not None 

217 return component 

218 

219 # Fallback for packages without Package-List field 

220 query = ( 

221 select(Override) 

222 .filter_by(suite=overridesuite, package=db_source.source) 

223 .join(OverrideType) 

224 .where(OverrideType.overridetype == "dsc") 

225 .join(Component) 

226 ) 

227 return session.execute(query).scalar_one().component 

228 

229 policy_queue = upload.target_suite.policy_queue 

230 if policy_queue == srcqueue: 

231 policy_queue = None 

232 

233 all_target_suites = [ 

234 upload.target_suite if policy_queue is None else policy_queue.suite 

235 ] 

236 if policy_queue is None or policy_queue.send_to_build_queues: 236 ↛ 239line 236 didn't jump to line 239 because the condition on line 236 was always true

237 all_target_suites.extend([q.suite for q in upload.target_suite.copy_queues]) 

238 

239 throw_away_binaries = False 

240 if upload.source is not None: 

241 source_component = source_component_func(upload.source) 

242 if upload.target_suite.suite_name in cnf.value_list( 

243 "Dinstall::ThrowAwayNewBinarySuites" 

244 ) and source_component.component_name in cnf.value_list( 

245 "Dinstall::ThrowAwayNewBinaryComponents" 

246 ): 

247 throw_away_binaries = True 

248 

249 for suite in all_target_suites: 

250 debug_suite = suite.debug_suite 

251 

252 if upload.source is not None: 

253 # If we have Source in this upload, let's include it into 

254 # upload suite. 

255 transaction.copy_source( 

256 upload.source, 

257 suite, 

258 source_component, 

259 allow_tainted=allow_tainted, 

260 ) 

261 

262 if ( 

263 not throw_away_binaries 

264 and debug_suite is not None 

265 and has_debug_binaries(upload) 

266 ): 

267 # If we're handing a debug package, we also need to include the 

268 # source in the debug suite as well. 

269 transaction.copy_source( 

270 upload.source, 

271 debug_suite, 

272 source_component_func(upload.source), 

273 allow_tainted=allow_tainted, 

274 ) 

275 

276 if not throw_away_binaries: 

277 for db_binary in upload.binaries: 

278 # Now, let's work out where to copy this guy to -- if it's 

279 # a debug binary, and the suite has a debug suite, let's go 

280 # ahead and target the debug suite rather then the stock 

281 # suite. 

282 copy_to_suite = suite 

283 if debug_suite is not None and is_debug_binary(db_binary): 

284 copy_to_suite = debug_suite 

285 

286 # build queues and debug suites may miss the source package 

287 # if this is a binary-only upload. 

288 if copy_to_suite != upload.target_suite: 

289 transaction.copy_source( 

290 db_binary.source, 

291 copy_to_suite, 

292 source_component_func(db_binary.source), 

293 allow_tainted=allow_tainted, 

294 ) 

295 

296 transaction.copy_binary( 

297 db_binary, 

298 copy_to_suite, 

299 binary_component_func(db_binary), 

300 allow_tainted=allow_tainted, 

301 extra_archives=[upload.target_suite.archive], 

302 ) 

303 

304 check_upload_for_external_signature_request( 

305 session, suite, copy_to_suite, db_binary 

306 ) 

307 

308 suite.update_last_changed() 

309 

310 # Copy .changes if needed 

311 if policy_queue is None and upload.target_suite.copychanges: 311 ↛ 312line 311 didn't jump to line 312 because the condition on line 311 was never true

312 src = os.path.join(upload.policy_queue.path, upload.changes.changesname) 

313 dst = os.path.join(upload.target_suite.path, upload.changes.changesname) 

314 fs.copy(src, dst, mode=upload.target_suite.archive.mode) 

315 

316 # List of files in the queue directory 

317 queue_files = [changesname] 

318 chg = daklib.upload.Changes( 

319 upload.policy_queue.path, changesname, keyrings=[], require_signature=False 

320 ) 

321 queue_files.extend(f.filename for f in chg.buildinfo_files) 

322 

323 # TODO: similar code exists in archive.py's `ArchiveUpload._install_policy` 

324 if policy_queue is not None: 

325 # register upload in policy queue 

326 new_upload = PolicyQueueUpload() 

327 new_upload.policy_queue = policy_queue 

328 new_upload.target_suite = upload.target_suite 

329 new_upload.changes = upload.changes 

330 new_upload.source = upload.source 

331 new_upload.binaries = upload.binaries 

332 session.add(new_upload) 

333 session.flush() 

334 

335 # copy .changes & similar to policy queue 

336 for fn in queue_files: 

337 src = os.path.join(upload.policy_queue.path, fn) 

338 dst = os.path.join(policy_queue.path, fn) 

339 transaction.fs.copy(src, dst, mode=policy_queue.change_perms) 

340 

341 # Copy upload to Process-Policy::CopyDir 

342 # Used on security.d.o to sync accepted packages to ftp-master, but this 

343 # should eventually be replaced by something else. 

344 copydir = cnf.get("Process-Policy::CopyDir") or None 

345 if policy_queue is None and copydir is not None: 345 ↛ 346line 345 didn't jump to line 346 because the condition on line 345 was never true

346 mode = upload.target_suite.archive.mode 

347 if upload.source is not None: 

348 for f in [df.poolfile for df in upload.source.srcfiles]: 

349 dst = os.path.join(copydir, f.basename) 

350 if not os.path.exists(dst): 

351 fs.copy(f.fullpath, dst, mode=mode) 

352 

353 for db_binary in upload.binaries: 

354 f = db_binary.poolfile 

355 dst = os.path.join(copydir, f.basename) 

356 if not os.path.exists(dst): 

357 fs.copy(f.fullpath, dst, mode=mode) 

358 

359 for fn in queue_files: 

360 src = os.path.join(upload.policy_queue.path, fn) 

361 dst = os.path.join(copydir, fn) 

362 # We check for `src` to exist as old uploads in policy queues 

363 # might still miss the `.buildinfo` files. 

364 if os.path.exists(src) and not os.path.exists(dst): 

365 fs.copy(src, dst, mode=mode) 

366 

367 if policy_queue is None: 

368 utils.process_buildinfos( 

369 upload.policy_queue.path, chg.buildinfo_files, fs, Logger 

370 ) 

371 

372 if policy_queue is None and upload.source is not None and not Options["No-Action"]: 

373 urgency = upload.changes.urgency 

374 # As per policy 5.6.17, the urgency can be followed by a space and a 

375 # comment. Extract only the urgency from the string. 

376 if " " in urgency: 376 ↛ 377line 376 didn't jump to line 377 because the condition on line 376 was never true

377 urgency, comment = urgency.split(" ", 1) 

378 if urgency not in cnf.value_list("Urgency::Valid"): 378 ↛ 379line 378 didn't jump to line 379 because the condition on line 378 was never true

379 urgency = cnf["Urgency::Default"] 

380 UrgencyLog().log(upload.source.source, upload.source.version, urgency) 

381 

382 if policy_queue is None: 

383 print(" ACCEPT") 

384 else: 

385 print(" ACCEPT-TO-QUEUE") 

386 if not Options["No-Action"]: 386 ↛ 389line 386 didn't jump to line 389 because the condition on line 386 was always true

387 Logger.log(["Policy Queue ACCEPT", srcqueue.queue_name, changesname]) 

388 

389 if policy_queue is None: 

390 pu = get_processed_upload(upload) 

391 daklib.announce.announce_accept(pu) 

392 

393 # TODO: code duplication. Similar code is in process-upload. 

394 # Move .changes to done 

395 now = datetime.datetime.now(tz=datetime.UTC) 

396 donedir = os.path.join(cnf["Dir::Done"], now.strftime("%Y/%m/%d")) 

397 if policy_queue is None: 

398 for fn in queue_files: 

399 src = os.path.join(upload.policy_queue.path, fn) 

400 if os.path.exists(src): 400 ↛ 398line 400 didn't jump to line 398 because the condition on line 400 was always true

401 dst = os.path.join(donedir, fn) 

402 dst = utils.find_next_free(dst) 

403 fs.copy(src, dst, mode=0o644) 

404 

405 if throw_away_binaries and upload.target_suite.archive.use_morgue: 

406 morguesubdir = cnf.get("New::MorgueSubDir", "new") 

407 

408 utils.move_to_morgue( 

409 morguesubdir, 

410 [db_binary.poolfile.fullpath for db_binary in upload.binaries], 

411 fs, 

412 Logger, 

413 ) 

414 

415 remove_upload(upload, transaction) 

416 

417 

418################################################################################ 

419 

420 

421@try_or_reject 

422def comment_reject(*args) -> None: 

423 real_comment_reject(*args, manual=True) 

424 

425 

426def real_comment_reject( 

427 upload: PolicyQueueUpload, 

428 srcqueue: PolicyQueue, 

429 comments: str, 

430 transaction: ArchiveTransaction, 

431 notify=True, 

432 *, 

433 manual=False, 

434) -> None: 

435 cnf = Config() 

436 

437 fs = transaction.fs 

438 session = transaction.session 

439 changesname = upload.changes.changesname 

440 queuedir = upload.policy_queue.path 

441 rejectdir = cnf["Dir::Reject"] 

442 

443 ### Copy files to reject/ 

444 

445 poolfiles = [b.poolfile for b in upload.binaries] 

446 if upload.source is not None: 446 ↛ 449line 446 didn't jump to line 449 because the condition on line 446 was always true

447 poolfiles.extend([df.poolfile for df in upload.source.srcfiles]) 

448 # Not beautiful... 

449 files = [ 

450 af.path 

451 for af in session.scalars( 

452 select(ArchiveFile) 

453 .filter_by(archive=upload.policy_queue.suite.archive) 

454 .join(ArchiveFile.file) 

455 .where(PoolFile.file_id.in_([f.file_id for f in poolfiles])) 

456 ) 

457 ] 

458 for byhand in upload.byhand: 458 ↛ 459line 458 didn't jump to line 459 because the loop on line 458 never started

459 path = os.path.join(queuedir, byhand.filename) 

460 if os.path.exists(path): 

461 files.append(path) 

462 chg = daklib.upload.Changes( 

463 queuedir, changesname, keyrings=[], require_signature=False 

464 ) 

465 for f in chg.buildinfo_files: 

466 path = os.path.join(queuedir, f.filename) 

467 if os.path.exists(path): 467 ↛ 465line 467 didn't jump to line 465 because the condition on line 467 was always true

468 files.append(path) 

469 files.append(os.path.join(queuedir, changesname)) 

470 

471 for fn in files: 

472 dst = utils.find_next_free(os.path.join(rejectdir, os.path.basename(fn))) 

473 fs.copy(fn, dst, link=True) 

474 

475 ### Write reason 

476 

477 dst = utils.find_next_free( 

478 os.path.join(rejectdir, "{0}.reason".format(changesname)) 

479 ) 

480 fh = fs.create(dst) 

481 fh.write(comments) 

482 fh.close() 

483 

484 ### Send mail notification 

485 

486 if notify: 486 ↛ 500line 486 didn't jump to line 500 because the condition on line 486 was always true

487 rejected_by = None 

488 reason = comments 

489 

490 # Try to use From: from comment file if there is one. 

491 # This is not very elegant... 

492 match = re.match(r"\AFrom: ([^\n]+)\n\n", comments) 

493 if match: 493 ↛ 497line 493 didn't jump to line 497 because the condition on line 493 was always true

494 rejected_by = match.group(1) 

495 reason = "\n".join(comments.splitlines()[2:]) 

496 

497 pu = get_processed_upload(upload) 

498 daklib.announce.announce_reject(pu, reason, rejected_by) 

499 

500 print(" REJECT") 

501 if not Options["No-Action"]: 501 ↛ 506line 501 didn't jump to line 506 because the condition on line 501 was always true

502 Logger.log( 

503 ["Policy Queue REJECT", srcqueue.queue_name, upload.changes.changesname] 

504 ) 

505 

506 changes = upload.changes 

507 remove_upload(upload, transaction) 

508 session.delete(changes) 

509 

510 

511################################################################################ 

512 

513 

514def remove_upload(upload: PolicyQueueUpload, transaction: ArchiveTransaction) -> None: 

515 fs = transaction.fs 

516 session = transaction.session 

517 

518 # Remove byhand and changes files. Binary and source packages will be 

519 # removed from {bin,src}_associations and eventually removed by clean-suites automatically. 

520 queuedir = upload.policy_queue.path 

521 for byhand in upload.byhand: 521 ↛ 522line 521 didn't jump to line 522 because the loop on line 521 never started

522 path = os.path.join(queuedir, byhand.filename) 

523 if os.path.exists(path): 

524 fs.unlink(path) 

525 session.delete(byhand) 

526 

527 chg = daklib.upload.Changes( 

528 queuedir, upload.changes.changesname, keyrings=[], require_signature=False 

529 ) 

530 queue_files = [upload.changes.changesname] 

531 queue_files.extend(f.filename for f in chg.buildinfo_files) 

532 for fn in queue_files: 

533 # We check for `path` to exist as old uploads in policy queues 

534 # might still miss the `.buildinfo` files. 

535 path = os.path.join(queuedir, fn) 

536 if os.path.exists(path): 536 ↛ 532line 536 didn't jump to line 532 because the condition on line 536 was always true

537 fs.unlink(path) 

538 

539 session.delete(upload) 

540 session.flush() 

541 

542 

543################################################################################ 

544 

545 

546def get_processed_upload(upload: PolicyQueueUpload) -> daklib.announce.ProcessedUpload: 

547 pu = daklib.announce.ProcessedUpload() 

548 

549 pu.maintainer = upload.changes.maintainer 

550 pu.changed_by = upload.changes.changedby 

551 pu.fingerprint = upload.changes.fingerprint 

552 pu.authorized_by_fingerprint = upload.changes.authorized_by_fingerprint 

553 

554 pu.suites = [upload.target_suite] 

555 pu.from_policy_suites = [upload.target_suite] 

556 

557 changes_path = os.path.join(upload.policy_queue.path, upload.changes.changesname) 

558 with open(changes_path, "r") as fd: 

559 pu.changes = fd.read() 

560 pu.changes_filename = upload.changes.changesname 

561 pu.sourceful = upload.source is not None 

562 pu.source = upload.changes.source 

563 pu.version = upload.changes.version 

564 pu.architecture = upload.changes.architecture 

565 pu.bugs = upload.changes.closes 

566 

567 pu.program = "process-policy" 

568 

569 return pu 

570 

571 

572################################################################################ 

573 

574 

575def remove_unreferenced_binaries( 

576 policy_queue: PolicyQueue, transaction: ArchiveTransaction 

577) -> None: 

578 """Remove binaries that are no longer referenced by an upload""" 

579 session = transaction.session 

580 suite = policy_queue.suite 

581 

582 query = sql.text( 

583 """ 

584 SELECT b.* 

585 FROM binaries b 

586 JOIN bin_associations ba ON b.id = ba.bin 

587 WHERE ba.suite = :suite_id 

588 AND NOT EXISTS (SELECT 1 FROM policy_queue_upload_binaries_map pqubm 

589 JOIN policy_queue_upload pqu ON pqubm.policy_queue_upload_id = pqu.id 

590 WHERE pqu.policy_queue_id = :policy_queue_id 

591 AND pqubm.binary_id = b.id)""" 

592 ) 

593 binaries = session.scalars( 

594 select(DBBinary).from_statement(query), 

595 { 

596 "suite_id": policy_queue.suite_id, 

597 "policy_queue_id": policy_queue.policy_queue_id, 

598 }, 

599 ) 

600 

601 for binary in binaries: 

602 Logger.log( 

603 [ 

604 "removed binary from policy queue", 

605 policy_queue.queue_name, 

606 binary.package, 

607 binary.version, 

608 ] 

609 ) 

610 transaction.remove_binary(binary, suite) 

611 

612 

613def remove_unreferenced_sources( 

614 policy_queue: PolicyQueue, transaction: ArchiveTransaction 

615) -> None: 

616 """Remove sources that are no longer referenced by an upload or a binary""" 

617 session = transaction.session 

618 suite = policy_queue.suite 

619 

620 query = sql.text( 

621 """ 

622 SELECT s.* 

623 FROM source s 

624 JOIN src_associations sa ON s.id = sa.source 

625 WHERE sa.suite = :suite_id 

626 AND NOT EXISTS (SELECT 1 FROM policy_queue_upload pqu 

627 WHERE pqu.policy_queue_id = :policy_queue_id 

628 AND pqu.source_id = s.id) 

629 AND NOT EXISTS (SELECT 1 FROM binaries b 

630 JOIN bin_associations ba ON b.id = ba.bin 

631 WHERE b.source = s.id 

632 AND ba.suite = :suite_id)""" 

633 ) 

634 sources = session.scalars( 

635 select(DBSource).from_statement(query), 

636 { 

637 "suite_id": policy_queue.suite_id, 

638 "policy_queue_id": policy_queue.policy_queue_id, 

639 }, 

640 ) 

641 

642 for source in sources: 

643 Logger.log( 

644 [ 

645 "removed source from policy queue", 

646 policy_queue.queue_name, 

647 source.source, 

648 source.version, 

649 ] 

650 ) 

651 transaction.remove_source(source, suite) 

652 

653 

654################################################################################ 

655 

656 

657def usage(status=0) -> NoReturn: 

658 print("""Usage: dak process-policy QUEUE""") 

659 sys.exit(status) 

660 

661 

662################################################################################ 

663 

664 

665def main() -> None: 

666 global Options, Logger 

667 

668 cnf = Config() 

669 session = DBConn().session() 

670 

671 Arguments = [ 

672 ("h", "help", "Process-Policy::Options::Help"), 

673 ("n", "no-action", "Process-Policy::Options::No-Action"), 

674 ] 

675 

676 for i in ["help", "no-action"]: 

677 key = "Process-Policy::Options::%s" % i 

678 if key not in cnf: 678 ↛ 676line 678 didn't jump to line 676 because the condition on line 678 was always true

679 cnf[key] = "" 

680 

681 queue_name = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined] 

682 

683 Options = cnf.subtree("Process-Policy::Options") 

684 if Options["Help"]: 

685 usage() 

686 

687 if len(queue_name) != 1: 687 ↛ 688line 687 didn't jump to line 688 because the condition on line 687 was never true

688 print("E: Specify exactly one policy queue") 

689 sys.exit(1) 

690 

691 queue_name = queue_name[0] 

692 

693 Logger = daklog.Logger("process-policy") 

694 if not Options["No-Action"]: 694 ↛ 697line 694 didn't jump to line 697 because the condition on line 694 was always true

695 urgencylog = UrgencyLog() 

696 

697 with ArchiveTransaction() as transaction: 

698 session = transaction.session 

699 pq = session.execute( 

700 select(PolicyQueue).filter_by(queue_name=queue_name) 

701 ).scalar_one_or_none() 

702 if pq is None: 702 ↛ 703line 702 didn't jump to line 703 because the condition on line 702 was never true

703 print("E: Cannot find policy queue %s" % queue_name) 

704 sys.exit(1) 

705 

706 commentsdir = os.path.join(pq.path, "COMMENTS") 

707 # The comments stuff relies on being in the right directory 

708 os.chdir(pq.path) 

709 

710 do_comments( 

711 commentsdir, 

712 pq, 

713 "REJECT.", 

714 "REJECTED.", 

715 "NOTOK", 

716 comment_reject, 

717 transaction, 

718 ) 

719 do_comments( 

720 commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, transaction 

721 ) 

722 do_comments( 

723 commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK", comment_accept, transaction 

724 ) 

725 

726 remove_unreferenced_binaries(pq, transaction) 

727 remove_unreferenced_sources(pq, transaction) 

728 

729 if not Options["No-Action"]: 729 ↛ exitline 729 didn't return from function 'main' because the condition on line 729 was always true

730 urgencylog.close()