Package dak :: Module manage_debug_suites
[hide private]
[frames] | no frames]

Source Code for Module dak.manage_debug_suites

  1  #! /usr/bin/env python3 
  2   
  3  """Manage debug suites 
  4   
  5  @contact: Debian FTP Master <ftpmaster@debian.org> 
  6  @copyright: 2015, Ansgar Burchardt <ansgar@debian.org> 
  7   
  8  """ 
  9   
 10  # This program is free software; you can redistribute it and/or modify 
 11  # it under the terms of the GNU General Public License as published by 
 12  # the Free Software Foundation; either version 2 of the License, or 
 13  # (at your option) any later version. 
 14   
 15  # This program is distributed in the hope that it will be useful, 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18  # GNU General Public License for more details. 
 19   
 20  # You should have received a copy of the GNU General Public License 
 21  # along with this program; if not, write to the Free Software 
 22  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 23   
 24  ################################################################################ 
 25   
 26  import sys 
 27   
 28  import apt_pkg 
 29   
 30  from daklib import daklog 
 31  from daklib.archive import ArchiveTransaction 
 32  from daklib.config import Config 
 33  from daklib.dbconn import Suite 
 34   
 35  ################################################################################ 
 36   
 37  Options = None 
 38  Logger = None 
 39   
 40  ################################################################################ 
 41   
 42   
43 -def usage(exit_code=0):
44 print( 45 """Usage: dak manage-debug-suites [-a|--all|<suite>...] 46 Manage the contents of one or more debug suites 47 48 -a, --all run on all known debug suites 49 -n, --no-action don't do anything 50 -h, --help show this help and exit""" 51 ) 52 53 sys.exit(exit_code)
54 55 56 ################################################################################ 57 58
59 -def clean(debug_suite, transaction):
60 session = transaction.session 61 62 # Sanity check: make sure this is a debug suite or we would remove everything 63 any_suite = session.query(Suite).filter_by(debug_suite=debug_suite).first() 64 if any_suite is None: 65 raise Exception( 66 "Suite '{0}' is not a debug suite".format(debug_suite.suite_name) 67 ) 68 69 # Only keep source packages that are still a base suite. 70 # All other sources and their binary packages can go. 71 query = """ 72 WITH 73 sources_to_keep AS 74 (SELECT DISTINCT sa.source 75 FROM src_associations sa 76 JOIN suite ON sa.suite = suite.id 77 WHERE suite.debugsuite_id = :debugsuite_id), 78 sources_removed AS 79 (DELETE FROM src_associations sa 80 WHERE sa.suite = :debugsuite_id 81 AND sa.source NOT IN (SELECT source FROM sources_to_keep) 82 RETURNING sa.source) 83 DELETE FROM bin_associations ba 84 USING binaries b 85 WHERE ba.suite = :debugsuite_id 86 AND ba.bin = b.id 87 AND b.source NOT IN (SELECT source FROM sources_to_keep) 88 RETURNING 89 b.package, 90 b.version, 91 (SELECT arch_string FROM architecture WHERE id=b.architecture) AS architecture 92 """ 93 result = session.execute(query, {"debugsuite_id": debug_suite.suite_id}) 94 for row in result: 95 Logger.log(["remove", debug_suite.suite_name, row[0], row[1], row[2]])
96 97
98 -def main():
99 global Options, Logger 100 101 cnf = Config() 102 103 for i in ["Help", "No-Action", "All"]: 104 key = "Manage-Debug-Suites::Options::%s" % i 105 if key not in cnf: 106 cnf[key] = "" 107 108 Arguments = [ 109 ("h", "help", "Manage-Debug-Suites::Options::Help"), 110 ("n", "no-action", "Manage-Debug-Suites::Options::No-Action"), 111 ("a", "all", "Manage-Debug-Suites::Options::All"), 112 ] 113 114 debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) 115 Options = cnf.subtree("Manage-Debug-Suites::Options") 116 117 if Options["Help"]: 118 usage() 119 120 Logger = daklog.Logger("manage-debug-suites", Options["No-Action"]) 121 122 with ArchiveTransaction() as transaction: 123 session = transaction.session 124 if Options["All"]: 125 if len(debug_suite_names) != 0: 126 print("E: Cannot use both -a and a queue name") 127 sys.exit(1) 128 raise Exception("Not yet implemented.") 129 else: 130 debug_suites = session.query(Suite).filter( 131 Suite.suite_name.in_(debug_suite_names) 132 ) 133 134 for debug_suite in debug_suites: 135 Logger.log(["cleaning debug suite {0}".format(debug_suite.suite_name)]) 136 clean(debug_suite, transaction) 137 if not Options["No-Action"]: 138 transaction.commit() 139 else: 140 transaction.rollback() 141 142 Logger.close()
143 144 145 ####################################################################################### 146 147 148 if __name__ == "__main__": 149 main() 150