]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
gen-sitemap: exclude uninteresting directories
authorOleg Broytman <phd@phdru.name>
Sun, 15 Mar 2015 20:30:18 +0000 (23:30 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Dec 2015 15:54:10 +0000 (18:54 +0300)
gen-sitemap
gen-sitemap.py

index c78fcd9b678a67b1c7dd7e053c67bd6a6e5a620b..9eba5ef76f2e217602b32b49fe22f441138c462d 100755 (executable)
@@ -1,2 +1,8 @@
 #! /bin/sh
-exec ./gen-sitemap.py ../htdocs/phdru.name
+exec ./gen-sitemap.py \
+   -x /Bookmarks/split \
+   -x /Graphics \
+   -x /Russian/blog/\* \
+   -x /Software/Python/\* \
+   -x /Software/dotfiles/\* \
+   ../htdocs/phdru.name
index d57d42230f4721c19d891f3749c8f2e1fd1c50b6..1afe424131947fac5bd56bb175d6ab734661fb71 100755 (executable)
@@ -5,17 +5,31 @@ from fnmatch import fnmatch
 import os
 
 parser = argparse.ArgumentParser(description='Generate sitemap')
+parser.add_argument('-x', '--exclude', action='append',
+                    help='exclude directories (pattern)')
 parser.add_argument('root_dir', help='Root dicrectory')
 args = parser.parse_args()
 
+exclude = []
+for pat in args.exclude:
+    exclude.append(pat)
+    if not pat.endswith('/*'):
+        exclude.append(pat + '/*')
+
 os.chdir(args.root_dir)
 fullpath = os.getcwd()
 fp_len = len(fullpath)
 
 for dirpath, dirs, files in sorted(os.walk(fullpath)):
-    dirpath = dirpath[fp_len:]
-    if not dirpath:
-        continue
-    parts = dirpath.split('/')
-    level = len(parts) - 2
-    print '    ' * level + parts[-1]
+    try:
+        dirpath = dirpath[fp_len:]
+        if not dirpath:
+            continue
+        for pat in exclude:
+            if fnmatch(dirpath, pat):
+                raise StopIteration
+        parts = dirpath.split('/')
+        level = len(parts) - 2
+        print '    ' * level + parts[-1]
+    except StopIteration:
+        pass