示例#1
0
 def exists(self, path):
     nodetype = api.path_to_nodetype(path)
     if nodetype and not nodetype.hidden():
         hdadef = nodetype.definition()
         info = api.path_to_components(path)
         if hdadef:
             return (
                 (path.endswith(".txt") and hdadef.embeddedHelp()) or
                 (info.section and info.section in hdadef.section())
             )
示例#2
0
    def delete(self, path):
        nodetype = api.path_to_nodetype(path)
        if nodetype:
            hdadef = nodetype.definition()
            if not hdadef:
                raise Exception("%r is not an asset" % path)

            info = api.path_to_components(path)
            section = info.section or "Help"
            if hdadef:
                hdadef.sections()[section].setContents("")
示例#3
0
    def write_file(self, path, bytestring):
        nodetype = api.path_to_nodetype(path)
        if nodetype:
            hdadef = nodetype.definition()
            if not hdadef:
                raise Exception("%r is not an asset" % path)

            info = api.path_to_components(path)
            sections = hdadef.sections()
            section = info.section or "Help"
            if section in sections:
                sections[section].setContents(bytestring)
            else:
                hdadef.addSection(section, bytestring)
示例#4
0
    def content(self, path, encoding="utf8"):
        hdadef = self._path_to_hdadef(path)
        if not hdadef or self._asset_is_hidden(hdadef):
            raise stores.ResourceNotFoundError(path)
        info = api.path_to_components(path)

        if info.section:
            content = hdadef.sections()[info.section].contents()
        else:
            content = hdadef.embeddedHelp()

        if encoding and isinstance(content, compat.bytes_type):
            content = content.decode(encoding)

        return content