Esempio n. 1
0
def do_pkg(changes_full_path, session):
    changes_dir = os.path.dirname(changes_full_path)
    changes_file = os.path.basename(changes_full_path)

    u = Upload()
    u.pkg.changes_file = changes_file
    (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file)
    u.load_changes(changes_file)
    u.pkg.directory = changes_dir
    u.update_subst()
    u.logger = Logger
    origchanges = os.path.abspath(u.pkg.changes_file)

    # Try to get an included dsc
    dsc = None
    (status, _) = u.load_dsc()
    if status:
        dsc = u.pkg.dsc

    cnf = Config()
    bcc = "X-DAK: dak process-new"
    if cnf.has_key("Dinstall::Bcc"):
        u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
    else:
        u.Subst["__BCC__"] = bcc

    files = u.pkg.files
    u.check_distributions()
    for deb_filename, f in files.items():
        if deb_filename.endswith(".udeb") or deb_filename.endswith(".deb"):
            u.binary_file_checks(deb_filename, session)
            u.check_binary_against_db(deb_filename, session)
        else:
            u.source_file_checks(deb_filename, session)
            u.check_source_against_db(deb_filename, session)

        u.pkg.changes["suite"] = copy.copy(u.pkg.changes["distribution"])

    try:
        with lock_package(u.pkg.changes["source"]):
            with clean_holding(u.pkg):
                if not recheck(u, session):
                    return

                new, byhand = determine_new(u.pkg.changes_file, u.pkg.changes, files, dsc=dsc, session=session)
                if byhand:
                    do_byhand(u, session)
                elif new:
                    do_new(u, session)
                else:
                    try:
                        check_daily_lock()
                        new_accept(u, Options["No-Action"], session)
                    except CantGetLockError:
                        print "Hello? Operator! Give me the number for 911!"
                        print "Dinstall in the locked area, cant process packages, come back later"

    except AlreadyLockedError as e:
        print "Seems to be locked by %s already, skipping..." % (e)
Esempio n. 2
0
def do_pkg(changes_file):
    changes_file = utils.validate_changes_file_arg(changes_file, 0)
    if not changes_file:
        return
    print "\n" + changes_file

    u = Upload()
    u.pkg.changes_file = changes_file
    # We can afoord not to check the signature before loading the changes file
    # as we've validated it already (otherwise it couldn't be in new)
    # and we can more quickly skip over already processed files this way
    u.load_changes(changes_file)

    origchanges = os.path.abspath(u.pkg.changes_file)

    # Still be cautious in case paring the changes file went badly
    if u.pkg.changes.has_key('source') and u.pkg.changes.has_key('version'):
        htmlname = u.pkg.changes["source"] + "_" + u.pkg.changes["version"] + ".html"
        htmlfile = os.path.join(cnf["Show-New::HTMLPath"], htmlname)
    else:
        # Changes file was bad
        print "Changes file %s missing source or version field" % changes_file
        return

    # Have we already processed this?
    if os.path.exists(htmlfile) and \
        os.stat(htmlfile).st_mtime > os.stat(origchanges).st_mtime:
            with open(htmlfile, "r") as fd:
                if fd.read() != timeout_str:
                    sources.append(htmlname)
                    return (PROC_STATUS_SUCCESS,
                            '%s already up-to-date' % htmlfile)

    # Now we'll load the fingerprint
    session = DBConn().session()
    htmlfiles_to_process.append(htmlfile)
    (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file, session=session)
    new_queue = get_policy_queue('new', session );
    u.pkg.directory = new_queue.path
    u.update_subst()
    files = u.pkg.files
    changes = u.pkg.changes
    sources.append(htmlname)

    for deb_filename, f in files.items():
        if deb_filename.endswith(".udeb") or deb_filename.endswith(".deb"):
            u.binary_file_checks(deb_filename, session)
            u.check_binary_against_db(deb_filename, session)
        else:
            u.source_file_checks(deb_filename, session)
            u.check_source_against_db(deb_filename, session)
    u.pkg.changes["suite"] = u.pkg.changes["distribution"]

    new, byhand = determine_new(u.pkg.changes_file, u.pkg.changes, files, 0, dsc=u.pkg.dsc, session=session)

    outfile = open(os.path.join(cnf["Show-New::HTMLPath"],htmlname),"w")

    filestoexamine = []
    for pkg in new.keys():
        for fn in new[pkg]["files"]:
            filestoexamine.append(fn)

    print >> outfile, html_header(changes["source"], filestoexamine)

    check_valid(new, session)
    distribution = changes["distribution"].keys()[0]
    print >> outfile, examine_package.display_changes(distribution, changes_file)

    for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine):
        print >> outfile, examine_package.check_dsc(distribution, fn, session)
    for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine):
        print >> outfile, examine_package.check_deb(distribution, fn, session)

    print >> outfile, html_footer()

    outfile.close()
    session.close()

    htmlfiles_to_process.remove(htmlfile)
    return (PROC_STATUS_SUCCESS, '%s already updated' % htmlfile)
