当前位置: 首页>>代码示例>>Python>>正文


Python Book.addImageFiles方法代码示例

本文整理汇总了Python中book.Book.addImageFiles方法的典型用法代码示例。如果您正苦于以下问题:Python Book.addImageFiles方法的具体用法?Python Book.addImageFiles怎么用?Python Book.addImageFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在book.Book的用法示例。


在下文中一共展示了Book.addImageFiles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import addImageFiles [as 别名]
	def convert(outputMgr, filePath, outDir, Device, verbose):
		listDir = []
		isDir = os.path.isdir(filePath)

		if (isDir):
			title = os.path.basename(filePath)
			listDir = os.listdir(filePath)
		else:
			listDir.append(filePath)
			title = 'Pictures'
			
		
		outputBook = Book()
		outputBook.DefaultDevice = Device
		
		if (title == None or title == ""):
			title = 'Pictures'
		
		files = []
		directories = []
		compressedFiles = []
		

		# Recursively loop through the filesystem
		for filename in listDir:
			if (isDir):
				filename = os.path.join(filePath, filename)
			if (verbose):
				print("Pre-Processing %s." % filename)
			if (os.path.isdir(str(filename))):	
				directories.append(filename)
			else:
				if (outputBook.isImageFile(filename)):
					if (verbose):
						print("ConvertPkg: Found Image %s" % filename)
					files.append(filename)
				else:
					imageExts = ['.cbz', '.zip']
					
					if os.path.splitext(filename)[1].lower() in imageExts:
						compressedFiles.append(filename)
		
				
		if (len(files) > 0):
			files.sort()
			outputBook.addImageFiles(files)
			outputBook.title = title
			bookConvert = BookConvert(outputBook, outputMgr, os.path.abspath(outDir), verbose)
			bookConvert.Export()			
		
		outDir = os.path.join(outDir, title)	
			
		for directory in directories:
			if(verbose):
				print("Converting %s", directory)
			convertFile.convert(outputMgr, directory, outDir, Device, verbose)
		
		for compressedFile in compressedFiles:
			try:
				if(verbose):
					print("Uncompressing %s" % compressedFile)
				z = zipfile.ZipFile(compressedFile, 'r')
			except:
				if (verbose):
					print("Failed to convert %s. Check if it is a valid zipFile." % compressedFile)
				continue
				
			if (isDir):
				temp_dir = os.path.join(filePath, os.path.splitext(os.path.basename(compressedFile))[0])
			else:
				temp_dir = os.path.splitext(compressedFile)[0]
			
			try:			
				os.mkdir(temp_dir)
			except:
				continue
				
			for name in z.namelist():
				tempName = os.path.join(temp_dir, name)
				convertFile.extract_from_zip(name, tempName, z)
			z.close
			convertFile.convert(outputMgr, temp_dir, outDir, Device, verbose)
			if os.path.exists(temp_dir):
				shutil.rmtree(temp_dir)
开发者ID:Kassino,项目名称:manga_downloader,代码行数:86,代码来源:ConvertFile.py


注:本文中的book.Book.addImageFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。