Example #1
0
def test_splitext():
    assert paths.split_extension("") == ("", "")
    assert paths.split_extension("/") == ("", "")
    assert paths.split_extension("/a") == ("a", "")
    assert paths.split_extension("/a/b") == ("b", "")
    assert paths.split_extension("/a/b.") == ("b", "")
    assert paths.split_extension("/a/b.c") == ("b", "c")
    assert paths.split_extension("/a/b.txt") == ("b", "txt")
    assert paths.split_extension("/a/b.abcdef") == ("b", "abcdef")
    assert paths.split_extension("/a/b.ABCDEF") == ("b", "ABCDEF")
    assert paths.split_extension("/a/b.c/") == ("", "")
Example #2
0
    def _path_to_tool(self, path):
        import hou

        match = self.nodeexp.match(path)
        if match:
            base, ext = paths.split_extension(match.group(1))
            return hou.shelves.tool(base)
Example #3
0
 def available_languages(self, path):
     store = self.store
     dirpath, filename = paths.split_dirpath(path)
     basename, ext = paths.split_extension(filename)
     result = []
     for lang in self.langauges:
         if lang == self.default_language:
             langfilename = filename
         else:
             langfilename = "%s.%s.%s" % (basename, lang, ext)
         if store.exists(paths.join(dirpath, langfilename)):
             result.append(lang)
     return result
Example #4
0
    def _get_include_content(self, path, root, context, icache, ref):
        incpath, name, value, unwrap = self._parse_include_path(ref)

        if incpath and incpath != paths.basepath(path):
            # The include is in another page
            incpath = paths.join(path, incpath)
            _, ext = paths.split_extension(incpath)
            if not ext:
                incpath = context.pages.source_path(incpath)

            incpath = paths.join(path, incpath)
            return self._load_include(incpath, root, context, icache, name, value, unwrap)
        elif name and value:
            # If no path was given, or it was this page's path, grab the target
            # from this page
            return self._target(root, name, value, unwrap)
Example #5
0
    def source_path(self, path, locale=None):
        path, frag = paths.split_fragment(path)

        if (
            not path.endswith("/") and self.store.exists(path) and
            self.store.is_dir(path)
        ):
            path += "/"
        if path.endswith("/"):
            path += self.index_page_name + self.wiki_ext

        basepath, ext = paths.split_extension(path)
        if not ext:
            if locale:
                path = "%s.%s%s" % (basepath, locale, ext)
            path += self.wiki_ext

        return path
Example #6
0
def path_to_components(path):
    """
    Takes a help path and returns a named tuple of the following components:

    * ``table`` - the node category name, e.g. ``Object``.
    * ``scopeop`` - if the node has a scope, the name of the scope node,
        otherwise an empty string.
    * ``namespace`` - the node's namespace, or an empty string.
    * ``name`` - the node's "core" name.
    * ``version`` - the node's version string.
    * ``ext`` - the filename extension given in the path (if any).
    * ``section`` - an asset section name, or an empty string.
    """

    match = help_exp.match(path)
    if not match:
        return None

    dirname = match.group("dir")
    if dirname not in dir_to_table:
        return None
    table = dir_to_table[dirname]

    namespace = match.group("ns")
    scopeop = match.group("scope")
    if scopeop:
        scopeop = scopeop.replace("--", "::")

    name = match.group("name")
    # Separate the extension
    corename, ext = paths.split_extension(name)

    version = None
    if "-" in corename:
        corename, version = corename.rsplit("-", 1)

    section = match.group("section")
    if section and section.startswith("/"):
        section = section[1:]

    return NodeInfo(table, scopeop, namespace, corename, version, ext, section)