示例#1
0
    def run(self, args):
        sandbox = SandBox(root_dir=args.sandbox)

        sandbox.create_dirs()

        if args.spec_git_url:
            g = GitRepository(sandbox.specs_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()
示例#2
0
文件: action.py 项目: AdaCore/e3-core
    def run(self, args):
        sandbox = SandBox()
        sandbox.root_dir = args.sandbox

        sandbox.create_dirs()

        if args.spec_git_url:
            mkdir(sandbox.spec_dir)
            g = GitRepository(sandbox.spec_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()
示例#3
0
文件: run.py 项目: piratos/e3-core
 def do_checkout(self):
     """Get sources from vcs to sandbox vcs_dir."""
     repo_name = self.data.repo_name
     repo_url = self.data.repo_data['url']
     repo_revision = self.data.repo_data['revision']
     repo_vcs = self.data.repo_data['vcs']
     if repo_vcs != 'git':
         logger.error('%s vcs type not supported', repo_vcs)
         self.status = STATUS.failure
         return
     repo_dir = os.path.join(self.sandbox.vcs_dir, repo_name)
     g = GitRepository(repo_dir)
     if e3.log.default_output_stream is not None:
         g.log_stream = e3.log.default_output_stream
     g.init()
     g.update(repo_url, repo_revision, force=True)
     self.status = STATUS.success
示例#4
0
 def do_checkout(self) -> None:
     """Get sources from vcs to sandbox vcs_dir."""
     repo_name = self.data.repo_name
     repo_url = self.data.repo_data["url"]
     repo_revision = self.data.repo_data["revision"]
     repo_vcs = self.data.repo_data["vcs"]
     if repo_vcs != "git":
         logger.error("%s vcs type not supported", repo_vcs)
         self.__status = STATUS.failure
         return
     assert self.sandbox.vcs_dir is not None
     repo_dir = os.path.join(self.sandbox.vcs_dir, repo_name)
     g = GitRepository(repo_dir)
     if e3.log.default_output_stream is not None:
         g.log_stream = e3.log.default_output_stream
     g.init()
     g.update(repo_url, repo_revision, force=True)
     self.__status = STATUS.success
示例#5
0
    def run(self, args):
        sandbox = SandBox()
        sandbox.root_dir = args.sandbox

        if args.specs_dir:
            sandbox.specs_dir = args.specs_dir

        if args.create_sandbox:
            sandbox.create_dirs()

        if args.create_sandbox and args.spec_git_url:
            mkdir(sandbox.specs_dir)
            g = GitRepository(sandbox.specs_dir)
            if e3.log.default_output_stream is not None:
                g.log_stream = e3.log.default_output_stream
            g.init()
            g.update(args.spec_git_url, args.spec_git_branch, force=True)

        sandbox.dump_configuration()
        sandbox.write_scripts()

        asr = AnodSpecRepository(sandbox.specs_dir)
        check_api_version(asr.api_version)

        # Load plan content if needed
        if args.plan:
            if not os.path.isfile(args.plan):
                raise SandBoxError("plan file %s does not exist" % args.plan,
                                   origin="SandBoxExec.run")
            with open(args.plan, "r") as plan_fd:
                plan_content = ["def main_entry_point():"]
                plan_content += [
                    "    %s" % line for line in plan_fd.read().splitlines()
                ]
                plan_content = "\n".join(plan_content)

            env = BaseEnv()
            cm = PlanContext(server=env)
            store = None
            resolver = getattr(
                AnodContext,
                str(args.resolver),
                AnodContext.always_create_source_resolver,
            )
            logger.debug("Using resolver %s", resolver.__name__)

            # Declare available actions and their signature
            def anod_action(module,
                            build=None,
                            host=None,
                            target=None,
                            qualifier=None):
                pass  # all: no cover

            for a in ("anod_install", "anod_build", "anod_test"):
                cm.register_action(a, anod_action)

            # Load the plan and execute
            plan = Plan(data={})
            plan.load_chunk(plan_content)
            actions = cm.execute(plan, "main_entry_point")

            ac = AnodContext(asr, default_env=env)
            for action in actions:
                ac.add_anod_action(
                    action.module,
                    action,
                    action.action.replace("anod_", "", 1),
                    action.qualifier,
                )

            # Check if machine plan is locally schedulable
            action_list = ac.schedule(resolver)
            e = ElectrolytJobFactory(sandbox, asr, store, dry_run=args.dry_run)
            e.run(action_list)
示例#6
0
def test_git_repo():
    working_tree = unixpath(os.path.join(os.getcwd(), 'working_tree'))
    working_tree2 = os.path.join(os.getcwd(), 'working_tree2')
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = unixpath(os.path.join(working_tree, 'new.txt'))
    echo_to_file(new_file, 'new\n')
    repo.git_cmd(['add', 'new.txt'])
    repo.git_cmd(['config', 'user.email', '*****@*****.**'])
    repo.git_cmd(['config', 'user.name', 'e3 core'])
    repo.git_cmd(['commit', '-m', 'new file'])
    repo.git_cmd(['tag', '-a', '-m', 'new tag', '20.0855369232'])

    with open('log.txt', 'w') as f:
        repo.write_log(f)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert 'new file' in commits[0]['message']
        assert commits[0]['email'] == '*****@*****.**'
        new_sha = commits[0]['sha']

    assert '20.0855369232' in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe('g')
    assert 'describe --always g' in str(err)

    echo_to_file(new_file, 'new line\n', append=True)

    with open('commit1.diff', 'wb') as f:
        repo.write_local_diff(f)

    with open('commit1.diff', 'rb') as f:
        assert b'+new line' in f.read()

    echo_to_file(new_file, 10000 * '*')

    repo.git_cmd(['commit', '-a', '-m', 'file update'])
    with open('log2.txt', 'w') as f:
        repo.write_log(f)
    with open('log2.txt', 'r') as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert 'file update' in commits[0]['message']
        assert 'diff too long' in commits[0]['diff']
        assert 'new file' in commits[1]['message']
        assert commits[1]['sha'] != commits[0]['sha']
        assert commits[1]['diff'] != commits[0]['diff']

    repo2 = GitRepository(working_tree2)
    repo2.init(url=working_tree, remote='tree1')
    try:
        repo2.update(url=working_tree, refspec='master')
    except GitError:
        if sys.platform == 'win32':
            # some git versions on windows do not support that well
            # ignore this test for now???
            pass
    else:
        repo2.rev_parse() == repo.rev_parse()
示例#7
0
def test_git_repo():
    working_tree = os.path.join(os.getcwd(), "working_tree")
    working_tree2 = os.path.join(os.getcwd(), "working_tree2")
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = os.path.join(working_tree, "new.txt")
    echo_to_file(new_file, "new\n")

    commit_note = unixpath(os.path.join(working_tree, "commit_note.txt"))
    echo_to_file(
        commit_note,
        "\n".join((
            "Code-Review+2: Nobody <*****@*****.**>",
            "Submitted-by: Nobody <*****@*****.**>",
            "Submitted-at: Thu, 08 Jun 2017 18:40:11 +0200",
        )),
    )

    repo.git_cmd(["add", "new.txt"])
    repo.git_cmd(["config", "user.email", "*****@*****.**"])
    repo.git_cmd(["config", "user.name", "e3 core"])
    repo.git_cmd(["commit", "-m", "new file"])
    repo.git_cmd(["tag", "-a", "-m", "new tag", "20.0855369232"])
    repo.git_cmd(
        ["notes", "--ref", "review", "add", "HEAD", "-F", commit_note])

    # try with gerrit notes
    with open("log.txt", "w") as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert "*****@*****.**" in commits[0]["notes"]["Code-Review+2"]

    # try with an invalid note
    repo.git_cmd([
        "notes", "--ref", "review", "add", "HEAD", "-f", "-m", "invalid-note"
    ])
    with open("log.txt", "w") as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert commits[0]["notes"] is None

    # try again without gerrit notes
    with open("log.txt", "w") as f:
        repo.write_log(f)
    with open("log.txt") as f:
        commits = list(repo.parse_log(f))
        assert "new file" in commits[0]["message"]
        assert commits[0]["email"] == "*****@*****.**"
        new_sha = commits[0]["sha"]

    assert "20.0855369232" in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe("g")
    assert "describe --always g" in str(err)

    echo_to_file(new_file, "new line\n", append=True)

    with open("commit1.diff", "wb") as f:
        repo.write_local_diff(f)

    with open("commit1.diff", "rb") as f:
        assert b"+new line" in f.read()

    echo_to_file(new_file, 10000 * "*")

    repo.git_cmd(["commit", "-a", "-m", "file update"])
    with open("log2.txt", "w") as f:
        repo.write_log(f)
    with open("log2.txt") as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert "file update" in commits[0]["message"]
        assert "diff too long" in commits[0]["diff"]
        assert "new file" in commits[1]["message"]
        assert commits[1]["sha"] != commits[0]["sha"]
        assert commits[1]["diff"] != commits[0]["diff"]

    repo2 = GitRepository(working_tree2)
    giturl = "file://%s" % working_tree.replace("\\", "/")
    repo2.init(url=giturl, remote="tree1")
    repo2.update(url=giturl, refspec="master")
    repo2.rev_parse() == repo.rev_parse()

    repo2.fetch_gerrit_notes(url=giturl)
    p = repo2.git_cmd(["notes", "--ref=review", "show", new_sha],
                      output=subprocess.PIPE)
    assert "invalid-note" in p.out
示例#8
0
def test_git_repo():
    working_tree = os.path.join(os.getcwd(), 'working_tree')
    working_tree2 = os.path.join(os.getcwd(), 'working_tree2')
    repo = GitRepository(working_tree)
    repo.init()
    os.chdir(working_tree)
    new_file = os.path.join(working_tree, 'new.txt')
    echo_to_file(new_file, 'new\n')

    commit_note = unixpath(os.path.join(working_tree, 'commit_note.txt'))
    echo_to_file(
        commit_note, '\n'.join(
            ('Code-Review+2: Nobody <*****@*****.**>',
             'Submitted-by: Nobody <*****@*****.**>',
             'Submitted-at: Thu, 08 Jun 2017 18:40:11 +0200')))

    repo.git_cmd(['add', 'new.txt'])
    repo.git_cmd(['config', 'user.email', '*****@*****.**'])
    repo.git_cmd(['config', 'user.name', 'e3 core'])
    repo.git_cmd(['commit', '-m', 'new file'])
    repo.git_cmd(['tag', '-a', '-m', 'new tag', '20.0855369232'])
    repo.git_cmd(
        ['notes', '--ref', 'review', 'add', 'HEAD', '-F', commit_note])

    # try with gerrit notes
    with open('log.txt', 'w') as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert '*****@*****.**' in commits[0]['notes']['Code-Review+2']

    # try with an invalid note
    repo.git_cmd([
        'notes', '--ref', 'review', 'add', 'HEAD', '-f', '-m', 'invalid-note'
    ])
    with open('log.txt', 'w') as f:
        repo.write_log(f, with_gerrit_notes=True)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert commits[0]['notes'] is None

    # try again without gerrit notes
    with open('log.txt', 'w') as f:
        repo.write_log(f)
    with open('log.txt', 'r') as f:
        commits = list(repo.parse_log(f))
        assert 'new file' in commits[0]['message']
        assert commits[0]['email'] == '*****@*****.**'
        new_sha = commits[0]['sha']

    assert '20.0855369232' in repo.describe()
    assert new_sha == repo.rev_parse()

    with pytest.raises(GitError) as err:
        repo.describe('g')
    assert 'describe --always g' in str(err)

    echo_to_file(new_file, 'new line\n', append=True)

    with open('commit1.diff', 'wb') as f:
        repo.write_local_diff(f)

    with open('commit1.diff', 'rb') as f:
        assert b'+new line' in f.read()

    echo_to_file(new_file, 10000 * '*')

    repo.git_cmd(['commit', '-a', '-m', 'file update'])
    with open('log2.txt', 'w') as f:
        repo.write_log(f)
    with open('log2.txt', 'r') as f:
        commits = list(repo.parse_log(f, max_diff_size=1000))
        # assert b'diff too long' not in commits[1]['diff']
        assert 'file update' in commits[0]['message']
        assert 'diff too long' in commits[0]['diff']
        assert 'new file' in commits[1]['message']
        assert commits[1]['sha'] != commits[0]['sha']
        assert commits[1]['diff'] != commits[0]['diff']

    repo2 = GitRepository(working_tree2)
    giturl = 'file://%s' % working_tree.replace('\\', '/')
    repo2.init(url=giturl, remote='tree1')
    repo2.update(url=giturl, refspec='master')
    repo2.rev_parse() == repo.rev_parse()

    repo2.fetch_gerrit_notes(url=giturl)
    p = repo2.git_cmd(['notes', '--ref=review', 'show', new_sha],
                      output=subprocess.PIPE)
    assert 'invalid-note' in p.out