5 Import known_changes files
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009 Mike O'Connor <stew@debian.org>
9 @license: GNU General Public License version 2 or later
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ################################################################################
29 ################################################################################
37 from daklib.dbconn import DBConn, get_dbchange, get_policy_queue, session_wrapper, ChangePendingFile, get_location, check_poolfile
38 from daklib.config import Config
39 from daklib.queue import Upload
40 from daklib.utils import poolify
42 # where in dak.conf all of our configuration will be stowed
43 options_prefix = "NewFiles"
44 options_prefix = "%s::Options" % options_prefix
46 log = logging.getLogger()
48 ################################################################################
51 def usage (exit_code=0):
52 print """Usage: dak import-new-files [options]
56 show verbose information messages
59 supress all output but errors
64 class ImportNewFiles(object):
66 def __init__(self, session=None):
69 newq = get_policy_queue('new', session)
70 for changes_fn in glob.glob(newq.path + "/*.changes"):
71 changes_bn = os.path.basename(changes_fn)
72 chg = get_dbchange(changes_bn, session)
75 success = u.load_changes(changes_fn)
76 u.pkg.changes_file = changes_bn
80 chg = u.pkg.add_known_changes(newq.path, newq.policy_queue_id, session)
84 log.critical("failed to load %s" % changes_fn)
87 log.critical("ACCLAIM: %s" % changes_fn)
90 for chg_fn in u.pkg.files.keys():
92 f = open(os.path.join(newq.path, chg_fn))
93 cpf = ChangePendingFile()
95 cpf.size = u.pkg.files[chg_fn]['size']
96 cpf.md5sum = u.pkg.files[chg_fn]['md5sum']
98 if u.pkg.files[chg_fn].has_key('sha1sum'):
99 cpf.sha1sum = u.pkg.files[chg_fn]['sha1sum']
101 log.warning("Having to generate sha1sum for %s" % chg_fn)
103 cpf.sha1sum = apt_pkg.sha1sum(f)
105 if u.pkg.files[chg_fn].has_key('sha256sum'):
106 cpf.sha256sum = u.pkg.files[chg_fn]['sha256sum']
108 log.warning("Having to generate sha256sum for %s" % chg_fn)
110 cpf.sha256sum = apt_pkg.sha256sum(f)
116 # Can't find the file, try to look it up in the pool
117 poolname = poolify(u.pkg.changes["source"], u.pkg.files[chg_fn]["component"])
118 l = get_location(cnf["Dir::Pool"], u.pkg.files[chg_fn]["component"], session=session)
120 log.critical("ERROR: Can't find location for %s (component %s)" % (chg_fn, u.pkg.files[chg_fn]["component"]))
122 found, poolfile = check_poolfile(os.path.join(poolname, chg_fn),
123 u.pkg.files[chg_fn]['size'],
124 u.pkg.files[chg_fn]["md5sum"],
129 log.critical("ERROR: Found multiple files for %s in pool" % chg_fn)
131 elif found is False and poolfile is not None:
132 log.critical("ERROR: md5sum / size mismatch for %s in pool" % chg_fn)
136 log.critical("ERROR: Could not find %s in pool" % chg_fn)
139 chg.poolfiles.append(poolfile)
147 except KeyboardInterrupt:
148 print("Caught C-c; terminating.")
149 utils.warn("Caught C-c; terminating.")
156 arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")),
157 ('q',"quiet", "%s::%s" % (options_prefix,"Quiet")),
158 ('v',"verbose", "%s::%s" % (options_prefix,"Verbose")),
161 args = apt_pkg.parse_commandline(cnf.Cnf, arguments,sys.argv)
168 if cnf.has_key("%s::%s" % (options_prefix,"Help")):
172 if cnf.has_key("%s::%s" % (options_prefix,"Quiet")):
175 elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")):
179 logging.basicConfig( level=level,
180 format='%(asctime)s %(levelname)s %(message)s',
181 stream = sys.stderr )
186 if __name__ == '__main__':