git-arr: Always generate the top level index

The top level index contains a "last updated" field, but it doesn't get
updated if using the --only option, which is very common in post-update hooks,
and causes the date to be stale.

This patch fixes that by always generating the top level index, even if --only
was given.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
Alberto Bertogli 2015-11-07 11:43:01 +00:00
parent 88dd6fab76
commit c4e6484bb0

18
git-arr

@ -284,7 +284,7 @@ def is_404(e):
else: else:
return e.status_code == 404 return e.status_code == 404
def generate(output, skip_index = False): def generate(output, only = None):
"""Generate static html to the output directory.""" """Generate static html to the output directory."""
def write_to(path, func_or_str, args = (), mtime = None): def write_to(path, func_or_str, args = (), mtime = None):
path = output + '/' + path path = output + '/' + path
@ -361,7 +361,7 @@ def generate(output, skip_index = False):
(str(r.name), str(bn), oname.raw), (str(r.name), str(bn), oname.raw),
tree, (r, bn, oname.url), mtime) tree, (r, bn, oname.url), mtime)
if not skip_index: # Always generate the index, to keep the "last updated" time fresh.
write_to('index.html', index()) write_to('index.html', index())
# We can't call static() because it relies on HTTP headers. # We can't call static() because it relies on HTTP headers.
@ -373,7 +373,11 @@ def generate(output, skip_index = False):
write_to('static/syntax.css', read_f, [static_path + '/syntax.css'], write_to('static/syntax.css', read_f, [static_path + '/syntax.css'],
os.stat(static_path + '/syntax.css').st_mtime) os.stat(static_path + '/syntax.css').st_mtime)
for r in sorted(repos.values(), key = lambda r: r.name): rs = sorted(repos.values(), key = lambda r: r.name)
if only:
rs = [r for r in rs if r.name in only]
for r in rs:
write_to('r/%s/index.html' % r.name, summary(r)) write_to('r/%s/index.html' % r.name, summary(r))
for bn in r.branch_names(): for bn in r.branch_names():
commit_count = 0 commit_count = 0
@ -441,18 +445,12 @@ def main():
if not args: if not args:
parser.error('Must specify an action (serve|generate)') parser.error('Must specify an action (serve|generate)')
if opts.only:
for rname in list(repos.keys()):
if rname not in opts.only:
del repos[rname]
if args[0] == 'serve': if args[0] == 'serve':
bottle.run(host = 'localhost', port = 8008, reloader = True) bottle.run(host = 'localhost', port = 8008, reloader = True)
elif args[0] == 'generate': elif args[0] == 'generate':
if not opts.output: if not opts.output:
parser.error('Must specify --output') parser.error('Must specify --output')
generate(output = opts.output, generate(output = opts.output, only = opts.only)
skip_index = len(opts.only) > 0)
else: else:
parser.error('Unknown action %s' % args[0]) parser.error('Unknown action %s' % args[0])