From 1f586de5bee300db6f4b49d2643924b7a7e7776b Mon Sep 17 00:00:00 2001 From: Mike O'Connor Date: Fri, 13 Nov 2009 18:48:24 +0000 Subject: [PATCH] adding a "import_new_files" script which will import into changes_pending_file from the new queue Signed-off-by: Mike O'Connor --- dak/import_new_files.py | 126 ++++++++++++++++++++++++++++++++++++++++ daklib/dbconn.py | 17 +++++- 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 dak/import_new_files.py diff --git a/dak/import_new_files.py b/dak/import_new_files.py new file mode 100644 index 00000000..67fdf33d --- /dev/null +++ b/dak/import_new_files.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Import known_changes files + +@contact: Debian FTP Master +@copyright: 2009 Mike O'Connor +@license: GNU General Public License version 2 or later +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + + +################################################################################ + +import sys +import os +import logging +import threading +import glob +from daklib.dbconn import DBConn, get_dbchange +from daklib.config import Config + +# where in dak.conf all of our configuration will be stowed +options_prefix = "NewFiles" +options_prefix = "%s::Options" % options_prefix + +log = logging.getLogger() + +################################################################################ + + +def usage (exit_code=0): + print """Usage: dak import-new-files [options] + +OPTIONS + -v, --verbose + show verbose information messages + + -q, --quiet + supress all output but errors + +""" + sys.exit(exit_code) + +class ImportKnownChanges(object): + @session_wrapper + def __init__(self, session=None): + try: + newq = get_policy_queue('new', session) + for changes_fn in glob.glob(newq.path + "/*.changes"): + changes_bn = os.path.basename(fn) + chg = session.query(DBChange).filter_by(changesname=changes_bn).one() + + u = Upload() + u.changes_file = changes_fn + u.load_changes(changes_fn) + + for chg_fn in u.pkg.files.keys(): + cpf = ChangePendingFile() + cpf.filename = chg_fn + cpf.size = self.files[chg_fn]['size'] + cpf.md5sum = self.files[chg_fn]['md5sum'] + + session.add(cpf) + chg.files.append(cpf) + + + session.commit() + + except KeyboardInterrupt: + print("Caught C-c; terminating.") + utils.warn("Caught C-c; terminating.") + self.plsDie() + + +def main(): + cnf = Config() + + arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")), + ('q',"quiet", "%s::%s" % (options_prefix,"Quiet")), + ('v',"verbose", "%s::%s" % (options_prefix,"Verbose")), + ] + + args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments,sys.argv) + + num_threads = 1 + + if len(args) > 0: + usage(1) + + if cnf.has_key("%s::%s" % (options_prefix,"Help")): + usage(0) + + level=logging.INFO + if cnf.has_key("%s::%s" % (options_prefix,"Quiet")): + level=logging.ERROR + + elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")): + level=logging.DEBUG + + + logging.basicConfig( level=level, + format='%(asctime)s %(levelname)s %(message)s', + stream = sys.stderr ) + + ImportNewFiles() + + +if __name__ == '__main__': + main() diff --git a/daklib/dbconn.py b/daklib/dbconn.py index e1b24250..2a961834 100644 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2843,6 +2843,16 @@ class DBConn(object): poolfiles = relation(PoolFile, secondary=self.tbl_changes_pool_files, backref="changeslinks"), + filetime = self.tbl_changes.c.filetime, + source = self.tbl_changes.c.source, + binaries = self.tbl_changes.c.binaries, + architecture = self.tbl_changes.c.architecture, + distribution = self.tbl_changes.c.distribution, + urgency = self.tbl_changes.c.urgency, + maintainer = self.tbl_changes.c.maintainer, + changedby = self.tbl_changes.c.changedby, + date = self.tbl_changes.c.date, + version = self.tbl_changes.c.version files = relation(ChangePendingFile, secondary=self.tbl_changes_pending_files_map, backref="changesfile"), @@ -2855,7 +2865,12 @@ class DBConn(object): properties = dict(change_pending_binary_id = self.tbl_changes_pending_binaries.c.id)) mapper(ChangePendingFile, self.tbl_changes_pending_files, - properties = dict(change_pending_file_id = self.tbl_changes_pending_files.c.id)) + properties = dict(change_pending_file_id = self.tbl_changes_pending_files.c.id, + filename = self.tbl_changes_pending_files.c.filename, + size = self.tbl_changes_pending_files.c.size, + md5sum = self.tbl_changes_pending_files.c.md5sum, + sha1sum = self.tbl_changes_pending_files.c.sha1sum, + sha256sum = self.tbl_changes_pending_files.c.sha256sum)) mapper(ChangePendingSource, self.tbl_changes_pending_source, properties = dict(change_pending_source_id = self.tbl_changes_pending_source.c.id, -- 2.39.5