Ejemplo n.º 1
0
def action(directory, upload):
    changes = upload.changes
    processed = True

    global Logger

    cnf = Config()

    okay = upload.check()

    try:
        summary = changes.changes.get('Changes', '')
    except UnicodeDecodeError as e:
        summary = "Reading changes failed: %s" % (e)
        # the upload checks should have detected this, but make sure this
        # upload gets rejected in any case
        upload.reject_reasons.append(summary)

    package_info = []
    if okay:
        if changes.source is not None:
            package_info.append("source:{0}".format(changes.source.dsc['Source']))
        for binary in changes.binaries:
            package_info.append("binary:{0}".format(binary.control['Package']))

    (prompt, answer) = ("", "XXX")
    if Options["No-Action"] or Options["Automatic"]:
        answer = 'S'

    print(summary)
    print()
    print("\n".join(package_info))
    print()
    if len(upload.warnings) > 0:
        print("\n".join(upload.warnings))
        print()

    if len(upload.reject_reasons) > 0:
        print("Reason:")
        print("\n".join(upload.reject_reasons))
        print()

        path = os.path.join(directory, changes.filename)
        created = os.stat(path).st_mtime
        now = time.time()
        too_new = (now - created < int(cnf['Dinstall::SkipTime']))

        if too_new:
            print("SKIP (too new)")
            prompt = "[S]kip, Quit ?"
        else:
            prompt = "[R]eject, Skip, Quit ?"
            if Options["Automatic"]:
                answer = 'R'
    elif upload.new:
        prompt = "[N]ew, Skip, Quit ?"
        if Options['Automatic']:
            answer = 'N'
    else:
        prompt = "[A]ccept, Skip, Quit ?"
        if Options['Automatic']:
            answer = 'A'

    while prompt.find(answer) == -1:
        answer = utils.our_raw_input(prompt)
        m = re_default_answer.match(prompt)
        if answer == "":
            answer = m.group(1)
        answer = answer[:1].upper()

    if answer == 'R':
        reject(directory, upload)
    elif answer == 'A':
        # upload.try_autobyhand must not be run with No-Action.
        if Options['No-Action']:
            accept(directory, upload)
        elif upload.try_autobyhand():
            accept(directory, upload)
        else:
            print("W: redirecting to BYHAND as automatic processing failed.")
            accept_to_new(directory, upload)
    elif answer == 'N':
        accept_to_new(directory, upload)
    elif answer == 'Q':
        sys.exit(0)
    elif answer == 'S':
        processed = False

    if not Options['No-Action']:
        upload.commit()

    return processed
Ejemplo n.º 2
0
def action(directory, upload):
    changes = upload.changes
    processed = True

    global Logger

    cnf = Config()

    okay = upload.check()

    summary = changes.changes.get('Changes', '')

    package_info = []
    if okay:
        if changes.source is not None:
            package_info.append("source:{0}".format(changes.source.dsc['Source']))
        for binary in changes.binaries:
            package_info.append("binary:{0}".format(binary.control['Package']))

    (prompt, answer) = ("", "XXX")
    if Options["No-Action"] or Options["Automatic"]:
        answer = 'S'

    print(summary)
    print()
    print("\n".join(package_info))
    print()
    if len(upload.warnings) > 0:
        print("\n".join(upload.warnings))
        print()

    if len(upload.reject_reasons) > 0:
        print("Reason:")
        print("\n".join(upload.reject_reasons))
        print()

        path = os.path.join(directory, changes.filename)
        created = os.stat(path).st_mtime
        now = time.time()
        too_new = (now - created < int(cnf['Dinstall::SkipTime']))

        if too_new:
            print("SKIP (too new)")
            prompt = "[S]kip, Quit ?"
        else:
            prompt = "[R]eject, Skip, Quit ?"
            if Options["Automatic"]:
                answer = 'R'
    elif upload.new:
        prompt = "[N]ew, Skip, Quit ?"
        if Options['Automatic']:
            answer = 'N'
    else:
        prompt = "[A]ccept, Skip, Quit ?"
        if Options['Automatic']:
            answer = 'A'

    while prompt.find(answer) == -1:
        answer = utils.our_raw_input(prompt)
        m = re_default_answer.match(prompt)
        if answer == "":
            answer = m.group(1)
        answer = answer[:1].upper()

    if answer == 'R':
        reject(directory, upload)
    elif answer == 'A':
        # upload.try_autobyhand must not be run with No-Action.
        if Options['No-Action']:
            accept(directory, upload)
        elif upload.try_autobyhand():
            accept(directory, upload)
        else:
            print("W: redirecting to BYHAND as automatic processing failed.")
            accept_to_new(directory, upload)
    elif answer == 'N':
        accept_to_new(directory, upload)
    elif answer == 'Q':
        sys.exit(0)
    elif answer == 'S':
        processed = False

    if not Options['No-Action']:
        upload.commit()

    return processed