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 apt_pkg 
 27  import sys 
 28   
 29  from daklib import daklog 
 30  from daklib.archive import ArchiveTransaction 
 31  from daklib.dbconn import * 
 32  from daklib.config import Config 
 33   
 34  ################################################################################ 
 35   
 36  Options = None 
 37  Logger = None 
 38   
 39  ################################################################################ 
 40   
 41   
42 -def usage(exit_code=0):
43 print("""Usage: dak manage-debug-suites [-a|--all|<suite>...] 44 Manage the contents of one or more debug suites 45 46 -a, --all run on all known debug suites 47 -n, --no-action don't do anything 48 -h, --help show this help and exit""") 49 50 sys.exit(exit_code)
51 52 ################################################################################ 53 54
55 -def clean(debug_suite, transaction):
56 session = transaction.session 57 58 # Sanity check: make sure this is a debug suite or we would remove everything 59 any_suite = session.query(Suite).filter_by(debug_suite=debug_suite).first() 60 if any_suite is None: 61 raise Exception("Suite '{0}' is not a debug suite".format(debug_suite.suite_name)) 62 63 # Only keep source packages that are still a base suite. 64 # All other sources and their binary packages can go. 65 query = """ 66 WITH 67 sources_to_keep AS 68 (SELECT DISTINCT sa.source 69 FROM src_associations sa 70 JOIN suite ON sa.suite = suite.id 71 WHERE suite.debugsuite_id = :debugsuite_id), 72 sources_removed AS 73 (DELETE FROM src_associations sa 74 WHERE sa.suite = :debugsuite_id 75 AND sa.source NOT IN (SELECT source FROM sources_to_keep) 76 RETURNING sa.source) 77 DELETE FROM bin_associations ba 78 USING binaries b 79 WHERE ba.suite = :debugsuite_id 80 AND ba.bin = b.id 81 AND b.source NOT IN (SELECT source FROM sources_to_keep) 82 RETURNING 83 b.package, 84 b.version, 85 (SELECT arch_string FROM architecture WHERE id=b.architecture) AS architecture 86 """ 87 result = session.execute(query, {"debugsuite_id": debug_suite.suite_id}) 88 for row in result: 89 Logger.log(["remove", debug_suite.suite_name, row[0], row[1], row[2]])
90 91
92 -def main():
93 global Options, Logger 94 95 cnf = Config() 96 97 for i in ["Help", "No-Action", "All"]: 98 key = "Manage-Debug-Suites::Options::%s" % i 99 if key not in cnf: 100 cnf[key] = "" 101 102 Arguments = [('h', "help", "Manage-Debug-Suites::Options::Help"), 103 ('n', "no-action", "Manage-Debug-Suites::Options::No-Action"), 104 ('a', "all", "Manage-Debug-Suites::Options::All")] 105 106 debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) 107 Options = cnf.subtree("Manage-Debug-Suites::Options") 108 109 if Options["Help"]: 110 usage() 111 112 Logger = daklog.Logger('manage-debug-suites', Options['No-Action']) 113 114 with ArchiveTransaction() as transaction: 115 session = transaction.session 116 if Options['All']: 117 if len(debug_suite_names) != 0: 118 print("E: Cannot use both -a and a queue name") 119 sys.exit(1) 120 raise Exception("Not yet implemented.") 121 else: 122 debug_suites = session.query(Suite).filter(Suite.suite_name.in_(debug_suite_names)) 123 124 for debug_suite in debug_suites: 125 Logger.log(['cleaning debug suite {0}'.format(debug_suite.suite_name)]) 126 clean(debug_suite, transaction) 127 if not Options['No-Action']: 128 transaction.commit() 129 else: 130 transaction.rollback() 131 132 Logger.close()
133 134 ####################################################################################### 135 136 137 if __name__ == '__main__': 138 main() 139