(Arne Babenhauserheide)
2012-02-21: FIX: Fixed the breaking on not yet existing files at the right FIX: Fixed the breaking on not yet existing files at the right place: contentequals now returns False, when the file does not yet exist.
diff --git a/site.py b/site.py
--- a/site.py
+++ b/site.py
@@ -80,6 +80,8 @@ def contentequals(filepath, content):
with open(filepath) as f:
return f.read() == content
except OSError: return not content
+ except IOError: return False # file does not exist. Empty != not existing.
+ # TODO: check: return True if content is None?
def parsereadme(filepath):
"""Parse the readme file"""
@@ -168,8 +170,9 @@ def writeoverview(ui, repo, target, name
# finish the overview
overview += templates["foot"]
- if not contentequals(join(target, "index.html"), overview):
- with open(join(target, "index.html"), "w") as f:
+ indexfile = join(target, "index.html")
+ if not contentequals(indexfile, overview):
+ with open(indexfile, "w") as f:
f.write(overview)
def writelog(ui, repo, target, name):
@@ -354,14 +357,14 @@ def parsesite(ui, repo, target, **opts):
screenfile = join(target, "style.css")
if screenstyle and not samefilecontent(screenstyle, screenfile):
shutil.copyfile(screenstyle, screenfile)
- elif not isfile(screenfile) or not contentequals(screenfile,templates["screenstyle"]):
+ elif not contentequals(screenfile,templates["screenstyle"]):
with open(screenfile, "w") as f:
f.write(templates["screenstyle"])
printstyle = opts["printstyle"]
printfile = join(target, "print.css")
if printstyle and not samefilecontent(printstyle, printfile):
shutil.copyfile(printstyle, printfile)
- elif not isfile(printfile) or not contentequals(printfile, templates["printstyle"]):
+ elif not contentequals(printfile, templates["printstyle"]):
with open(printfile, "w") as f:
f.write(templates["printstyle"])