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

Source Code for Module dak.contents

  1  #! /usr/bin/env python3 
  2  """ 
  3  Create all the contents files 
  4   
  5  @contact: Debian FTPMaster <ftpmaster@debian.org> 
  6  @copyright: 2008, 2009 Michael Casadevall <mcasadevall@debian.org> 
  7  @copyright: 2009 Mike O'Connor <stew@debian.org> 
  8  @copyright: 2011 Torsten Werner <twerner@debian.org> 
  9  @license: GNU General Public License version 2 or later 
 10  """ 
 11   
 12  ################################################################################ 
 13   
 14  # This program is free software; you can redistribute it and/or modify 
 15  # it under the terms of the GNU General Public License as published by 
 16  # the Free Software Foundation; either version 2 of the License, or 
 17  # (at your option) any later version. 
 18   
 19  # This program is distributed in the hope that it will be useful, 
 20  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 21  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 22  # GNU General Public License for more details. 
 23   
 24  # You should have received a copy of the GNU General Public License 
 25  # along with this program; if not, write to the Free Software 
 26  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 27   
 28  ################################################################################ 
 29   
 30  # <Ganneff> there is the idea to slowly replace contents files 
 31  # <Ganneff> with a new generation of such files. 
 32  # <Ganneff> having more info. 
 33   
 34  # <Ganneff> of course that wont help for now where we need to generate them :) 
 35   
 36  ################################################################################ 
 37   
 38  import sys 
 39  import apt_pkg 
 40   
 41  from daklib.config import Config 
 42  from daklib.dbconn import * 
 43  from daklib.contents import BinaryContentsScanner, ContentsWriter, \ 
 44      SourceContentsScanner 
 45  from daklib import daklog 
 46  from daklib import utils 
 47   
 48  ################################################################################ 
 49   
 50   
51 -def usage(exit_code=0):
52 print("""Usage: dak contents [options] subcommand 53 54 SUBCOMMANDS 55 generate 56 generate Contents-$arch.gz files 57 58 scan-source 59 scan the source packages in the existing pool and load contents into 60 the src_contents table 61 62 scan-binary 63 scan the (u)debs in the existing pool and load contents into the 64 bin_contents table 65 66 OPTIONS 67 -h, --help 68 show this help and exit 69 70 OPTIONS for generate 71 -a, --archive=ARCHIVE 72 only operate on suites in the specified archive 73 74 -s, --suite={stable,testing,unstable,...} 75 only operate on specified suite names 76 77 -c, --component={main,contrib,non-free} 78 only operate on specified components 79 80 -f, --force 81 write Contents files for suites marked as untouchable, too 82 83 OPTIONS for scan-source and scan-binary 84 -l, --limit=NUMBER 85 maximum number of packages to scan 86 """) 87 sys.exit(exit_code)
88 89 ################################################################################ 90 91
92 -def write_all(cnf, archive_names=[], suite_names=[], component_names=[], force=None):
93 Logger = daklog.Logger('contents generate') 94 ContentsWriter.write_all(Logger, archive_names, suite_names, component_names, force) 95 Logger.close()
96 97 ################################################################################ 98 99
100 -def binary_scan_all(cnf, limit):
101 Logger = daklog.Logger('contents scan-binary') 102 result = BinaryContentsScanner.scan_all(limit) 103 processed = '%(processed)d packages processed' % result 104 remaining = '%(remaining)d packages remaining' % result 105 Logger.log([processed, remaining]) 106 Logger.close()
107 108 ################################################################################ 109 110
111 -def source_scan_all(cnf, limit):
112 Logger = daklog.Logger('contents scan-source') 113 result = SourceContentsScanner.scan_all(limit) 114 processed = '%(processed)d packages processed' % result 115 remaining = '%(remaining)d packages remaining' % result 116 Logger.log([processed, remaining]) 117 Logger.close()
118 119 ################################################################################ 120 121
122 -def main():
123 cnf = Config() 124 cnf['Contents::Options::Help'] = '' 125 cnf['Contents::Options::Suite'] = '' 126 cnf['Contents::Options::Component'] = '' 127 cnf['Contents::Options::Limit'] = '' 128 cnf['Contents::Options::Force'] = '' 129 arguments = [('h', "help", 'Contents::Options::Help'), 130 ('a', 'archive', 'Contents::Options::Archive', 'HasArg'), 131 ('s', "suite", 'Contents::Options::Suite', "HasArg"), 132 ('c', "component", 'Contents::Options::Component', "HasArg"), 133 ('l', "limit", 'Contents::Options::Limit', "HasArg"), 134 ('f', "force", 'Contents::Options::Force'), 135 ] 136 args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) 137 options = cnf.subtree('Contents::Options') 138 139 if (len(args) != 1) or options['Help']: 140 usage() 141 142 limit = None 143 if len(options['Limit']) > 0: 144 limit = int(options['Limit']) 145 146 if args[0] == 'scan-source': 147 source_scan_all(cnf, limit) 148 return 149 150 if args[0] == 'scan-binary': 151 binary_scan_all(cnf, limit) 152 return 153 154 archive_names = utils.split_args(options['Archive']) 155 suite_names = utils.split_args(options['Suite']) 156 component_names = utils.split_args(options['Component']) 157 158 force = bool(options['Force']) 159 160 if args[0] == 'generate': 161 write_all(cnf, archive_names, suite_names, component_names, force) 162 return 163 164 usage()
165 166 167 if __name__ == '__main__': 168 main() 169