From d5335f321286b1e5eafa74efc0d4c16434b4caa5 Mon Sep 17 00:00:00 2001 From: RRA Date: Sun, 15 Sep 2019 13:58:00 +0200 Subject: [PATCH] added possibility to exclude directories with --exclude-directory option --- distribusi/cli.py | 6 ++++++ distribusi/distribusi.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/distribusi/cli.py b/distribusi/cli.py index 93d33d1..f8b49d6 100644 --- a/distribusi/cli.py +++ b/distribusi/cli.py @@ -59,6 +59,12 @@ def build_argparser(): help="Removes previously made index.html. Warning: this will remove ALL index.html files in the directories listed", action="store_true") + parser.add_argument( + '-e', + '--exclude-directory', + help="Exclude one or multiple directories from indexing", + nargs="*") + return parser diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py index db00db8..ae314e9 100644 --- a/distribusi/distribusi.py +++ b/distribusi/distribusi.py @@ -70,8 +70,17 @@ def div(args, type_, subtype, tag, name): def distribusify(args, directory): # noqa for root, dirs, files in os.walk(directory): + + if args.exclude_directory: + if args.verbose: + print('Excluding directory:', ", ".join(args.exclude_directory)) + dirs[:] = [d for d in dirs if d not in args.exclude_directory] + + + if not args.remove_index: html = [] + if args.verbose: print('Generating directory listing for', root) @@ -147,6 +156,7 @@ def distribusify(args, directory): # noqa if not args.no_template: f.write(html_footer) + if args.remove_index: index = os.path.join(root, 'index.html') if 'index.html' in files: