[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#622117: [PATCH 2/2] Fill field "builder" in pkg_history



Hi,

all logs processed, besides a few (52) where the log file was not found.

I am attaching the script I used for future reference.

Greetings,
Joachim

-- 
Joachim "nomeata" Breitner
Debian Developer
  nomeata@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nomeata@joachim-breitner.de | http://people.debian.org/~nomeata
#!/usr/bin/env python2.5
# vim:set encoding=utf-8 et ts=4 sw=4 ai:

# set-builder â?? set builder column of logs logs in the wanna-peruse database

# © 2009 Philipp Kern <pkern@debian.org>
# © 2011 Joachim Breitner <nomeata@debian.org>

# 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, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.

"""
@contact: Debian Wanna-Build Admins <wb-team@buildd.debian.org>
@copyright: 2009 Philipp Kern <pkern@debian.org>,
            2011 Joachim Breitner <nomeata@debian.org>
@license: GNU General Public License version 2 or later
"""

import os.path
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib'))
sys.path.insert(0, "lib")

from ConfigParser import ConfigParser
from debian.wannabuild.logs import BuildLogFactory
from optparse import OptionParser
import email.message
import logging
import logging.config
import mailbox
import os
import string
import time
import re

from sqlalchemy import create_engine, MetaData, Table, String, DateTime, \
                       Integer, Column, select, and_, func, desc, asc, types

DEFAULT_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '..',
                                   'etc', 'buildlogs.conf')
EX_TEMPFAIL = 75

def main():
    # Parse commandline.
    parser = OptionParser()
    parser.add_option('-d', '--dry-run', dest="dryrun", action="store_true",
                      help="Don't actually process: just display what would "\
                      "happen")
    parser.add_option('-c', '--config', dest="config_file", metavar="FILE",
                      default=DEFAULT_CONFIG_FILE,
                      help="Configuration file to use")
    (options, args) = parser.parse_args()

    if not os.path.exists(options.config_file):
        options.config_file = "buildlogs.conf"

    # Set up logging as specified in the configuration file.
    logging.config.fileConfig(options.config_file)
    if not options.dryrun:
        logger = logging.getLogger("inject")
    else:
        logger = logging.getLogger("inject_dryrun")

    # Read the configuration file.
    config = ConfigParser()
    config.read(options.config_file)

    # Set up the infrastructure.
    buildlog_factory = BuildLogFactory(
        logger=logger,
        config=config,
        options=options
        )

    file_factory, file_extension = buildlog_factory.compress

    for arch in buildlog_factory.dbfactory.architectures:
        tbl = buildlog_factory.dbfactory.get_pkg_history(arch)
        qry = tbl.select(tbl.c.builder == None)
        for x in buildlog_factory.dbfactory.conn.execute(qry).fetchall():
            filename = os.path.join(
                buildlog_factory.dbdir,
                x['package'][0],
                x['package'],
                x['version'],
                "%s_%d_log%s" % (arch,
                        time.mktime(x['timestamp'].timetuple()),
                        file_extension))
            if not os.path.exists(filename):
                print "Expected file not found: %s" % filename
                continue
            file = file_factory(filename)
            first_line = file.readline()
	    host = None	
            m = re.match('^From .*@([^ ]*)', first_line)
            if m:
                host = m.group(1)
	    m = re.match('^Return-[Pp]ath: <buildd@(.*)>', first_line)
	    if m and not host:
                host = m.group(1)
	    if host:
                print "Log: %s Host: %s" % (filename,host)
                upd = tbl.update(
                    (tbl.c.package      == x['package']) &
                    (tbl.c.distribution == x['distribution']) &
                    (tbl.c.version      == x['version']) &
                    (tbl.c.timestamp    == x['timestamp']),
                    { 'builder': host})
                buildlog_factory.dbfactory.conn.execute(upd)
            else:
                print "Not understood: %s in %s" % (first_line, filename)


if __name__ == '__main__':
    try:
        main()
    except:
        # This will trigger a mail only if the logging has already been set up.
        logging.critical("exception caught outside main",
                         exc_info=sys.exc_info())
        # Defer delivery, although this means that Exim will retry by itself,
        # the log also will not get lost.
        sys.exit(EX_TEMPFAIL)
    finally:
        logging.shutdown()

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: