Example #1
0
def reset_pack(pack):
    """Resets a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping reset. ")
        return True

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, skipping removal. ")
    else:
        if not remove_pack(pack + sep + pconfig):
            err("Pack", pack, "could not be removed, --reset has failed. ")
            return False

    if not install_pack(pack + sep + pconfig):
        err("Pack", pack, "could not be (re)installed, --reset has failed. ")
        return False
    return True
Example #2
0
def update_pack(pack):
    """Updates a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, can not update. ")
        return False

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping update. ")
        return True

    try:
        return pack_setup.update(pack_dir, pconfig)
    except classes.UnsupportedAction:
        err("Pack", pack,
            "does not support updating. You may want to --reset the pack. ")
        return False
Example #3
0
File: run.py Project: KWARC/localmh
def do(args, unknown):
    rep = match_repo(args.repo)

    if rep == None:
        err("Unable to find repository '"+args.repo+"' locally. ")
        return False

    # Create a generated instance.
    gen = Generated(rep)

    if args.branch == None and not args.list and not args.status:
        err("Branch argument is required unless --list or --status is given. ")
        return False

    if args.install:
        return gen.install_branch(args.branch)

    if args.init:
        return gen.init_branch(args.branch)

    if args.pull:
        return gen.pull_branch(args.branch)

    if args.push:
        return gen.push_branch(args.branch)

    if args.list:
        for b in gen.get_all_branches(tuple=False):
            std(b)
        return True

    return gen.print_status()
Example #4
0
def do(args, unknown):
    rep = match_repo(args.repo)

    if rep == None:
        err("Unable to find repository '" + args.repo + "' locally. ")
        return False

    # Create a generated instance.
    gen = Generated(rep)

    if args.branch == None and not args.list and not args.status:
        err("Branch argument is required unless --list or --status is given. ")
        return False

    if args.install:
        return gen.install_branch(args.branch)

    if args.init:
        return gen.init_branch(args.branch)

    if args.pull:
        return gen.pull_branch(args.branch)

    if args.push:
        return gen.push_branch(args.branch)

    if args.list:
        for b in gen.get_all_branches(tuple=False):
            std(b)
        return True

    return gen.print_status()
Example #5
0
def reset_pack(pack):
    """Resets a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping reset. ")
        return True

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, skipping removal. ")
    else:
        if not remove_pack(pack+sep+pconfig):
            err("Pack", pack, "could not be removed, --reset has failed. ")
            return False

    if not install_pack(pack+sep+pconfig):
        err("Pack", pack, "could not be (re)installed, --reset has failed. ")
        return False
    return True
Example #6
0
def write_deps(dirname, deps):
    """Writes dependencies into a given module. """

    f = lmh_locate("content", match_repo(dirname), "META-INF", "MANIFEST.MF")
    n = re.sub(r"dependencies: (.*)", "dependencies: "+",".join(deps), read_file(f))
    write_file(f, n)
    std("Wrote new dependencies to", f)
Example #7
0
def do(args, unknown):

    if not args.no_check and not check_deps():
        err("Dependency check failed. ")
        err("Cannot perform specefied action. ")
        err("Use --no-check to skip checking dependencies. ")
        return False

    if len(args.pack) == 0:
        args.pack = ["default"]
        if args.saction == "update":
            # Update self as well when calling lmh setup --update
            args.pack += ["self"]

    if args.saction == "install":
        return lmh.lib.packs.install(*args.pack)
    elif args.saction == "update":
        return lmh.lib.packs.update(*args.pack)
    elif args.saction == "remove":
        return lmh.lib.packs.remove(*args.pack)
    elif args.saction == "reset":
        return lmh.lib.packs.reset(*args.pack)
    elif args.saction == "manage":
        return lmh.lib.packs.manage(*args.pack)
    elif args.saction == "unmanage":
        return lmh.lib.packs.unmanage(*args.pack)
    elif args.saction == "status":
        return lmh.lib.packs.status(*args.pack)
    else:
        std("No setup action specefied, assuming --install. ")
        std("Please specify some action in the future. ")
        return lmh.lib.packs.install(*args.pack)
Example #8
0
def remove_pack(pack):
    """Removes a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, nothing to remove. ")
        return True

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping removal. ")
        return True

    try:
        return pack_setup.remove(pack_dir, pconfig)
    except classes.UnsupportedAction:
        err("Pack", pack,
            "does not support removal. Maybe you can remove it manually. ")
        return False
