Treat addfile arguments as glob patterns.
This commit is contained in:
parent
f29677d4e0
commit
261faf66ae
1 changed files with 13 additions and 12 deletions
25
epubfile.py
25
epubfile.py
|
@ -1222,18 +1222,19 @@ def random_string(length, characters=string.ascii_lowercase):
|
||||||
def addfile_argparse(args):
|
def addfile_argparse(args):
|
||||||
book = Epub.open(args.epub)
|
book = Epub.open(args.epub)
|
||||||
|
|
||||||
for file in args.files:
|
for pattern in args.files:
|
||||||
print(f'Adding file {file}.')
|
for file in glob.glob(pattern):
|
||||||
file = pathclass.Path(file)
|
print(f'Adding file {file}.')
|
||||||
try:
|
file = pathclass.Path(file)
|
||||||
book.easy_add_file(file)
|
try:
|
||||||
except (IDExists, FileExists) as exc:
|
book.easy_add_file(file)
|
||||||
rand_suffix = random_string(3, string.digits)
|
except (IDExists, FileExists) as exc:
|
||||||
base = file.replace_extension('').basename
|
rand_suffix = random_string(3, string.digits)
|
||||||
id = f'{base}_{rand_suffix}'
|
base = file.replace_extension('').basename
|
||||||
basename = f'{base}_{rand_suffix}{file.dot_extension}'
|
id = f'{base}_{rand_suffix}'
|
||||||
content = open(file.absolute_path, 'rb').read()
|
basename = f'{base}_{rand_suffix}{file.dot_extension}'
|
||||||
book.add_file(id, basename, content)
|
content = open(file.absolute_path, 'rb').read()
|
||||||
|
book.add_file(id, basename, content)
|
||||||
|
|
||||||
book.move_nav_to_end()
|
book.move_nav_to_end()
|
||||||
book.save(args.epub)
|
book.save(args.epub)
|
||||||
|
|
Loading…
Reference in a new issue