Example #1
0
def build_uplift_requirements(repo_dir):
    if os.path.exists(requirements_file) and util.ask_yn("Found existing requirements. Should they be used?"):
        bug_info = util.read_json(requirements_file)
    else:
        bug_info = {}
        enabled_branches = c.read_value('repository.enabled_branches')
        all_queries = c.read_value('queries')
        queries = []
        for branch in enabled_branches:
            queries.extend(all_queries[branch])

        bugs = [x for x in find_bugs(queries) if not is_skipable(x)]
        print "Fetching bug data"
        for bug_id in bugs:
            if is_skipable(bug_id):
                continue
            bug = bzapi.fetch_complete_bug(bug_id)
            print "+",
            needed_on = branch_logic.needed_on_branches(bug)
            if len(needed_on) == 0:
                continue
            b = bug_info[bug_id] = {}
            b['needed_on'] = needed_on
            b['already_fixed_on'] = branch_logic.fixed_on_branches(bug)
            b['summary'] = bug['summary']
        print "\nFinished fetching bug data"
        util.write_json(requirements_file, bug_info)
    return bug_info
Example #2
0
def guess_bug_id(repo_dir, commit):
    def _show_bugs():
        print "Possible bugs:"
        for i in range(0, len(possible_bug_ids)):
            print "%d) Bug %s: %s" % (i, possible_bug_ids[i], bug_summaries.get(possible_bug_ids[i], "Closed bug"))

    msg = git.log(repo_dir, commit, number=1, pretty="%B")
    bug_ids = []
    possible_bug_ids = []
    bug_summaries = {}
    for pattern in bug_id_patterns:
        possible_bug_ids.extend([int(x) for x in pattern.findall(msg)])
    possible_bug_ids = list(set(sorted(possible_bug_ids)))
    for bug in possible_bug_ids:
        bug_data = bzapi.fetch_bug(bug, include_fields="summary")
        if bug_data.has_key("summary"):
            bug_summaries[bug] = bug_data["summary"]

    print "Commit %s has a body of:\n%s" % (commit, msg.strip())
    print "-" * 80

    if len(possible_bug_ids) == 1:
        print "I only found one bug:\nBug %s -- %s" % (
            possible_bug_ids[0],
            bug_summaries.get(possible_bug_ids[0], "Closed bug"),
        )
        if util.ask_yn("Use it?"):
            bug_ids = possible_bug_ids
    elif len(possible_bug_ids) > 0:
        _show_bugs()
        index = None
        prompt = "index, 'clear' or 'done' %s: "
        _input = raw_input(prompt % str(bug_ids))
        while _input.strip().lower() != "done":
            if _input.strip().lower() == "clear":
                bug_ids = []
            else:
                try:
                    i = int(_input.strip())
                    if possible_bug_ids[i] in bug_ids:
                        print "Dude, this is already there!"
                    else:
                        bug_ids.append(possible_bug_ids[i])
                except:
                    print "try again!"
                    pass
            _input = raw_input(prompt % str(bug_ids))
    else:
        print "There are no bugs to guess from"
    print "=" * 80
    return bug_ids
Example #3
0
def push(repo_dir):
    branches = c.read_value('repository.enabled_branches')
    preview_push_info = git.push(repo_dir, remote="origin", branches=branches, dry_run=True)
    print "If you push, you'd be pushing: "
    _display_push_info(preview_push_info)
    if not util.ask_yn('Do you wish to push?'):
        return None
    for i in range(5):
        try:
            rv = git.push(repo_dir, remote="origin", branches=branches, dry_run=False)
            util.write_json(push_info_file, rv)
            print "Push attempt %d worked" % int(i+1)
            return rv
        except:
            print "Push attempt %d failed" % int(i+1)
    raise git.PushFailure("remote %s branches %s" % (remote, util.e_join(branches)))
