MCPcopy
hub / github.com/ciromattia/kcc / getOutputFilename

Function getOutputFilename

kindlecomicconverter/comic2ebook.py:1051–1100  ·  view source on GitHub ↗
(srcpath, wantedname, ext, tomenumber)

Source from the content-addressed store, hash-verified

1049
1050
1051def getOutputFilename(srcpath, wantedname, ext, tomenumber):
1052 source_path = Path(srcpath)
1053 if srcpath[-1] == os.path.sep:
1054 srcpath = srcpath[:-1]
1055 if 'Ko' in options.profile and options.format == 'EPUB':
1056 if options.noKepub:
1057 # Just use normal epub extension if no_kepub option is true
1058 ext = '.epub'
1059 else:
1060 ext = '.kepub.epub'
1061 if wantedname is not None:
1062 wanted_root, wanted_ext = os.path.splitext(wantedname)
1063 if wantedname.endswith(ext):
1064 filename = os.path.abspath(wantedname)
1065 elif wanted_ext == '.mobi' and ext == '.epub':
1066 filename = os.path.abspath(wanted_root + ext)
1067 # output directory
1068 else:
1069 abs_path = os.path.abspath(options.output)
1070 if not os.path.exists(abs_path):
1071 os.mkdir(abs_path)
1072 if source_path.is_file():
1073 filename = os.path.join(os.path.abspath(options.output), source_path.stem + tomenumber + ext)
1074 else:
1075 filename = os.path.join(os.path.abspath(options.output), source_path.name + tomenumber + ext)
1076 elif os.path.isdir(srcpath):
1077 filename = srcpath + tomenumber + ext
1078 else:
1079 if 'Ko' in options.profile and options.format == 'EPUB':
1080 if source_path.is_file():
1081 name = re.sub(r'\W+', '_', source_path.stem) + tomenumber + ext
1082 else:
1083 name = re.sub(r'\W+', '_', source_path.name) + tomenumber + ext
1084 filename = source_path.with_name(name)
1085 else:
1086 filename = os.path.splitext(srcpath)[0] + tomenumber + ext
1087 if os.path.isfile(filename):
1088 counter = 0
1089 basename = os.path.splitext(filename)[0]
1090 while os.path.isfile(basename + '_kcc' + str(counter) + ext):
1091 counter += 1
1092 filename = basename + '_kcc' + str(counter) + ext
1093 elif options.format == 'MOBI' and ext == '.epub':
1094 counter = 0
1095 basename = os.path.splitext(filename)[0]
1096 if os.path.isfile(basename + '.mobi'):
1097 while os.path.isfile(basename + '_kcc' + str(counter) + '.mobi'):
1098 counter += 1
1099 filename = basename + '_kcc' + str(counter) + ext
1100 return filename
1101
1102
1103def getMetadata(path, originalpath):

Callers 2

buildPDFFunction · 0.85
makeBookFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected