git » git-arr » commit c303c30

Fix the "--only" option

author Alberto Bertogli
2012-11-26 23:55:40 UTC
committer Alberto Bertogli
2013-03-09 23:23:52 UTC
parent 9ec2bde5c45c64f7fac432dbd3f23a1883d2b594

Fix the "--only" option

This patch fixes the --only option, and makes it avoid generating the
top-level index so we don't get a broken one with only the specified
repositories.

The intention is that this option is used in hooks to update the views after a
commit or push.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

git-arr +9 -5

diff --git a/git-arr b/git-arr
index 3a44427..17f681f 100755
--- a/git-arr
+++ b/git-arr
@@ -247,7 +247,7 @@ def static(path):
 # Static HTML generation
 #
 
-def generate(output):
+def generate(output, skip_index = False):
     """Generate static html to the output directory."""
     def write_to(path, func_or_str, args = (), mtime = None):
         path = output + '/' + path
@@ -323,7 +323,8 @@ def generate(output):
                             (str(r.name), str(bn), oname.raw),
                         tree, (r, bn, oname.url), mtime)
 
-    write_to('index.html', index())
+    if not skip_index:
+        write_to('index.html', index())
 
     # We can't call static() because it relies on HTTP headers.
     read_f = lambda f: open(f).read()
@@ -384,6 +385,7 @@ def main():
     parser.add_option('-o', '--output', metavar = 'DIR',
             help = 'output directory (for generate)')
     parser.add_option('', '--only', metavar = 'REPO', action = 'append',
+            default = [],
             help = 'generate/serve only this repository')
     opts, args = parser.parse_args()
 
@@ -400,15 +402,17 @@ def main():
         parser.error('Must specify an action (serve|generate)')
 
     if opts.only:
-        global repos
-        repos = [ r for r in repos if r.name in opts.only ]
+        for rname in list(repos.keys()):
+            if rname not in opts.only:
+                del repos[rname]
 
     if args[0] == 'serve':
         bottle.run(host = 'localhost', port = 8008, reloader = True)
     elif args[0] == 'generate':
         if not opts.output:
             parser.error('Must specify --output')
-        generate(output = opts.output)
+        generate(output = opts.output,
+                skip_index = len(opts.only) > 0)
     else:
         parser.error('Unknown action %s' % args[0])