mirror of
https://github.com/ciromattia/kcc
synced 2026-10-20 16:32:31 +00:00
fix minor bugs in getOutputFilename
This commit is contained in:
@@ -1084,32 +1084,38 @@ def getOutputFilename(srcpath, wantedname, ext, tomenumber):
|
|||||||
ext = '.epub'
|
ext = '.epub'
|
||||||
else:
|
else:
|
||||||
ext = '.kepub.epub'
|
ext = '.kepub.epub'
|
||||||
if wantedname is not None:
|
|
||||||
|
custom_output_directory = False
|
||||||
|
if wantedname:
|
||||||
wanted_root, wanted_ext = os.path.splitext(wantedname)
|
wanted_root, wanted_ext = os.path.splitext(wantedname)
|
||||||
|
# so you could have an output folder with . in the filename
|
||||||
if not options.folder_output and wantedname.endswith(ext):
|
if not options.folder_output and wantedname.endswith(ext):
|
||||||
filename = os.path.abspath(wantedname)
|
filename = os.path.abspath(wantedname)
|
||||||
elif wanted_ext == '.mobi' and ext == '.epub':
|
elif wanted_ext == '.mobi' and ext == '.epub':
|
||||||
filename = os.path.abspath(wanted_root + ext)
|
filename = os.path.abspath(wanted_root + ext)
|
||||||
# output directory
|
|
||||||
else:
|
else:
|
||||||
|
custom_output_directory = True
|
||||||
abs_path = os.path.abspath(options.output)
|
abs_path = os.path.abspath(options.output)
|
||||||
if not os.path.exists(abs_path):
|
if not os.path.exists(abs_path):
|
||||||
os.mkdir(abs_path)
|
os.mkdir(abs_path)
|
||||||
if source_path.is_file():
|
|
||||||
filename = os.path.join(os.path.abspath(options.output), source_path.stem + tomenumber + ext)
|
if wantedname is None or custom_output_directory:
|
||||||
else:
|
|
||||||
filename = os.path.join(os.path.abspath(options.output), source_path.name + tomenumber + ext)
|
|
||||||
else:
|
|
||||||
if 'Ko' in options.profile and options.format == 'EPUB':
|
if 'Ko' in options.profile and options.format == 'EPUB':
|
||||||
if source_path.is_file():
|
if source_path.is_file():
|
||||||
name = KOBO_TOUCH_DRIVER_REGEX.sub('_', source_path.stem) + tomenumber + ext
|
name = KOBO_TOUCH_DRIVER_REGEX.sub('_', source_path.stem) + tomenumber + ext
|
||||||
else:
|
else:
|
||||||
name = KOBO_TOUCH_DRIVER_REGEX.sub('_', source_path.name) + tomenumber + ext
|
name = KOBO_TOUCH_DRIVER_REGEX.sub('_', source_path.name) + tomenumber + ext
|
||||||
filename = source_path.with_name(name)
|
|
||||||
elif os.path.isdir(srcpath):
|
|
||||||
filename = srcpath + tomenumber + ext
|
|
||||||
else:
|
else:
|
||||||
filename = os.path.splitext(srcpath)[0] + tomenumber + ext
|
if source_path.is_file():
|
||||||
|
name = source_path.stem + tomenumber + ext
|
||||||
|
else:
|
||||||
|
name = source_path.name + tomenumber + ext
|
||||||
|
|
||||||
|
if custom_output_directory:
|
||||||
|
filename = os.path.join(os.path.abspath(options.output), name)
|
||||||
|
else:
|
||||||
|
filename = source_path.with_name(name)
|
||||||
|
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
counter = 0
|
counter = 0
|
||||||
basename = os.path.splitext(filename)[0]
|
basename = os.path.splitext(filename)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user