Example #9
0
 def run_lmh_find_moved(find, replace):
     if simulate:
         # We will run it over dest only.
         std("lmh", "find", json.dumps(find), "--replace", json.dumps(replace), "--apply", odest)
     else:
         # Append it to to a list.
         local_finds.append(find)
         local_replaces.append(replace)
Example #10
0
def unmanage_pack(pack):
    """Marks a single pack as managed"""

    (pack, sep, pconfig) = pack.partition(":")

    std("Marked packaged '"+pack+"' as unamanged. ")

    return get_pack_setup(pack).mark_unmanaged()
Example #11
0
def unmanage_pack(pack):
    """Marks a single pack as managed"""

    (pack, sep, pconfig) = pack.partition(":")

    std("Marked packaged '" + pack + "' as unamanged. ")

    return get_pack_setup(pack).mark_unmanaged()
Example #12
0
def rm_untracked(file, t = ""):
    if not is_tracked(file):
        try:
            os.remove(file)
            std("Removed", t, file)
        except:
            err("Unable to remove", file)
            return False
    return True
Example #13
0
 def run_lmh_find_moved(find, replace):
     if simulate:
         # We will run it over dest only.
         std("lmh", "find", json.dumps(find), "--replace",
             json.dumps(replace), "--apply", odest)
     else:
         # Append it to to a list.
         local_finds.append(find)
         local_replaces.append(replace)
Example #14
0
def do(cmd, args, *repos):
    """Does an arbitraty git commit on all repositories. """
    ret = True
    if args == None:
        args = [""]
    args = args[0].split(" ")
    for rep in repos:
        std("git "+cmd, args[0], rep)
        ret = git_do(rep, cmd, *args) and ret

    return ret
Example #15
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 #16
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 #17
0
def list_config():
    """
    Prints information about all available configuration settings to stdout. 
    """

    for key in sorted(config_meta.keys()):
        try:
            if config_meta[key]["hidden"]:
                continue
        except:
            pass
        std(key +" =", format_type(config_meta[key]["type"]), json.dumps(get_config(key)))
Example #18
0
def list_config():
    """
    Prints information about all available configuration settings to stdout. 
    """

    for key in sorted(config_meta.keys()):
        try:
            if config_meta[key]["hidden"]:
                continue
        except:
            pass
        std(key + " =", format_type(config_meta[key]["type"]),
            json.dumps(get_config(key)))
Example #19
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 #20
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 #21
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 #22
0
def find_and_replace_file(file, match, replace, replace_match = None):
    """Finds and replaces a single file. """

    if len(match) != len(replace):
        err("Find and Replace patterns are not of the same length. ")
        return False

    # Compile thex regexp
    try:
        match_regex = [re.compile(m) for m in match]
    except Exception as e:
        err(e)
        err("Unable to compile regular expressions. ")
        return False

    # get the repository
    repo = os.path.relpath(find_repo_dir(file), lmh_locate("content"))

    # We did nothing yet
    did = False
    if replace_match == None:
        def replace_match(match, replace):
            # TODO: Migrate this to the parent scope.
            # did = True

            # Make a template,
            replacer_template = {}
            replacer_template["repo"] = repo
            for i, g in enumerate(match.groups()):
                replacer_template["g"+str(i)] = g

            # And replace in it
            return Template(replace).substitute(replacer_template)

    # Read file and search
    file_content = read_file(file)
    new_file_content = file_content

    # Iterate over the regexes and replace
    for (m, r) in zip(match_regex, replace):
        new_file_content = re.sub(m, lambda x:replace_match(x, r), new_file_content)

    if file_content != new_file_content:
        std(file)
        # If something has changed, write back the file.
        write_file(file, new_file_content)
    if did:
        std(file)
    return did
Example #23
0
def hook_post_install(rep):
    """
        Hook that runs before installation of a repository.
    """

    # Create an instance for the generated branch.
    gen = Generated(rep)

    # and install all of them.
    for g in gen.get_all_branches(tuple=False):
        std("Setting up generated branch '" + g + "'. ")
        if not gen.install_branch(g):
            return False

    return hook_post_update(rep)
