コード例 #1
0
ファイル: hstores.py プロジェクト: mchaput/bookish
 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
ファイル: hstores.py プロジェクト: mchaput/bookish
    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
ファイル: hstores.py プロジェクト: mchaput/bookish
    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
ファイル: hstores.py プロジェクト: mchaput/bookish
    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