def write_page(self, name, content, message=None, create=False, username=None, email=None): """Write page to git repo :param name: Name of page. :param content: Content of page. :param message: Commit message. :param create: Perform git add operation? :param username: Commit Name. :param email: Commit Email. :return: Git commit sha1. """ cname = to_canonical(name) filename = cname_to_filename(cname) with open(self.path + "/" + filename, 'w') as f: f.write(content) if create: self.gittle.add(filename) if not message: message = "Updated %s" % name username, email = self._get_user(username, email) ret = self.gittle.commit(name=username, email=email, message=message, files=[filename]) cache.delete(cname) return ret
def write_page(self, name, content, message=None, create=False, username=None, email=None): def escape_repl(m): if m.group(1): return "```" + escape(m.group(1)) + "```" def unescape_repl(m): if m.group(1): return "```" + unescape(m.group(1)) + "```" cname = to_canonical(name) # prevents p tag from being added, we remove this later content = "<div>" + content + "</div>" content = re.sub(r"```(.*?)```", escape_repl, content, flags=re.DOTALL) tree = lxml.html.fromstring(content) cleaner = Cleaner(remove_unknown_tags=False, kill_tags=set(["style"]), safe_attrs_only=False) tree = cleaner.clean_html(tree) content = lxml.html.tostring(tree, encoding="utf-8", method="html") # remove added div tags content = content[5:-6] # FIXME this is for block quotes, doesn't work for double ">" content = re.sub(r"(\n>)", "\n>", content) content = re.sub(r"(^>)", ">", content) # Handlebars partial ">" content = re.sub(r"\{\{>(.*?)\}\}", r"{{>\1}}", content) # Handlebars, allow {{}} inside HTML links content = content.replace("%7B", "{") content = content.replace("%7D", "}") content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL) filename = self.cname_to_filename(cname) with open(self.path + "/" + filename, "w") as f: f.write(content) if create: self.repo.add(filename) if not message: message = "Updated %s" % name if not username: username = self.default_committer_name if not email: email = self.default_committer_email ret = self.repo.commit(name=username, email=email, message=message, files=[filename]) cache.delete(cname) return ret
def _invalidate_cache(self, save_history=None): cache.delete(self._cache_key('data')) if save_history: if not save_history[0].get('_cache_missing'): save_history = [{'_cache_missing': True}] + save_history cache.set(self._cache_key('history'), save_history) else: cache.delete(self._cache_key('history'))