def test_directory(): assert paths.directory("/") == "/" assert paths.directory("/a/b/") == "/a/b/" assert paths.directory("/a/b/c") == "/a/b/" assert paths.directory("a") == "" assert paths.directory("a/b") == "a/"
def checkpoints(self, path): cachestore = self.cachestore dirpath = paths.directory(path) cpdirpath = CHECKPOINT_DIR + dirpath if cachestore.exists(cpdirpath): names = cachestore.list_dir(cpdirpath) else: return [] cps = [] for name in names: if not name.endswith(CHECKPOINT_EXT): continue basename = name[:0 - len(CHECKPOINT_EXT)] fname, userid, cpid = basename.rsplit(".", 2) if userid != self.userid: continue cppath = paths.join(cpdirpath, name) fpath = paths.join(dirpath, fname) if fpath != path: continue cps.append({ "path": cppath, "modified": cachestore.last_modified(cppath), "id": cpid, }) cps.sort(key=lambda d: d["modified"]) return cps
def save_checkpoint(self, path, content, encoding="utf8"): self.store.write_file(path, content.encode(encoding)) cppath = self._checkpoint_path(path) cpdir = paths.directory(cppath) if not self.cachestore.exists(cpdir): self.cachestore.make_dir(cpdir) self.cachestore.write_file(cppath, content.encode(encoding)) asp = self._autosave_path(path) if self.cachestore.exists(asp): self.cachestore.delete(asp)
def _get_parent_path(pages, path, block): # Find the path to the parent document attrs = block.get("attrs", {}) if "parent" in attrs: # If the author specified a parent, use that parent = attrs.get("parent") parentpath = pages.source_path(paths.join(path, parent)) elif pages.is_index_page(path): # If this is an index page, assume its parent is the _index page of # the parent directory parentpath = Parents._find_ancestor(pages, paths.parent(path)) else: # Assume the parent is the _index page for this directory parentpath = Parents._find_ancestor(pages, paths.directory(path)) return parentpath
def autosave(self, path, content): aspath = self._autosave_path(path) asdir = paths.directory(aspath) if not self.cachestore.exists(asdir): self.cachestore.make_dir(asdir) self.cachestore.write_file(aspath, content.encode("utf8"))