Example #1
0
def install(*reps):
    """Install a repositories and its dependencies"""

    ret = True

    reps = list(filter(lambda x:x, [r.strip() for r in reps]))

    for rep in reps:
        if not is_installed(rep):
            std("Starting installation:         ", term_colors("blue")+"'"+rep+"'"+term_colors("normal"))
            (res, deps) = do_install(rep)

            if not res:
                err("Failed installation:           ", term_colors("red")+"'"+rep+"'"+term_colors("normal"))
                ret = False
            else:
                std("Finished installation:         ", term_colors("green")+"'"+rep+"'"+term_colors("normal"))
                reps.extend([d for d in deps if not d in reps])
        else:
            std("Re-scanning for dependencies: ", term_colors("blue")+"'"+rep+"'"+term_colors("normal"))

            (res, deps) = do_deps_install(rep)

            if not res:
                err("Failed scan:                  ", term_colors("red")+"'"+rep+"'"+term_colors("normal"))
            else:
                std("Finished scan:                ", term_colors("green")+"'"+rep+"'"+term_colors("normal"))
                reps.extend([d for d in deps if not d in reps])
    return ret
Example #2
0
def do(args, unknown):
    res = ls_remote(*args.spec)
    if res == False:
        return False
    else:
        for r in res:
            if is_installed(r):
                std(term_colors("green") + r + term_colors("normal"))
            else:
                std(term_colors("red") + r + term_colors("normal"))
        return True
Example #3
0
File: run.py Project: KWARC/localmh
def do(args, unknown):
    res = ls_remote(*args.spec)
    if res == False:
        return False
    else:
        for r in res:
            if is_installed(r):
                std(term_colors("green")+r+term_colors("normal"))
            else:
                std(term_colors("red")+r+term_colors("normal"))
        return True
Example #4
0
def status(repos, show_unchanged, remote, *args):
    """Does git status on all installed repositories """

    ret = True

    for rep in repos:

        # If we are clean, do nothing
        if is_clean(rep) and not show_unchanged:
            continue

        std("git status", rep)

        if remote:
            r_status = get_remote_status(rep)
            if r_status == "failed":
                std("Remote status:", term_colors("red")+"Unknown (network issues)", term_colors("normal"))
            elif r_status == "ok":
                std("Remote status:", term_colors("green")+"Up-to-date", term_colors("normal"))
            elif r_status == "pull":
                std("Remote status:", term_colors("yellow")+"New commits on remote, please pull. ", term_colors("normal"))
            elif r_status == "push":
                std("Remote status:", term_colors("yellow")+"New local commits, please push. ", term_colors("normal"))
            elif r_status == "divergence":
                std("Remote status:", term_colors("red")+"Remote and local versions have diverged. ", term_colors("normal"))

        val = git_status(rep, *args)
        if not val:
            err("Unable to run git status on", rep)
            ret = False

    return ret
Example #5
0
def format_type(t):
    """
    Formats a type for output to the command line
    """
    if t == "string":
        return term_colors("yellow")+"<string>"+term_colors("normal")
    elif t == "bool":
        return term_colors("green")+"<bool>"+term_colors("normal")
    elif t == "int":
        return term_colors("blue")+"<int>"+term_colors("normal")
    elif t == "int+":
        return term_colors("cyan")+"<int+>"+term_colors("normal")
Example #6
0
def format_type(t):
    """
    Formats a type for output to the command line
    """
    if t == "string":
        return term_colors("yellow") + "<string>" + term_colors("normal")
    elif t == "bool":
        return term_colors("green") + "<bool>" + term_colors("normal")
    elif t == "int":
        return term_colors("blue") + "<int>" + term_colors("normal")
    elif t == "int+":
        return term_colors("cyan") + "<int+>" + term_colors("normal")
Example #7
0
def pull(verbose, *repos):
    """Pulls all currently installed repositories and updates dependencies"""

    # Check if we need to update the local repository
    def needs_updating(rep):
        rep = match_repo(rep, abs=True)
        if verbose:
            return True
        state = get_remote_status(rep)
        return state == "pull" or state == "failed" or state == "divergence"

    ret = True

    repos = list(filter(lambda x: x, [r.strip() for r in repos]))

    for rep in repos:
        std("Starting update:           ",
            term_colors("blue") + "'" + rep + "'" + term_colors("normal"))

        if not do_pull(rep, needs_updating(rep)):
            std("Update failed:             ",
                term_colors("red") + "'" + rep + "'" + term_colors("normal"))
            ret = False
        else:
            std("Update suceeded:           ",
                term_colors("green") + "'" + rep + "'" + term_colors("normal"))

    std("Re-installing updated repositories ...")
    return ret and install(*repos)