Example #24
0
def hook_post_install(rep):
    """
        Hook that runs before installation of a repository.
    """

    # Create an instance for the generated branch.
    gen = Generated(rep)

    # and install all of them.
    for g in gen.get_all_branches(tuple=False):
        std("Setting up generated branch '"+g+"'. ")
        if not gen.install_branch(g):
            return False

    return hook_post_update(rep)
Example #25
0
def status_pack(pack):
    """Prints status of a pack"""

    (pack, sep, pconfig) = pack.partition(":")

    setup_pack = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    std("---")
    std("Package", pack)
    std("Installed:", setup_pack.is_installed(pack_dir))
    std("Managed:", setup_pack.is_managed())
    std("---")

    return True
Example #26
0
def status_pack(pack):
    """Prints status of a pack"""

    (pack, sep, pconfig) = pack.partition(":")

    setup_pack = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    std("---")
    std("Package", pack)
    std("Installed:", setup_pack.is_installed(pack_dir))
    std("Managed:", setup_pack.is_managed())
    std("---")

    return True
Example #27
0
def export(f=None):
    """Exports the list of currently installed repositories. """

    # Get all locally installed directories
    installed = match_repos(lmh_locate("content"))

    if (f == None):
        for mod in installed:
            std(mod)
        return True
    try:
        write_file(f, os.linesep.join(installed))
        return True
    except:
        err("Unable to write %s" % f)
        return False
Example #28
0
def export(f = None):
    """Exports the list of currently installed repositories. """

    # Get all locally installed directories
    installed = match_repos(lmh_locate("content"))

    if(f == None):
        for mod in installed:
            std(mod)
        return True
    try:
        write_file(f, os.linesep.join(installed))
        return True
    except:
        err("Unable to write %s" % f)
        return False
Example #29
0
File: run.py Project: KWARC/localmh
def do(args, unknown):

    url = get_config("mh::issue_url")
    repo = match_repo(args.repo)

    # if we can not match the repository, exit
    if not repo:
        err("Unable to match repository '"+repo+"'")
        return False

    # Try and open the url
    # and if that fails, just print it.      
    url = url.replace("$name", repo)
    if not webbrowser.open(url):
        std(url)

    return True
Example #30
0
def add_symis(text, symis):
    addtext = []

    for sym in symis:
        if sym[1] == 0:
            continue
        addtext.append("\\sym%s{%s}\n" % ("i"*sym[1], "}{".join(sym[2])))

    # HACK: Print out the symbols we add
    std(", ".join(addtext).replace("\n", ""))

    addtext = remove_doubles(addtext)
    pattern = r"\\begin{modsig}((.|\n)*)\\end{modsig}"



    return re.sub(pattern, r"\\begin{modsig}\1"+"".join(addtext)+"\\end{modsig}", text)
Example #31
0
def do(args, unknown):

    url = get_config("mh::issue_url")
    repo = match_repo(args.repo)

    # if we can not match the repository, exit
    if not repo:
        err("Unable to match repository '" + repo + "'")
        return False

    # Try and open the url
    # and if that fails, just print it.
    url = url.replace("$name", repo)
    if not webbrowser.open(url):
        std(url)

    return True
Example #32
0
def add_symis(text, symis):
    addtext = []

    for sym in symis:
        if sym[1] == 0:
            continue
        addtext.append("\\sym%s{%s}\n" % ("i" * sym[1], "}{".join(sym[2])))

    # HACK: Print out the symbols we add
    std(", ".join(addtext).replace("\n", ""))

    addtext = remove_doubles(addtext)
    pattern = r"\\begin{modsig}((.|\n)*)\\end{modsig}"

    return re.sub(pattern,
                  r"\\begin{modsig}\1" + "".join(addtext) + "\\end{modsig}",
                  text)
Example #33
0
    def print_status(self):
        """
            Prints some status information about the branches.
        """
        std(    "Repository Name:    ", self.repo)

        for (b, p) in self.get_all_branches():
            std("Generated Branch:   ", "'"+b+"'")
            std("Path:               ", "'"+p+"'")
            std("Installed:          ", "Yes" if self.is_installed(b) else "No")
