Пример #1
0
def test_multi_char_keys():
  file = tmpfile(["ls a","ls /OD."])
  script = Script(file)

  assert script.current_char() == 'l'
  script.seek_next_col()
  assert script.current_char() == 's'
  script.seek_next_col()
  assert script.current_char() == ' '
  script.seek_next_col()
  assert script.current_char() == 'a'
  script.seek_next_col()
  assert script.current_char() == ''
  script.seek_next_col()

  script.seek_next_line()


  assert script.current_char() == 'l'
  script.seek_next_col()
  assert script.current_char() == 's'
  script.seek_next_col()
  assert script.current_char() == ' '
  script.seek_next_col()
  assert script.current_char() == '/'
  script.seek_next_col()
  assert script.current_char() == ''
  assert script.current_key() == ''

  script.add_multi_char_key('OD')
  assert script.current_char() == ''
  assert script.current_key() == 'OD'
Пример #2
0
def test_script_rendering():
  file = tmpfile(["x%{var1}x","%{HOME}/tmp"])
  script = Script(file)
  script.render({"var1":"val1"})

  assert script.lines[0] == "xval1x"
  assert script.lines[1] == "%{HOME}/tmp"

  script.render(os.environ)

  assert script.lines[0] == "xval1x"
  assert script.lines[1] == f"{os.environ['HOME']}/tmp"
Пример #3
0
    def post(self):
        """
        Return the data for the comparisons.

        :returns: error: With a error, data: with data.
        :rtype: json
        """
        args = get_options(['token', 'file', 'benchmark_id', 'alg_name'])
        checks = ['token', 'benchmark_id']
        alg_name = args['alg_name']
        bench = None
        error = ''

        new_algs = []
        result = {}

        for check in checks:
            if not args[check] and not error:
                error = 'User not authenticated'

        if not error:
            user = validate_by_token(app.config['SECRET_KEY'], args['token'])

            if user is None:
                error = 'User not authenticated'
            else:
                bench = get_benchmark(args['benchmark_id'])

                if bench is None:
                    error = 'Benchmark not known'

        if not error:
            fname = tmpfile(args['file'])
            data_local, error = read_benchmark_data(alg_name, fname, bench)
            new_algs = data_local['alg'].unique().tolist()
            error = write_proposal_data(data_local, user, bench)

            if not error:
                cache.clear()

        result.update({
            'error': error,
            'new_algs': new_algs,
            'new_algs_str': ",".join(new_algs)
        })

        return result
Пример #4
0
    def post(self):
        """
        Return the data for the comparisons.

        :returns: error: With a error, data: with data.
        :rtype: json
        """
        args = get_options([
            'file', 'benchmark_id', 'algs', 'alg_name', 'report', 'dimension',
            'mobile'
        ])
        error = is_error_in_args(args)
        data = {}
        result = {}
        benchmark_id = args['benchmark_id']
        dimension = args['dimension']
        old_algs = set()
        new_algs = set()

        report_module, error = get_report(args['report'], benchmark_id)

        if not error:
            bench = get_benchmark(benchmark_id)

        if args['algs'] and not error:
            data, error = read_data_alg(benchmark_id, args['algs'])
            old_algs = set(data['alg'].tolist())

        if args['file'] and not error:
            fname = tmpfile(args['file'])
            alg_name = args['alg_name']
            data_local, error = read_benchmark_data(alg_name, fname, bench)

            if not error:
                new_algs = set(data_local['alg'].tolist())
                common_alg = new_algs.intersection(old_algs)

                if common_alg:
                    error = 'Algorithms \'{}\' were already in the database'.format(
                        ", ".join(common_alg))

            if not error:
                data = concat_df(data, data_local)

        if not args['file'] and not args['algs']:
            error = 'Error: without reference algorithms the file is mandatory'

        if not error:
            # Sort by categories
            categories = sorted(bench['categories'],
                                key=lambda cat: cat.position)
            milestones = bench['milestones_required']
            dimension = args['dimension']
            tables_idx, tables_titles, tables_df = report_module.create_tables(
                data, categories, milestones, dimension)
            tables = {
                'idx': tables_idx,
                'titles': tables_titles,
                'tables': tables_df
            }
            figures_json = report_module.create_figures(data,
                                                        categories,
                                                        milestones,
                                                        dimension,
                                                        mobile=args['mobile'])
            error = figures_json['error']
            divs = figures_json['divs']
            js = figures_json['js']
            result.update({'tables': tables, 'js': js, 'divs': divs})

        result.update({'error': error})
        return result
Пример #5
0
def simple_script():
  file = tmpfile(["ls","pwd","date"])
  return Script(file)
