#! /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
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