(Arne Babenhauserheide)
2011-11-23: write .statichgrepo, print.css and screen.css only if they were write .statichgrepo, print.css and screen.css only if they were changed.
diff --git a/site.py b/site.py
--- a/site.py
+++ b/site.py
@@ -258,6 +258,20 @@ 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."""
@@ -279,16 +293,18 @@ def parsesite(ui, repo, target, **opts):
# first the stylesheets
screenstyle = opts["screenstyle"]
- if screenstyle:
- shutil.copyfile(screenstyle, join(target, "style.css"))
- else:
+ screenfile = join(target, "style.css")
+ if screenstyle and not samefilecontent(screenstyle, screenfile):
+ shutil.copyfile(screenstyle, screenfile)
+ elif not contentequals(screenfile,templates["screenstyle"]):
with open(join(target, "style.css"), "w") as f:
f.write(templates["screenstyle"])
printstyle = opts["printstyle"]
- if printstyle:
- shutil.copyfile(printstyle, join(target, "print.css"))
- else:
- with open(join(target, "print.css"), "w") as f:
+ printfile = join(target, "print.css")
+ if printstyle and not samefilecontent(printstyle, printfile):
+ shutil.copyfile(printstyle, printfile)
+ elif not contentequals(printfile, templates["printstyle"]):
+ with open(printfile, "w") as f:
f.write(templates["printstyle"])
# then the overview