コード例 #1
0
ファイル: git_visitor_status.py プロジェクト: mvendra/mvtools
import os
import git_visitor_base
from subprocess import check_output
from subprocess import CalledProcessError


def visitor_status(repos, options):

    for r in repos:
        try:
            out = check_output(["git", "-C", r, "status", "-s"])
        except CalledProcessError as cpe:
            print("Git status returned error.")
            return False
        except OSError as oe:
            print("Failed calling git. Make sure it is installed.")
            return False
        if len(out) == 0:
            pass  # clean HEAD
        else:
            print("%s is dirty." % r)

    return True


if __name__ == "__main__":
    r = git_visitor_base.do_visit(None, None, visitor_status)
    if False in r:
        sys.exit(1)
コード例 #2
0
import path_utils
import dirsize

# source: http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
def sizeof_fmt(num, suffix='b'):
    for unit in ['','K','M','G','T','P','E','Z']:
        if abs(num) < 1024.0:
            return "%3.1f %s%s" % (num, unit, suffix)
        num /= 1024.0
    return "%.1f%s%s" % (num, 'Y', suffix)

def visitor_reposize(repos, options):

    # this tool will ignore submodules, since dirsize will consider subfolders
    repos_filtered = path_utils.filter_path_list_no_same_branch(repos)

    total = 0
    for rp in repos_filtered:
        rs = dirsize.get_dir_size(rp, False)
        total += rs
        print("%s: %s" % (rp, sizeof_fmt(int(rs), '')))

    print("Total size of all repos: %s" % sizeof_fmt(total, ''))
    return True

if __name__ == "__main__":
    r = git_visitor_base.do_visit(None, None, visitor_reposize)
    if False in r:
        sys.exit(1)

コード例 #3
0
ファイル: git_visitor_pull.py プロジェクト: mvendra/mvtools
    report = []
    all_passed = True
    for rp in repos:

        try:
            remotes, branches = git_visitor_base.apply_filters(rp, options)
        except git_visitor_base.gvbexcept as gvbex:
            all_passed = False
            report.append("%s%s: %s.%s" % (terminal_colors.TTY_RED, rp, gvbex.message, ORIGINAL_COLOR)) 
            continue

        op_piece, report_piece = git_pull.do_pull(rp, remotes, branches)
        all_passed = all_passed and (not op_piece)
        for ri in report_piece:
            report.append(ri)

    git_visitor_base.print_report(all_passed, report)
    return all_passed

if __name__ == "__main__":

    filters = None
    if len(sys.argv) > 1:
        filters = sys.argv[1:]

    r = git_visitor_base.do_visit(None, filters, visitor_pull)
    if False in r:
        sys.exit(1)

コード例 #4
0
    # accordingly - by returning True to indicate a "go ahead and change"
    # plus the new remote url/path
    return False, remote_path

def visitor_remote_refactor(repos, options):

    report = []
    all_passed = True

    for rp in repos:
        remotes = git_repo_query.get_remotes(rp)
        if remotes is None:
            continue
        for rmn in remotes:
            for rmop in remotes[rmn]:

                diff, new_url = change_path(rp, rmn, rmop, remotes[rmn][rmop])
                if diff:
                    op_piece, report_piece = git_remote.remote_change_url(rp, rmn, rmop, new_url)
                    all_passed = all_passed and (not op_piece)
                    report.append(report_piece)

    git_visitor_base.print_report(all_passed, report)
    return all_passed

if __name__ == "__main__":
    r = git_visitor_base.do_visit(None, None, visitor_remote_refactor)
    if False in r:
        sys.exit(1)

コード例 #5
0
ファイル: git_visitor_fetch.py プロジェクト: mvendra/mvtools
def visitor_fetch(repos, options):

    ORIGINAL_COLOR = terminal_colors.get_standard_color()

    report = []
    all_passed = True
    for rp in repos:
        remotes = git_repo_query.get_remotes(rp)
        remotes = git_visitor_base.filter_remotes(remotes, options)
        if remotes is None:
            report.append("%s%s: Failed filtering remotes.%s" % (terminal_colors.TTY_RED, rp, ORIGINAL_COLOR))
            continue
        op_piece, report_piece = git_fetch.do_fetch(rp, remotes)
        all_passed = all_passed and (not op_piece)
        for ri in report_piece:
            report.append(ri)

    git_visitor_base.print_report(all_passed, report)
    return all_passed


if __name__ == "__main__":

    filters = None
    if len(sys.argv) > 1:
        filters = sys.argv[1:]

    r = git_visitor_base.do_visit(None, filters, visitor_fetch)
    if False in r:
        sys.exit(1)