(Arne Babenhauserheide)
2011-10-06: Add the repo to the target and make sure it is up to date. Add the repo to the target and make sure it is up to date.
diff --git a/static.py b/static.py --- a/static.py +++ b/static.py @@ -35,6 +35,7 @@ without the interactivity). import os from os.path import join, isdir, isfile, basename import shutil +import mercurial import mercurial.cmdutil from mercurial import commands @@ -61,7 +62,7 @@ templates = { def parsereadme(filepath): """Parse the readme file""" with open(filepath) as r: - return r.read() + return "<pre>" + r.read() + "</pre>" def parsesite(ui, repo, target, **opts): @@ -79,7 +80,7 @@ def parsesite(ui, repo, target, **opts): if opts["name"]: name = opts["name"] - elif target: name = target + elif target != "static": name = target else: name = basename(repo.root) # first the stylesheets @@ -99,26 +100,48 @@ def parsesite(ui, repo, target, **opts): # then the overview overview = open(join(target, "index.html"), "w") overview.write(templates["head"].replace("REPO_NAME", name)) - # add a readme, if it exists # TODO: Parse different types of readme files + # 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"): - overview.write(parsereadme(f)) + readme = parsereadme(f) + overview.write( "\n".join(readme.splitlines()[:3])) + break # now add the 5 most recent log entries # divert all following ui output to a string, so we can just use standard functions ui.pushbuffer() commands.log(ui, repo, template="""<div style='float: right; padding-left: 0.5em'><em>({author|person})</em></div> -<p><strong> {date|shortdate}: <a href='commits/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span></p><p>{desc|escape}</p>""", date="", rev="0:0", user=ui.username()) +<p><strong> {date|shortdate}: <a href='commits/{node}.html'>{desc|strip|fill68|firstline}</a> <span style='font-size: xx-small'>{branches} {tags}</span></p><p>{desc|escape}</p>""", date="", rev="0", user=ui.username()) overview.write(ui.popbuffer()) + + # add the full readme + overview.write(readme) + # finish the overview overview.write(templates["foot"]) +def addrepo(ui, repo, target): + """Add the repo to the target and make sure it is up to date.""" + try: + commands.init(ui, dest=target) + except mercurial.error.RepoError, e: + # already exists + pass + commands.push(ui, repo, dest=target) def static(ui, repo, target=None, **opts): """Create a static copy of the repository and/or upload it to an FTP server.""" + if repo.root == target: + ui.warn("static target repo can’t be the current repo") + return # first: just create the site. + if target is None: target = "static" parsesite(ui, repo, target, **opts) + # add the hg repo to the static site + addrepo(ui, repo, target)