Exemplo n.º 1
0
def loop_params(file_list):
    for i, (error_no, error_comment) in enumerate(ERRORS, start=1):
        info("{2} of {3}: {0} {1}".format(
            error_no, error_comment, i, len(ERRORS)))
        for fullpath in file_list:
            hash_before = sha1_file(fullpath)
            yield (fullpath, hash_before, error_no, error_comment)
Exemplo n.º 2
0
def run_by_reason_only(repo,
                       file_or_directory,
                       recurse=True,
                       dryrun=False,
                       verbose=False,
                       autopep8=None,
                       errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"
                    ] + verbose_opt + recurse_opt

    i = 0
    for error_no, description in errors:
        cmd = autopep8_cmd + [
            "--select={0}".format(error_no), file_or_directory
        ]

        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(file_or_directory, error_no,
                                            description)
                repo.index.add([file_or_directory])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 3
0
def run_by_file_only(repo,
                     file_or_directory,
                     recurse=True,
                     dryrun=False,
                     verbose=False,
                     autopep8=None,
                     errors=None):
    select_opt = (["--select={0}".format(",".join(errors))]
                  if errors != ERRORS else [])
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"
                    ] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 4
0
def run_autopep8(repo,
                 file_or_directory,
                 recurse=True,
                 dryrun=False,
                 verbose=False,
                 autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 5
0
def run_by_file_only(repo,
                     file_or_directory, recurse=True,
                     dryrun=False, verbose=False, autopep8=None,
                     errors=None):
    select_opt = (
        ["--select={0}".format(",".join(errors))]
        if errors != ERRORS
        else []
    )
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + select_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath in file_list:
        cmd = autopep8_cmd + [fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: pep8 all errors".format(fullpath)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 6
0
def run_all(repo,
            file_or_directory, recurse=True,
            dryrun=False, verbose=False, autopep8=None,
            errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    select_opt = (
        ["--select={0}".format(",".join(errors))]
        if errors != ERRORS
        else []
    )
    verbose_opt = ["--verbose"] if verbose else []
    cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + recurse_opt + select_opt + [file_or_directory]

    if verbose or dryrun:
        info(" ".join(cmd))
    if not dryrun:
        output = run_command(cmd)
        if repo.is_dirty():
            info(output)
            msg = "autopep8 run on all {0}".format(file_or_directory)
            repo.index.add([file_or_directory])
            repo.index.commit(msg)
Exemplo n.º 7
0
def run_all(repo,
            file_or_directory,
            recurse=True,
            dryrun=False,
            verbose=False,
            autopep8=None,
            errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    select_opt = (["--select={0}".format(",".join(errors))]
                  if errors != ERRORS else [])
    verbose_opt = ["--verbose"] if verbose else []
    cmd = [autopep8 or "autopep8", "--in-place"
           ] + verbose_opt + recurse_opt + select_opt + [file_or_directory]

    if verbose or dryrun:
        info(" ".join(cmd))
    if not dryrun:
        output = run_command(cmd)
        if repo.is_dirty():
            info(output)
            msg = "autopep8 run on all {0}".format(file_or_directory)
            repo.index.add([file_or_directory])
            repo.index.commit(msg)
Exemplo n.º 8
0
def run_autopylint(file_or_directory, ext=".py", recurse=True,
                   dryrun=False, verbose=False, author=None):
    file_list = get_filelist(file_or_directory, recurse, ext)
    i = 0
    for fullpath, hash_before, error_no, error_comment in loop_params(file_list):
        cmd = ["autopylint", "--in-place", "--verbose",
               "--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if hash_before != sha1_file(fullpath):
                # I can't tell if autopep8 has modified a file from the return code,
                # so I do it the hard way...
                info(output)
                git_commit(
                    fullpath,
                    "{0} {1}".format(error_no, error_comment),
                    dryrun, verbose, author)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 9
0
def run_autopep8(repo,
                 file_or_directory, recurse=True,
                 dryrun=False, verbose=False, autopep8=None,
                 errors=None):
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt

    file_list = get_filelist(file_or_directory, recurse)
    i = 0
    for fullpath, error_no, error_comment in loop_params(file_list, errors):
        cmd = autopep8_cmd + ["--select={0}".format(error_no), fullpath]
        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(fullpath, error_no, error_comment)
                repo.index.add([fullpath])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))
Exemplo n.º 10
0
def run_by_reason_only(repo,
                       file_or_directory, recurse=True,
                       dryrun=False, verbose=False, autopep8=None,
                       errors=None):
    recurse_opt = ["--recursive"] if recurse else []
    verbose_opt = ["--verbose"] if verbose else []
    autopep8_cmd = [autopep8 or "autopep8", "--in-place"] + verbose_opt + recurse_opt

    i = 0
    for error_no, description in errors:
        cmd = autopep8_cmd + ["--select={0}".format(error_no), file_or_directory]

        if verbose or dryrun:
            info(" ".join(cmd))
        if not dryrun:
            output = run_command(cmd)
            if repo.is_dirty():
                info(output)
                msg = "{0}: {1} {2}".format(file_or_directory, error_no, description)
                repo.index.add([file_or_directory])
                repo.index.commit(msg)
                i += 1
    info("# {0} files scanned/modified".format(i))