From 261faf66ae9cb8949e96a68312f82d9d7cdc4e4d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 30 Dec 2019 13:50:05 -0800 Subject: [PATCH] Treat addfile arguments as glob patterns. --- epubfile.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/epubfile.py b/epubfile.py index 6dd0c93..7434293 100644 --- a/epubfile.py +++ b/epubfile.py @@ -1222,18 +1222,19 @@ def random_string(length, characters=string.ascii_lowercase): def addfile_argparse(args): book = Epub.open(args.epub) - for file in args.files: - print(f'Adding file {file}.') - file = pathclass.Path(file) - try: - book.easy_add_file(file) - except (IDExists, FileExists) as exc: - rand_suffix = random_string(3, string.digits) - base = file.replace_extension('').basename - id = f'{base}_{rand_suffix}' - basename = f'{base}_{rand_suffix}{file.dot_extension}' - content = open(file.absolute_path, 'rb').read() - book.add_file(id, basename, content) + for pattern in args.files: + for file in glob.glob(pattern): + print(f'Adding file {file}.') + file = pathclass.Path(file) + try: + book.easy_add_file(file) + except (IDExists, FileExists) as exc: + rand_suffix = random_string(3, string.digits) + base = file.replace_extension('').basename + id = f'{base}_{rand_suffix}' + basename = f'{base}_{rand_suffix}{file.dot_extension}' + content = open(file.absolute_path, 'rb').read() + book.add_file(id, basename, content) book.move_nav_to_end() book.save(args.epub)