本文整理匯總了Python中book.Book.add_image_files方法的典型用法代碼示例。如果您正苦於以下問題:Python Book.add_image_files方法的具體用法?Python Book.add_image_files怎麽用?Python Book.add_image_files使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類book.Book
的用法示例。
在下文中一共展示了Book.add_image_files方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert
# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import add_image_files [as 別名]
def convert(output_mgr, file_path, out_dir, device, verbose):
kindle_dir = 'images' if device == 'Kindle 5' else 'Pictures'
list_dir = []
is_dir = os.path.isdir(file_path)
if is_dir:
title = os.path.basename(file_path)
list_dir = os.listdir(file_path)
else:
list_dir.append(file_path)
title = kindle_dir
output_book = Book()
output_book.device = device
if title is None or title == "":
title = kindle_dir
files = []
directories = []
compressed_files = []
# Recursively loop through the filesystem
for filename in list_dir:
if is_dir:
filename = os.path.join(file_path, filename)
if verbose:
print("Pre-Processing %s." % filename)
if os.path.isdir(str(filename)):
directories.append(filename)
else:
if output_book.is_image_file(filename):
if verbose:
print("ConvertPkg: Found Image %s" % filename)
files.append(filename)
else:
image_exts = ['.cbz', '.zip']
if os.path.splitext(filename)[1].lower() in image_exts:
compressed_files.append(filename)
if len(files) > 0:
files.sort()
output_book.add_image_files(files)
output_book.title = title
book_convert = BookConvert(output_book, output_mgr, os.path.abspath(out_dir), verbose)
book_convert.export()
out_dir = os.path.join(out_dir, title)
for directory in directories:
if verbose:
print("Converting %s", directory)
ConvertFile.convert(output_mgr, directory, out_dir, device, verbose)
for compressed_file in compressed_files:
try:
if verbose:
print("Uncompressing %s" % compressed_file)
z = zipfile.ZipFile(compressed_file, 'r')
except:
if verbose:
print("Failed to convert %s. Check if it is a valid zipFile." % compressed_file)
continue
if is_dir:
temp_dir = os.path.join(file_path, os.path.splitext(os.path.basename(compressed_file))[0])
else:
temp_dir = os.path.splitext(compressed_file)[0]
try:
os.mkdir(temp_dir)
except:
continue
for name in z.namelist():
temp_name = os.path.join(temp_dir, name)
ConvertFile.extract_from_zip(name, temp_name, z)
z.close()
ConvertFile.convert(output_mgr, temp_dir, out_dir, device, verbose)
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)