Esempio n. 3
0
sys.path.append('/srv/dak/dak')
from daklib.dbconn import *
from daklib import utils
from daklib.queue import Upload

i = 0
t = 0
pattern = '*.changes'
changes_dir = '/srv/dak/done'

def find_changes(pattern, root):
    for path, dirs, files in os.walk(os.path.abspath(root)):
        for filename in fnmatch.filter(files, pattern):
            yield os.path.join(path, filename)

for changes_file in find_changes(pattern, changes_dir):
    t = t + 1
for changes_file in find_changes(pattern, changes_dir):
    u = Upload()
    u.pkg.changes_file = changes_file
    (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file)
    if u.load_changes(changes_file):
        try:
            u.store_changelog()
        except:
            print 'Unable to handle %s' % changes_file
    else:
        print u.rejects
    i = i + 1
    sys.stdout.write('%d out of %d processed\r' % (i, t))
Esempio n. 4
0
def process_it(changes_file, session):
    global Logger

    Logger.log(["Processing changes file", changes_file])

    cnf = Config()

    holding = Holding()

    # TODO: Actually implement using pending* tables so that we don't lose track
    #       of what is where

    u = Upload()
    u.pkg.changes_file = changes_file
    u.pkg.directory = os.getcwd()
    u.logger = Logger
    origchanges = os.path.abspath(u.pkg.changes_file)

    # Some defaults in case we can't fully process the .changes file
    u.pkg.changes["maintainer2047"] = cnf["Dinstall::MyEmailAddress"]
    u.pkg.changes["changedby2047"] = cnf["Dinstall::MyEmailAddress"]

    # debian-{devel-,}[email protected] toggles writes access based on this header
    bcc = "X-DAK: dak process-upload"
    if cnf.has_key("Dinstall::Bcc"):
        u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
    else:
        u.Subst["__BCC__"] = bcc

    # Remember where we are so we can come back after cd-ing into the
    # holding directory.  TODO: Fix this stupid hack
    u.prevdir = os.getcwd()

    try:
        # If this is the Real Thing(tm), copy things into a private
        # holding directory first to avoid replacable file races.
        if not Options["No-Action"]:
            holding.chdir_to_holding()

            # Absolutize the filename to avoid the requirement of being in the
            # same directory as the .changes file.
            holding.copy_to_holding(origchanges)

            # Relativize the filename so we use the copy in holding
            # rather than the original...
            changespath = os.path.basename(u.pkg.changes_file)
        else:
            changespath = origchanges

        (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changespath)

        if u.pkg.changes["fingerprint"]:
            valid_changes_p = u.load_changes(changespath)
        else:
            for reason in rejects:
                if re_match_expired.match(reason):
                    # Hrm, key expired. Lets see if we can still parse the .changes before
                    # we reject. Then we would be able to mail the maintainer, instead of
                    # just silently dropping the upload.
                    u.load_changes(changespath)
            valid_changes_p = False
            u.rejects.extend(rejects)

        if valid_changes_p:
            u.check_distributions()
            u.check_files(not Options["No-Action"])
            valid_dsc_p = u.check_dsc(not Options["No-Action"])
            if valid_dsc_p and not Options["No-Action"]:
                u.check_source()
            u.check_hashes()
            if valid_dsc_p and not Options["No-Action"] and not len(u.rejects):
                u.check_lintian()
            u.check_urgency()
            u.check_timestamps()
            u.check_signed_by_key()

        action(u, session)

    except (SystemExit, KeyboardInterrupt):
        cleanup()
        raise

    except:
        print "ERROR"
        traceback.print_exc(file=sys.stderr)

    cleanup()
    # Restore previous WD
    os.chdir(u.prevdir)
Esempio n. 5
0
from daklib.queue import Upload

i = 0
t = 0
pattern = '*.changes'
changes_dir = '/srv/ftp.debian.org/queue/done'


def find_changes(pattern, root):
    for path, dirs, files in os.walk(os.path.abspath(root)):
        for filename in fnmatch.filter(files, pattern):
            yield os.path.join(path, filename)


for changes_file in find_changes(pattern, changes_dir):
    t = t + 1
for changes_file in find_changes(pattern, changes_dir):
    u = Upload()
    u.pkg.changes_file = changes_file
    (u.pkg.changes["fingerprint"],
     rejects) = utils.check_signature(changes_file)
    if u.load_changes(changes_file):
        try:
            u.store_changelog()
        except:
            print 'Unable to handle %s' % changes_file
    else:
        print u.rejects
    i = i + 1
    sys.stdout.write('%d out of %d processed\r' % (i, t))