Example #34
0
def get_item_source(source_string, def_source, def_branch, name=""):
    """Gets the source branch and origin from a string and defaults. """
    source = def_source
    branch = def_branch

    if not source_string == "":
        index = source_string.find("@")
        if index == 0:
            branch = source_string[1:]
        elif index > 0:
            source = source_string[:index]
            branch = source_string[index+1:]
        else:
            source = source_string

        std("Using", name, "Version: "+source+"@"+branch)

    return (source, branch)
Example #35
0
    def print_status(self):
        """
            Prints some status information about the branches.
        """
        std("Repository Name:    ", self.repo)

        for (b, p) in self.get_all_branches():
            std("Generated Branch:   ", "'" + b + "'")
            std("Path:               ", "'" + p + "'")
            std("Installed:          ",
                "Yes" if self.is_installed(b) else "No")
Example #36
0
def add_symbols(fname, warns=[]):
    # Add missing symbols form language bindings to module

    q = find_sds(fname, warns)
    if len(q) == 1:
        # we have already done something
        return q[0]

    (fmodname, defs, syms, symdefs, modcontent) = q

    # check if we still need them
    def need_sym(d):
        # negated
        req = ["sym", d[1], d[2]]
        try:
            name = "-".join(d[2])
        except:
            name = ""

        # Normalise for issue #166
        req[2] = "-".join(req[2]).split("-")
        req[1] = len(req[2])

        # We have an empty argument, what's this?
        if name == "":
            # it is empty
            return False

        return not ((req in syms) or (name in symdefs))

    # OK filter them out
    required = list(filter(need_sym, defs))

    # Add them if we need to
    if len(required) > 0:
        std("Adding %s symbol definition(s) from %s: " %
            (len(required), fname),
            newline=False)
        towrite = add_symis(modcontent, required)
        std()
        write_file(fmodname, towrite)

    return True
Example #37
0
def add_symbols(fname, warns=[]):
    # Add missing symbols form language bindings to module

    q = find_sds(fname, warns)
    if len(q) == 1:
    # we have already done something
        return q[0]

    (fmodname, defs, syms, symdefs, modcontent) = q

    # check if we still need them
    def need_sym(d):
        # negated
        req = ["sym", d[1], d[2]]
        try:
            name = "-".join(d[2])
        except:
            name = ""

        # Normalise for issue #166
        req[2] = "-".join(req[2]).split("-")
        req[1] = len(req[2])

        # We have an empty argument, what's this?
        if name == "":
            # it is empty
            return False

        return not ((req in syms) or (name in symdefs))

    # OK filter them out
    required = list(filter(need_sym, defs))

    # Add them if we need to
    if len(required) > 0:
        std("Adding %s symbol definition(s) from %s: " % (len(required), fname), newline = False)
        towrite = add_symis(modcontent, required)
        std()
        write_file(fmodname, towrite)

    return True
Example #38
0
File: run.py Project: KWARC/localmh
def do(args, unknown):
    if args.reset_all:
        try:
            os.remove(config.config_file)
            return True
        except:
            pass
        return False

    if args.reset:
        if args.key == None:
            err("Missing key. ")
            return False
        try:
            return config.reset_config(args.key)
        except:
            pass
        return False

    if args.key == None:
        config.list_config()
        std()
        std("Type 'lmh config KEY' to get more information on KEY. ")
        std("Type 'lmh config KEY VALUE' to change KEY to VALUE. ")
        return True
    elif args.value == None:
        return config.get_config_help(args.key)
    else:
        try:
            return config.set_config(args.key, args.value)
        except:
            pass
        return False
Example #39
0
def do(args, unknown):
    if args.reset_all:
        try:
            os.remove(config.config_file)
            return True
        except:
            pass
        return False

    if args.reset:
        if args.key == None:
            err("Missing key. ")
            return False
        try:
            return config.reset_config(args.key)
        except:
            pass
        return False

    if args.key == None:
        config.list_config()
        std()
        std("Type 'lmh config KEY' to get more information on KEY. ")
        std("Type 'lmh config KEY VALUE' to change KEY to VALUE. ")
        return True
    elif args.value == None:
        return config.get_config_help(args.key)
    else:
        try:
            return config.set_config(args.key, args.value)
        except:
            pass
        return False