Example #4
0
def merge(repo_dir, gaia_url, branch_to, branch_from):
    git.delete_gaia(repo_dir)
    t = util.time_start()
    if os.path.exists(repo_dir):
        print "Updating Gaia"
        git.update_gaia(repo_dir, gaia_url)
        print "Updated Gaia in %0.2f seconds" % util.time_end(t)
    else:
        print "Creating Gaia"
        git.create_gaia(repo_dir, gaia_url)  # This is sadly broken
        print "Created Gaia in %0.2f seconds" % util.time_end(t)

    print "Merging %s into branch %s" % (branch_from, branch_to)
    if not branch_to in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge into a branch that doesn't exist (%s)" % branch_to
        return None
    if not branch_from in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge from a branch that doesn't exist (%s)" % branch_from
        return None

    git.checkout(repo_dir, branch_to)
    start_commit = git.get_rev(repo_dir)
    git.merge(repo_dir, branch_from, strategy="recursive")
    end_commit = git.get_rev(repo_dir)
    print "Merge range is %s..%s" % (start_commit[:7], end_commit[:7])
    print git.log(repo_dir, "%s..%s" % (start_commit, end_commit), pretty="oneline")
    print "Dry Run push"
    git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=True)
    info = git.push(repo_dir, remote="origin", branches=[branch_to])
    print "Would be pusing to %s" % info["url"]
    for branch in info["branches"].keys():
        s, e = info["branches"][branch]
        print "  %s: %s..%s" % (branch, s, e)
    if util.ask_yn("Push for realises?"):
        info = git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=False)
        print "Pushed to %s" % info["url"]
        for branch in info["branches"].keys():
            s, e = info["branches"][branch]
            print "  %s: %s..%s" % (branch, s, e)
        comment(repo_dir, branch_to, "%s..%s" % (start_commit, end_commit))
Example #5
0
        "--verbose",
    ])


def resume_learning():
    import alphago.training.supervised_policy_trainer as spt
    spt.handle_arguments(cmd_line_args=[
        "resume", slpolicy_weight, "--epochs", "10", "--verbose"
    ])


if __name__ == '__main__':
    flag = [True for _ in range(3)]
    if path.isfile(slpolicy_planes):
        print("slpolicy_planes is exists. Can I execute sgf_to_tensor?")
        flag[0] = ask_yn()

    if path.isfile(slpolicy_model):
        print("slpolicy_model is exists. Can I execute create_model?")
        flag[1] = ask_yn()

    if path.isdir(slpolicy_weight):
        print("slpolicy_weight is exists. Can I execute learn_weights?")
        flag[2] = ask_yn()

    features = [
        "board", "ones", "turns_since", "liberties", "capture_size",
        "self_atari_size", "liberties_after", "ladder_capture",
        "ladder_escape", "sensibleness", "zeros"
    ]
Example #6
0
    ])


def resume_learning(weight_RL):
    run_training(cmd_line_args=[
        slpolicy_model,
        weight_RL,
        rlpolicy_weight,
        # "--save-every", "500",
        # "--game-batch", "20",
        # "--iterations", "10000",
        "--save-every",
        "100",
        "--game-batch",
        "1",
        "--iterations",
        "2",
        "--resume",
        "--verbose",
    ])


if __name__ == '__main__':
    flag = True
    if os.path.isdir(rlpolicy_weight):
        print("rlpolicy_weight is exists. Can I execute learn_weights?")
        flag = ask_yn()

    weight_SL = os.path.join(slpolicy_weight, "weights.00001.hdf5")
    if flag: learn_weights(weight_SL)
Example #7
0
            commits = []
        elif len(commits) > 0 and delete_match:
            try:
                delete_num = int(delete_match.group('delete'))
            except ValueError:
                delete_num = None
                
            if delete_num is None or delete_num < 1 or delete_num > len(commits):
                print "You are trying to delete an invalid commit number" 
            else:
                del commits[delete_num - 1]

        elif user_input == "skip":
            print "Adding a bug to the skipped bug list means that you will never"
            print "see it again.  This is persisted between executions of this program"
            if util.ask_yn("Add bug to skipped bug list?"):
                uplift.skip_bug(bug_id)
            break
        else:
            added = False
            if git.valid_id(user_input):
                add_commit(repo_dir, upstream, commits, user_input)
                added = True
            else:
                for pattern in commit_regex:
                    match = pattern.search(user_input)
                    if match:
                        add_commit(repo_dir, upstream, commits, match.group('id'))
                        added = True
            if not added:
                print "This is not valid input: %s" % user_input