(Arne Babenhauserheide)
2011-11-23: Only write .statichgrepo print.css style.css and index.html when Only write .statichgrepo print.css style.css and index.html when their data changed.
diff --git a/.bugs/bugs b/.bugs/bugs --- a/.bugs/bugs +++ b/.bugs/bugs @@ -4,7 +4,7 @@ Add a list of branches, heads and tags t if b is used: a bugtracker: issue/<id>/<name> | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:1d631d51ff06b3bdca50e21da3d6a00bcb801c85, time:1319147632.52 get mtimes from the repo instead of querying the FTP server. We know which files were changed. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:29210503551d0eafca67dda8d6fffbd40bf837dc, time:1319213074.57 FIX: revision 0 is omitted: change that :) | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:29396f1753e45b5a37ffa0ce04d96c876d6b6722, time:1319209563.68 -only write .statichgrepo print.css style.css and index.html when their data changed \(or \-\-force\) → read them and compare the contents. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:4f02149269a60fca85aa040116b2789d98c906f2, time:1319212903.98 +only write .statichgrepo print.css style.css and index.html when their data changed \(or \-\-force\) → read them and compare the contents. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:4f02149269a60fca85aa040116b2789d98c906f2, time:1319212903.98 add proper caching of every ftp directory listing. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:750692931106d78ffc38c1ed63013c4dac4099dd, time:1319175393.07 fork-/clone-info for each entry in [paths] with its incoming data (if it has some): | owner:, open:True, id:8621575e4016752e8987c8b294dfa9166f77eff3, time:1319147671.39 More complex Readme parsing. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:94fbade896adbf6f696cfdb331021437dff3f30e, time:1319147671.39 diff --git a/site.py b/site.py --- a/site.py +++ b/site.py @@ -66,6 +66,21 @@ templates = { _indexregexp = re.compile("^\\.*index.html$") +def samefilecontent(filepath1, filepath2): + """Check if the content of the two referenced files is equal.""" + try: + with open(filepath1) as f1: + with open(filepath2) as f2: + return f1.read() == f2.read() + except OSError: return False + +def contentequals(filepath, content): + """Check if the files content is content.""" + try: + with open(filepath) as f: + return f.read() == content + except OSError: return not content + def parsereadme(filepath): """Parse the readme file""" with open(filepath) as r: @@ -74,35 +89,38 @@ def parsereadme(filepath): def writeoverview(ui, repo, target, name): """Create the overview page""" - overview = open(join(target, "index.html"), "w") - overview.write(templates["head"].replace("{reponame}", name).replace("{title}", name)) + overview = "" + overview += templates["head"].replace("{reponame}", name).replace("{title}", name) # add a short identifier from the first line of the readme, if it # exists # TODO: Parse different types of readme files readme = name for f in os.listdir(repo.root): if f.lower().startswith("readme"): readme = parsereadme(f) - overview.write( "\n".join(readme.splitlines()[:3])) + overview += "\n".join(readme.splitlines()[:3]) break # now the links to the log and the files. - overview.write("<p><a href='commits'>changelog</a> | <a href='src/" + repo["tip"].hex() + "/'>files</a></p>") + overview += "<p><a href='commits'>changelog</a> | <a href='src/" + repo["tip"].hex() + "/'>files</a></p>" # now add the 5 most recent log entries # divert all following ui output to a string, so we can just use standard functions - overview.write("<h2>Changes (<a href='commits'>full changelog</a>)</h2>") + overview += "<h2>Changes (<a href='commits'>full changelog</a>)</h2>" ui.pushbuffer() t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False) t.use_template("""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div><strong> {date|shortdate}: <a href='commit/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags} {bookmarks}</span><p>{desc|escape}</p>""") for c in range(1, min(len(repo.changelog), 5)): ctx = repo.changectx(str(-c)) t.show(ctx) - overview.write(ui.popbuffer()) + overview += ui.popbuffer() # add the full readme - overview.write("<h2>"+_("Readme")+"</h2>") - overview.write(readme) + overview += "<h2>"+_("Readme")+"</h2>" + overview += readme # finish the overview - overview.write(templates["foot"]) + overview += templates["foot"] + if not contentequals(join(target, "index.html"), overview): + with open(join(target, "index.html"), "w") as f: + f.write(overview) def writelog(ui, repo, target, name): """Write the full changelog, in steps of 100.""" @@ -258,21 +276,6 @@ def writesourcetree(ui, repo, target, na f.write(createindex(target, ctx)) f.write(templates["foot"].replace("{reponame}", "<a href='../../'>"+name+"</a>")) -def samefilecontent(filepath1, filepath2): - """Check if the content of the two referenced files is equal.""" - try: - with open(filepath1) as f1: - with open(filepath2) as f2: - return f1.read() == f2.read() - except OSError: return False - -def contentequals(filepath, content): - """Check if the files content is content.""" - try: - with open(filepath) as f: - return f.read() == content - except OSError: return not content - def parsesite(ui, repo, target, **opts): """Create the static folder.""" idfile = join(target, _staticidentifier)