Example #40
0
def find_file(file, match):
    """Finds inside a single file. """

    # Compile thex regexp
    try:
        match_regex = [re.compile(m) for m in match]
    except Exception as e:
        err(e)
        err("Unable to compile regular expressions. ")
        return False

    # Read file and search
    file_content = read_file(file)

    ret = False
    for i, m in enumerate(match_regex):
        if re.search(m, file_content) != None:
            if len(match) > 1:
                std(str(i), file)
            else:
                std(file)
            ret = True

    return ret
Example #41
0
def do_deps_install(rep):
    """
        Runs a dependency check.
    """

    std("Looking for dependencies ...")

    deps = []

    try:
        for dep in get_package_dependencies(rep):
            if not is_installed(dep):
                std("   unsatisfied dependency: ", "'"+dep+"'")
            else:
                std("   satisfied dependency:", "'"+dep+"'")
            deps.append(dep)
    except Exception as e:
        std(e)
        err("Failed.")
        return (False, deps)

    std("Done. ")

    return (True, deps)
Example #42
0
def remove_pack(pack):
    """Removes a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, nothing to remove. ")
        return True

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping removal. ")
        return True

    try:
        return pack_setup.remove(pack_dir, pconfig)
    except classes.UnsupportedAction:
        err("Pack", pack, "does not support removal. Maybe you can remove it manually. ")
        return False
Example #43
0
def update_pack(pack):
    """Updates a single pack. """

    (pack, sep, pconfig) = pack.partition(":")

    pack_setup = get_pack_setup(pack)
    pack_dir = get_pack_dir(pack)

    if not pack_setup:
        return False

    if not pack_setup.is_installed(pack_dir):
        err("Pack", pack, "is not installed, can not update. ")
        return False

    if not pack_setup.is_managed():
        std("Pack", pack, "is marked as unmanaged, skipping update. ")
        return True

    try:
        return pack_setup.update(pack_dir, pconfig)
    except classes.UnsupportedAction:
        err("Pack", pack, "does not support updating. You may want to --reset the pack. ")
        return False
Example #44
0
def commit(msg, verbose, *repos):
    """Commits all installed repositories """

    ret = True

    for rep in repos:
        std("git commit", rep, "", newline=False)
        if verbose or git_do_data(rep, "status", "--porcelain")[0] != "":
            std()
            ret = git_commit(rep, "-a", "-m", msg) and ret
        else:
            std("Ok, nothing to commit. ")
    return ret
Example #45
0
def get_config_help(key):
    """
    Prints help to stdout about the given configuration settting. 
    """

    # check if the key exists
    if not key in config_meta:
        err("Option", key, " does not exist. ")
        return False

    # get its meta-information
    meta = config_meta[key]

    # and print that
    std(format_type(meta["type"]), key)
    std(meta["help"])
    std("Current Value: " + json.dumps(get_config(key)))
    std("Default Value: " + json.dumps(meta["default"]))

    return True
Example #46
0
def get_config_help(key):
    """
    Prints help to stdout about the given configuration settting. 
    """
    
    # check if the key exists
    if not key in config_meta:
        err("Option", key, " does not exist. ")
        return False

    # get its meta-information
    meta = config_meta[key]
    
    # and print that
    std(format_type(meta["type"]), key)
    std(meta["help"])
    std("Current Value: " + json.dumps(get_config(key)))
    std("Default Value: " + json.dumps(meta["default"]))

    return True
Example #47
0
def do(args, unknown):
    # If there are no repositories, check everything for dependencies.
    if len(args.spec) == 0:
        std("Nothing to install, re-installing all existing repositories.  ")
        return install(*match_repos(lmh_locate("content")))

    if not get_config("install::noglobs"):
        args.spec = ls_remote(*args.spec)
        if len(args.spec) == 0:
            err("Nothing to install...")
            return True
        if args.no_confirm_install:
            std("Picked", len(args.spec),"repositories. ")
        else:
            std("Picked", len(args.spec),"repositories: ")
            std(*args.spec)
            if read_raw("Continue (y/N)?").lower() != "y":
                err("Installation aborted. ")
                return False


    return install(*args.spec)
Example #48
0
def push(verbose, *repos):
    """Pushes all currently installed repositories. """

    # Check if we need to update the local repository
    def needs_updating(rep):
        state = get_remote_status(rep)
        return state == "push" 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("git push", rep, "", newline = False)

        if verbose or needs_updating(rep):
            std()
            ret = git_push(rep) and ret
        else:
            std("OK, nothing to push. ")

    return ret
Example #49
0
def do(args, unknown):

    if not webbrowser.open(get_config("gl::issue_url")):
        std(get_config("gl::issue_url"))

    return True
Example #50
0
    def init_branch(self, branch):
        """
            Creates a new branch for status information.
        """

        # Get name and path.
        bsplit = branch.split(":")
        if len(bsplit) == 1:
            (name, pth) = (bsplit[0], bsplit[0])
        else:
            (name, pth) = (bsplit[0], bsplit[1])

        std("Creating branch '" + name + "' at '" + pth + "'. ")

        # Check if the branch already exists.
        if name in self.get_all_branches(tuple=False):
            err("Branch '" + name +
                "' already exists, can not create it again. Use --install to install. "
                )
            return False

        # Get the paths
        rpath = match_repo(self.repo, abs=True)
        dpath = os.path.join(rpath, pth)
        meta_inf_path = os.path.join(rpath, "META-INF", "MANIFEST.MF")

        # Find paths for the .gitignore
        gitignore_path = os.path.join(rpath, ".gitignore")
        gitignore_entry = os.path.join("/", pth) + "\n"

        # and either add to it or create it.
        if os.path.isfile(gitignore_path):
            write_file(gitignore_path,
                       read_file(gitignore_path) + gitignore_entry)
        else:
            write_file(gitignore_path, gitignore_entry)

        # Update the meta-inf
        written = False
        lines = get_metainf_lines(self.repo)

        # try to append it to a line that already exists.
        for (i, l) in enumerate(lines):
            if l.startswith(gbranchstring):
                lines[i] = lines[i].rstrip("\n") + " " + branch
                written = True
                break

        # or make a new one.
        if written == False:
            lines.extend([gbranchstring + " " + branch])

        # and write that file.
        write_file(meta_inf_path, lines)

        # Create the orphaned branch.
        if not make_orphan_branch(rpath, name):
            return False

        # push it
        if not do(rpath, "push", "-u", "origin", name):
            err("Pushing branch to origin failed. ")
            return False

        # Clear the deploy branch cache for this repository.
        self.clear_branch_cache()

        # install it.
        if not self.install_branch(name):
            return False

        # change the commit message
        if not do(dpath, "commit", "--amend", "--allow-empty", "-m",
                  "Create deploy branch. "):
            return False

        # and push it.
        if not do(dpath, "push", "--force", "origin", name):
            return False

        std("Generated files branch '" + name +
            "' created, installed and pushed. ")
        std("Please commit and push META-INF/MANIFEST.MF and .gitignore to publish installation. "
            )

        return True
Example #51
0
def transmod(modname, org_lang, dest_lang, pre_terms = {}):
    """Translate a module from one language to another. """

    # Load json from a file if pre_terms is a string
    if type(pre_terms) == str:
        try:
            pre_terms = json.loads(read_file(pre_terms))
        except:
            try:
                pre_terms = json.loads(pre_terms)
            except:
                err("Unable to load json in file %r" % pre_terms)
                err("Make sure you have given a valid JSON-encoded string or path to a valid .json file. ")
                return False

    # Load the set of pre-translated terms
    if org_lang in pre_terms:
        pre_terms = pre_terms[org_lang]
        if dest_lang in pre_terms:
            pre_terms = pre_terms[dest_lang]
        else:
            pre_terms = {}
    else:
        pre_terms = {}


    # filenames for the original + translated modules
    orfn = "%s.%s.tex" % (modname, org_lang)
    newfn = "%s.%s.tex" % (modname, dest_lang)

    # read the original file
    try:
        content = read_file(orfn)
    except:
        err("Unable to read original module", orfn)
        return False

    #
    # STEP 1: Replace the third argument to the modnl + viewnl environments
    #

    content = re.sub(r"(\\begin\{modnl\}\[[^\]]*\]\{[^\}]*\})\{"+org_lang+r"\}", r"\1{"+dest_lang+"}", content)
    content = re.sub(r"(\\begin\{viewnl\}\[[^\]]*\]\{[^\}]*\})\{"+org_lang+r"\}", r"\1{"+dest_lang+"}", content)

    #
    # STEP 2: Update everything inside the environments
    #

    def replacer(match):
        content = match.group(2)

        # trefi -> mtrefi
        content = re.sub(r"\\trefi\[([^\]]*)\]\{([^\}]*)\}", r"\\mtrefi[\1?\2]{\\ttl{\2}}", content)
        # trefii -> mtrefii
        content = re.sub(r"\\trefii\[([^\]]*)\]\{([^\}]*)\}\{([^\}]*)\}", r"\\mtrefii[\1?\2-\3]{\\ttl{\2 \3}}", content)
        # trefiii -> mtrefiii
        content = re.sub(r"\\trefiii\[([^\]]*)\]\{([^\}]*)\}\{([^\}]*)\}\{([^\}]*)\}", r"\\mtrefiii[\1?\2-\3-\4]{\\ttl{\2 \3 \4}}", content)

        # defi
        content = re.sub(r"\\defi\[([^\]]*)\]\{([^\}]*)\}", r"\\defi[\1]{\\ttl{\2}}", content)
        content = re.sub(r"\\defi\{([^\}]*)\}", r"\\defi[\1]{\\ttl{\1}}", content)
        # defii
        content = re.sub(r"\\defii\[([^\]]*)\]\{([^\}]*)\}\{([^\}]*)\}", r"\\defii[\1]{\\ttl{\2}}{\\ttl{\3}}", content)
        content = re.sub(r"\\defii\{([^\}]*)\}\{([^\}]*)\}", r"\\defii[\1-\2]{\\ttl{\1}}{\\ttl{\2}}", content)
        # defiii
        content = re.sub(r"\\defiii\[([^\]]*)\]\{([^\}]*)\}\{([^\}]*)\}\{([^\}]*)\}", r"\\defiii[\1]{\\ttl{\2}}{\\ttl{\3}}{\\ttl{\4}}", content)
        content = re.sub(r"\\defiii\{([^\}]*)\}\{([^\}]*)\}\{([^\}]*)\}", r"\\defiii[\1-\2-\3]{\\ttl{\1}}{\\ttl{\2}}{\\ttl{\3}}", content)


        def inner_supper(m):
            # Inner replacement function
            # Inserts the \ttl before any trailing whitespace.

            (sub_inner, n) = re.subn(r"([\n\f\t\v\s]+)$", r"}\1", m.group(1))
            if n == 0:
                sub_inner+="}"

            return r"\ttl{"+sub_inner+m.group(6)

        def supper(m):
            # Outer replacement function.
            toreplace = m.group(4)

            if re.match(r"^([\n\f\t\v\s]*)$", toreplace):
                # we are only whitespaces => do nothing
                pass
            else:
                # we are ntop only whitespaces => replace some sentences.
                toreplace = re.sub(r"(((\w)+\s+)*((\w)+\s*))([\.\!\?\,\;]?)", inner_supper, toreplace)
            return m.group(1)+toreplace+m.group(5)

        # Replace non-wrapped text fragments
        content = re.sub(r"((\]|\}|\$[^\$]*\$)(\w*))([^\\\{\}\$\]\[]+)(\s*)", supper, content)

        # and return the content
        return match.group(1)+content+match.group(4)

    # Replace text inside the environments of modnl and viewnl
    content = re.sub(r"(\\begin{modnl})((.|\n)*)(\\end{modnl})", replacer, content)
    content = re.sub(r"(\\begin{viewnl})((.|\n)*)(\\end{viewnl})", replacer, content)

    #
    # STEP 3: Apply the pre-translated directory to \ttl{...}
    #

    # Replace all the technical terms
    def replacer2(match):
        # prefer full matches
        if match.groups(1)[0] in pre_terms:
            return match.groups(1)[0][pre_terms]


        # Split the terms and look check if we can translate them
        terms = []
        for t in match.groups(1)[0].split(" "):
            if t in pre_terms:
                terms.append((pre_terms[t], True))
            else:
                terms.append((t, False))

        # Put the results back together
        result = ""
        is_open_ttl = False

        # For each of the terms
        for (r, s) in terms:
            if not is_open_ttl:
                # We do not have an openn ttl
                if s:
                    result+=r+" "
                else:
                    result+="\\ttl{"+r+" "
                    is_open_ttl = True
            else:
                # We do have an open ttl
                if s:
                    result += result[:-1]+"} "+r+" "
                    is_open_ttl = False
                else:
                    result += r+" "
        # Close the last bracket if needed
        result = result[:-1]
        if is_open_ttl:
            result +="}"

        return result

    content = re.sub(r"\\ttl\{([^\}]*)\}", replacer2, content)

    # write back the file
    try:
        write_file(newfn, content)
    except:
        err("Unable to write new module", newfn)
        return False

    # and do some logging
    std("Prepared translation of", modname, "from")
    std(orfn)
    std("to")
    std(newfn)
    std("Please finish the translation and then commit the module. ")

    # we need it for the return code
    return True
Example #52
0
def create_multi(modname, pre_terms, *langs):
    if len(langs) == 0:
        err("You need to create at least one language. ")
        return False
    lang = langs[0]

    # Read the module
    try:
        content = read_file(modname+".tex")
    except:
        err("Unable to read original module", modname+".tex")
        return False

    # Module content
    module_content_regex = r"^((?:.|\n)*)\\begin\{module\}\[(?:(.*),\s*)?id=([^,\]]*)(?:\s*(.*))\]((?:.|\n)*?)\\end\{module\}((?:.|\n)*)$"
    module_move_regex = r"(\\(?:gimport|symdef|symtest|symvariant|symi+)(?:(?:\[(?:[^\]])*\])|(?:\{(?:[^\}])*\}))*((\n|$|\s)?))"

    # Find the module
    mod_content = re.findall(module_content_regex, content)

    if len(mod_content) != 1:
        err("Expected exactly one module environment. (Is the module really monolingual?)")
        return False

    mod_content = mod_content[0]

    # Main Language Content
    main_module = ""
    main_language = ""

    # Prefix and suffix to add to the module
    mod_prefix = mod_content[0]
    mod_suffix = mod_content[5]

    # Id of the module
    mod_id = mod_content[2]
    mod_meta = mod_content[1]+mod_content[3]
    if mod_meta != "":
        mod_meta = "["+mod_meta+"]"

    # We only want to move these
    module_to_move = "".join([m[0] for m in re.findall(module_move_regex, mod_content[4])])
    module_keep = re.sub(module_move_regex, lambda match:match.group(2), mod_content[4])

    # Assemble the main module
    main_module = mod_prefix
    main_module += "\\begin{modsig}"+mod_meta+"{"+mod_id+"}"
    main_module += module_to_move
    main_module += "\\end{modsig}"
    main_module += mod_suffix

    try:
        write_file(modname+".tex", main_module)
    except:
        err("Unable to write", modname+".tex")
        return False

    # Assemble the main language binding
    main_language = mod_prefix
    main_language += "\\begin{modnl}"+mod_meta+"{"+mod_id+"}{"+lang+"}\n"
    main_language += module_keep
    main_language += "\n\\end{modnl}"
    main_language += mod_suffix

    try:
        write_file(modname+"."+lang+".tex", main_language)
    except:
        err("Unable to write", modname+"."+lang+".tex")
        return False

    lmh.lib.io.__supressStd__ = True

    # Add the symbols frome the language file name
    add_symbols(modname+"."+lang+".tex")

    # Translate to all the other languages
    for l in langs[1:]:
        if not transmod(modname, lang, l, pre_terms = pre_terms):
            lmh.lib.io.__supressStd__ = False
            return False
    lmh.lib.io.__supressStd__ = False

    std("Created multilingual module", modname+".tex")

    # Thats it.
    return True
Example #53
0
def do(args, unknown):
    std("lmh, Version", about.version(), "( git", about.git_version(), ")")
    std()
    std(about.license_text())

    return True
Example #54
0
def do_pull(rep, needs_update):
    """
        Actually pulls a repository.
    """

    # pre-installation hook.
    std("Running pre-update hook for '" + rep + "' ... ", newline=False)

    if not hook_pre_pull(rep):
        err("Failed. ")
        return (False, [])

    std("Done. ")

    ret = True

    if needs_update:
        std("Running git pull ...")
        rgp = git_pull(match_repo(rep, abs=True))
        ret = rgp and ret
        if rgp:
            std("OK")
        else:
            err("Failed (merge conflicts or network issues?)")
            ret = False
    else:
        std("Nothing to pull ...")

    std("Running post-update hook for '" + rep + "' ... ", newline=False)
    if not hook_post_pull(rep):
        err("Failed. ")
        return (False, [])
    std("Done. ")

    return ret