Пример #6
0
def try_to_merge_hard(driver_repo, driver_branch, kernel_repo, kernel_branch,
                      commit):
    ref = commit['ref']
    fp = git_popen(kernel_repo, "diff %s~1..%s" % (ref, ref))
    rlines, addfiles, rmfiles = analyze_diff(fp)
    fp.close()
    patchfile = tmpfile('alsa-kmirror-patch')
    fp = open(patchfile, 'w+')
    fp.write(''.join(rlines))
    fp.close()
    curdir = getcwd()
    chdir(git_repo(driver_repo))
    lines = git_popen(driver_repo,
                      "apply -v --check %s 2>&1" % patchfile).readlines()
    patch = plines = None
    for line in lines:
        if line.startswith('Checking patch '):
            patch = line[15:-4]
            plines = None
        elif line == 'error: while searching for:\n':
            plines = []
        elif line.startswith('error: '):
            if patch and plines is not None:
                break
            patch = plines = None
        else:
            if plines is not None:
                plines.append(line)
    if not patch and not plines:
        return False
    chdir(git_repo(kernel_repo))
    lines = git_popen(kernel_repo, "annotate %s %s" %
                      (to_kernel_file(patch), ref)).readlines()
    start = end = None
    idx = -1
    missing = plines[:]
    missingrefs = []
    for line in lines:
        idx += 1
        pos = line.find('\t')
        if pos < 0:
            continue
        hash = line[:pos]
        pos = line.find(')')
        if pos < 0:
            continue
        code = line[pos + 1:]
        if code in missing:
            missing.remove(code)
            if start is None:
                start = idx
            end = idx
        elif start is not None:
            missing.append(code)
    if start is None:
        return False
    for idx in range(max(0, start - 1), min(len(lines), end + 2)):
        line = lines[idx]
        pos = line.find('\t')
        if pos < 0:
            continue
        hash = line[:pos]
        if hash == ref[:8]:
            continue
        pos = line.find(')')
        if pos < 0:
            continue
        code = line[pos + 1:]
        for m in missing:
            if code == m:
                if not hash in missingrefs:
                    missingrefs.append(hash)
    chdir(curdir)
    ok = False
    for mref in missingrefs:
        commits = git_read_commits(kernel_repo, mref + "~1", mref)
        if commits and try_to_merge(driver_repo, driver_branch, kernel_repo,
                                    commits[0]):
            ok = True
    return ok
Пример #7
0
def try_to_merge(driver_repo,
                 driver_branch,
                 src_repo,
                 commit,
                 filecheck=is_alsa_file,
                 fileconv=to_alsa_file2,
                 do_checkout=True):
    comment = commit['comment'].splitlines()
    ref = commit['ref']

    print 'Merging %s %s' % (ref[:7], comment[0])

    #fp = git_popen(src_repo, "diff --binary %s~1..%s" % (ref, ref))
    root = ''
    if 'root_flag' in commit and commit['root_flag']:
        root = '--root '
    fp = git_popen(src_repo, "diff-tree -p --binary %s%s" % (root, ref))
    rlines, addfiles, rmfiles = analyze_diff(fp,
                                             filecheck=filecheck,
                                             fileconv=fileconv)
    fp.close()

    patchfile = tmpfile('alsa-merge-patch')
    fp = open(patchfile, 'w+')
    fp.write(''.join(rlines))
    fp.close()

    commentfile = tmpfile('alsa-merge-comment')
    fp = open(commentfile, 'w+')
    fp.write(''.join(commit['comment']))
    fp.close()

    elems = re.compile('(.*?)\s+<(.*)>').match(commit['Author'])
    exports = 'export GIT_AUTHOR_NAME="%s" ; ' % elems.group(1)
    exports += 'export GIT_AUTHOR_EMAIL="%s" ; ' % elems.group(2)
    exports += 'export GIT_AUTHOR_DATE="%s" ; ' % commit['AuthorDate']
    elems = re.compile('(.*?)\s+<(.*)>').match(commit['Commit'])
    exports += 'export GIT_COMMITER_NAME="%s" ; ' % elems.group(1)
    exports += 'export GIT_COMMITER_EMAIL="%s" ; ' % elems.group(2)
    exports += 'export GIT_COMMITER_DATE="%s" ; ' % commit['CommitDate']
    exports += 'export GIT_COMMITTER_NAME="%s" ; ' % elems.group(1)
    exports += 'export GIT_COMMITTER_EMAIL="%s" ; ' % elems.group(2)
    exports += 'export GIT_COMMITTER_DATE="%s"' % commit['CommitDate']

    curdir = getcwd()
    if do_checkout and git_system(driver_repo,
                                  "checkout -q %s" % driver_branch):
        raise ValueError, 'git checkout'

    chdir(git_repo(driver_repo))
    lines = popen("LANG=C patch -f -p 1 --dry-run --reject-file=%s < %s" %
                  (tmpfile("rejects"), patchfile)).readlines()
    print ''.join(lines)
    failed = fuzz = succeed = 0
    for line in lines:
        if line.find('FAILED') >= 0:
            failed += 1
        if line.find('succeed') >= 0:
            if line.find('fuzz') >= 0:
                fuzz += 1
            else:
                succeed += 1
    if failed:
        print 'Merge skipped %s %s (%s failed)' % (ref[:7], comment[0], failed)
        chdir(curdir)
        if do_checkout and \
           ref[:7] in ['bdb527e', 'fc5b15f', '82b1d73', \
                       '02a237b', 'ef8d60f', 'c0fa6c8', \
                       '1605282', '3946860', 'd70f363', \
                       '6539799', '152a3a7', '79980d9']:
            print '  It is probably OK...'
            return False
        raise ValueError
        return False
    if git_system(
            driver_repo,
            "apply --check --binary --allow-binary-replacement %s" %
            patchfile):
        print 'Merge skipped %s %s (apply check)' % (ref[:7], comment[0])
        chdir(curdir)
        if not do_checkout:
            raise ValueError
        return False
    if git_system(driver_repo,
                  "apply --binary --allow-binary-replacement %s" % patchfile):
        chdir(curdir)
        raise ValueError, 'git apply'
    if addfiles and git_system(driver_repo, "add %s" % ' '.join(addfiles)):
        chdir(curdir)
        raise ValueError, 'git add'
    if rmfiles and git_system(driver_repo, "rm %s" % ' '.join(rmfiles)):
        chdir(curdir)
        raise ValueError, 'git rm'
    if git_system(driver_repo, "commit -F %s" % commentfile, exports=exports):
        chdir(curdir)
        raise ValueError, 'git commit'
    chdir(curdir)

    print 'Merge complete %s %s (%s fuzz)' % (ref[:7], comment[0], fuzz)
    return True
Пример #8
0
def simple_script():
    file = tmpfile(["echo hi"])
    return file