verifying that the input file exists

This commit is contained in:
benton 2021-07-21 18:14:42 -05:00
parent 3e20ca84a2
commit 9cee504f49

13
knock
View file

@ -1,11 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os, sys, argparse, subprocess
import argparse
from pathlib import Path from pathlib import Path
import subprocess
parser = argparse.ArgumentParser(prog="knock", description='Convert an ACSM file to a DRM-free ePub file') parser = argparse.ArgumentParser(prog='knock', description='Convert an ACSM file to a DRM-free EPUB file')
parser.add_argument('acsm_file', metavar='file', type=str, help='the ACSM file to convert') parser.add_argument('acsm_file', metavar='file', type=str, help='the ACSM file to convert')
args = parser.parse_args() args = parser.parse_args()
@ -16,6 +14,9 @@ args.epub_file = args.acsm_file.with_suffix('.epub')
args.adobe_dir = Path('~/.config/knock').expanduser() args.adobe_dir = Path('~/.config/knock').expanduser()
args.activation_file = args.adobe_dir.joinpath('activation.xml') args.activation_file = args.adobe_dir.joinpath('activation.xml')
if not args.acsm_file.exists():
raise Exception(f'{str(args.acsm_file)} does not exist.')
if not args.adobe_dir.exists(): if not args.adobe_dir.exists():
raise Exception('This device is not registered') raise Exception('This device is not registered')
@ -41,5 +42,5 @@ subprocess.check_output([
args.drm_file.unlink() args.drm_file.unlink()
print(f'\nThe DRM-free ePub file now exists at {str(args.epub_file)}!') print(f'\nThe DRM-free EPUB file now exists at {str(args.epub_file)}!')
print(f'Once you make sure the ePub file is readable, you can delete {str(args.acsm_file)}.') print(f'Once you make sure the EPUB file is readable, you can delete {str(args.acsm_file)}.')