From bb9c32cadb93e6b46e64064ccce8e4560fb9bec2 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 28 Oct 2020 14:50:55 -0700 Subject: [PATCH] Add command 'new' to create empty book file. --- epubfile.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/epubfile.py b/epubfile.py index df3e0c1..b94709e 100644 --- a/epubfile.py +++ b/epubfile.py @@ -1481,6 +1481,17 @@ merge: Overwrite the output file without prompting. '''.strip(), +new=''' +new: + Create a new, blank epub file. + + > epubfile.py new book.epub + + flags: + -y | --autoyes: + Overwrite the file without prompting. +'''.strip(), + normalize=''' normalize: Rename files and directories in the book to match a common structure. @@ -1694,6 +1705,13 @@ def merge_argparse(args): number_headerfile=args.number_headerfile, ) +def new_book_argparse(args): + if os.path.exists(args.epub): + if not (args.autoyes or getpermission.getpermission(f'Overwrite {args.epub}?')): + raise ValueError(f'{args.epub} exists.') + book = Epub.new() + book.save(args.epub) + def normalize_argparse(args): epubs = [epub for pattern in args.epubs for epub in winglob.glob(pattern)] for epub in epubs: @@ -1808,6 +1826,11 @@ def main(argv): p_merge.add_argument('-y', '--autoyes', dest='autoyes', action='store_true') p_merge.set_defaults(func=merge_argparse) + p_new = subparsers.add_parser('new') + p_new.add_argument('epub') + p_new.add_argument('-y', '--autoyes', dest='autoyes', action='store_true') + p_new.set_defaults(func=new_book_argparse) + p_normalize = subparsers.add_parser('normalize') p_normalize.add_argument('epubs', nargs='+', default=[]) p_normalize.set_defaults(func=normalize_argparse)