Example #8
0
def pull(verbose, *repos):
    """Pulls all currently installed repositories and updates dependencies"""

    # Check if we need to update the local repository
    def needs_updating(rep):
        rep = match_repo(rep, abs=True)
        if verbose:
            return True
        state = get_remote_status(rep)
        return state == "pull" or state == "failed" or state == "divergence"

    ret = True

    repos = list(filter(lambda x:x, [r.strip() for r in repos]))

    for rep in repos:
        std(    "Starting update:           ", term_colors("blue")+"'"+rep+"'"+term_colors("normal"))

        if not do_pull(rep, needs_updating(rep)):
            std("Update failed:             ", term_colors("red")+"'"+rep+"'"+term_colors("normal"))
            ret = False
        else:
            std("Update suceeded:           ", term_colors("green")+"'"+rep+"'"+term_colors("normal"))

    std("Re-installing updated repositories ...")
    return ret and install(*repos)
Example #9
0
def calc_deps_single(repo, apply = False):

    # Log message
    std("Checking dependencies for:   ", repo)

    # find the absolute path
    dirname = find_repo_dir(repo)

    # Getting the real dependencies
    given_dependencies = get_package_dependencies(repo)+[repo]
    given_dependencies = list(set(given_dependencies))

    # All the required paths
    real_paths = {}

    for root, dirs, files in os.walk(dirname):
        path = root.split('/')
        for file in files:
            fileName, fileExtension = os.path.splitext(file)
            if fileExtension != ".tex":
                continue

            # read the file
            for f in read_file_lines(os.path.join(root, file)):

                for find in re.findall(r"\\(usemhvocab|usemhmodule|adoptmhmodule|importmhmodule)\[(([^\]]*),)?repos=([^,\]]+)(\s*)(,([^\]])*)?\]", f):
                    real_paths[find[3]] = True

                for find in re.findall(r"\\(usemodule|adoptmodule|importmodule|usevocab)\[([^\]]+)\]", f):
                    real_paths[find[1]] = True

                for find in re.findall(r"\\(MathHub){([^\}]+)}", f):
                    real_paths[find[1]] = True

                for find in re.findall(r"\\(gimport|guse|gadpot)\[([^\]]+)\]", f):
                    real_paths[find[1]] = True

    # Now only take paths which have exactly two parts
    real_dependencies = []
    for path in real_paths:
        comps = path.split("/")
        if len(comps) < 2:
            continue
        real_dependencies.append(comps[0]+"/"+comps[1])

    real_dependencies = list(set(real_dependencies))

    # No need to require itself
    while repo in real_dependencies: real_dependencies.remove(repo)
    while repo in given_dependencies: given_dependencies.remove(repo)


    # we are missing the ones that are real but not given
    missing = list(filter(lambda x:not x in given_dependencies, real_dependencies))

    # we do not need those that are given but not real
    not_needed = list(filter(lambda x:not x in real_dependencies, given_dependencies))

    # the others are fine
    fine  = list(filter(lambda x:x in real_dependencies, given_dependencies))

    ret = {
            "fine": fine,
            "missing": missing,
            "not_needed": not_needed,
            "should_be": real_dependencies
    }

    std("---")
    if len(ret["fine"]) > 0:
        std(term_colors("green"),  "Used dependencies:         ", term_colors("normal"), ", ".join(ret["fine"]))
    if len(ret["not_needed"]) > 0:
        std(term_colors("yellow"), "Superfluous dependencies:  ", term_colors("normal"), ", ".join(ret["not_needed"]))
    if len(ret["missing"]) > 0:
        std(term_colors("red"),    "Missing dependencies:      ", term_colors("normal"), ", ".join(ret["missing"]))
    std("---")
    if len(ret["missing"]) > 0 or len(ret["not_needed"]) > 0:
        std("Dependencies should be: ", ", ".join(ret["should_be"]))

    if apply:
        write_deps(dirname, ret["should_be"])