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()) )
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("")
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)
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