mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 17:56:30 +00:00
Work on folders - break code
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
# executable are found
|
# executable are found
|
||||||
# - Improve error reporting
|
# - Improve error reporting
|
||||||
|
|
||||||
__version__ = '2.10'
|
__version__ = '2.3'
|
||||||
__license__ = 'ISC'
|
__license__ = 'ISC'
|
||||||
__copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>'
|
__copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
@@ -49,7 +49,15 @@ import image, cbxarchive, pdfjpgextract
|
|||||||
def buildHTML(path,file):
|
def buildHTML(path,file):
|
||||||
filename = getImageFileName(file)
|
filename = getImageFileName(file)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
htmlfile = os.path.join(path.replace('/Images','/Text'),filename[0] + '.html')
|
postfix = ''
|
||||||
|
head = path
|
||||||
|
while True:
|
||||||
|
head, tail = os.path.split(head)
|
||||||
|
if tail == 'Images':
|
||||||
|
htmlpath = os.path.join(head,'Text')
|
||||||
|
break
|
||||||
|
postfix = tail + "/" + postfix
|
||||||
|
htmlfile = os.path.join(htmlpath,filename[0] + '.html')
|
||||||
f = open(htmlfile, "w")
|
f = open(htmlfile, "w")
|
||||||
f.writelines(["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n",
|
f.writelines(["<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n",
|
||||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
|
||||||
@@ -58,7 +66,7 @@ def buildHTML(path,file):
|
|||||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n",
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n",
|
||||||
"</head>\n",
|
"</head>\n",
|
||||||
"<body>\n",
|
"<body>\n",
|
||||||
"<div><img src=\"../Images/",file,"\" alt=\"",file,"\" /></div>\n",
|
"<div><img src=\"../Images/",postfix,file,"\" alt=\"",file,"\" /></div>\n",
|
||||||
"</body>\n",
|
"</body>\n",
|
||||||
"</html>"
|
"</html>"
|
||||||
])
|
])
|
||||||
@@ -66,7 +74,7 @@ def buildHTML(path,file):
|
|||||||
return path,file
|
return path,file
|
||||||
|
|
||||||
def buildNCX(dstdir, title, chapters):
|
def buildNCX(dstdir, title, chapters):
|
||||||
ncxfile = dstdir + '/OEBPS/toc.ncx'
|
ncxfile = os.path.join(dstdir,'OEBPS','toc.ncx')
|
||||||
f = open(ncxfile, "w")
|
f = open(ncxfile, "w")
|
||||||
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
|
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
"<!DOCTYPE ncx PUBLIC \"-//NISO//DTD ncx 2005-1//EN\" \"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">\n",
|
"<!DOCTYPE ncx PUBLIC \"-//NISO//DTD ncx 2005-1//EN\" \"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">\n",
|
||||||
@@ -81,7 +89,7 @@ def buildNCX(dstdir, title, chapters):
|
|||||||
"<navMap>"
|
"<navMap>"
|
||||||
])
|
])
|
||||||
for chapter in chapters:
|
for chapter in chapters:
|
||||||
folder = chapter[0].replace(dstdir + '/OEBPS','').lstrip('/')
|
folder = chapter[0].replace(os.path.join(dstdir,'OEBPS'),'').lstrip('/').lstrip('\\\\')
|
||||||
title = os.path.basename(folder)
|
title = os.path.basename(folder)
|
||||||
filename = getImageFileName(os.path.join(folder,chapter[1]))
|
filename = getImageFileName(os.path.join(folder,chapter[1]))
|
||||||
f.write("<navPoint id=\"" + folder.replace('/','_') + "\"><navLabel><text>" + title
|
f.write("<navPoint id=\"" + folder.replace('/','_') + "\"><navLabel><text>" + title
|
||||||
@@ -91,7 +99,7 @@ def buildNCX(dstdir, title, chapters):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def buildOPF(profile, dstdir, title, filelist, cover=None):
|
def buildOPF(profile, dstdir, title, filelist, cover=None):
|
||||||
opffile = dstdir + '/OEBPS/content.opf'
|
opffile = os.path.join(dstdir,'OEBPS','content.opf')
|
||||||
# read the first file resolution
|
# read the first file resolution
|
||||||
profilelabel, deviceres, palette = image.ProfileData.Profiles[profile]
|
profilelabel, deviceres, palette = image.ProfileData.Profiles[profile]
|
||||||
imgres = str(deviceres[0]) + "x" + str(deviceres[1])
|
imgres = str(deviceres[0]) + "x" + str(deviceres[1])
|
||||||
@@ -113,7 +121,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
|
|||||||
])
|
])
|
||||||
# set cover
|
# set cover
|
||||||
if cover is not None:
|
if cover is not None:
|
||||||
filename = getImageFileName(cover.replace(dstdir + '/OEBPS','').lstrip('/'))
|
filename = getImageFileName(cover.replace(os.path.join(dstdir,'OEBPS'),'').lstrip('/').lstrip('\\\\'))
|
||||||
if '.png' == filename[1]:
|
if '.png' == filename[1]:
|
||||||
mt = 'image/png'
|
mt = 'image/png'
|
||||||
else:
|
else:
|
||||||
@@ -121,7 +129,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
|
|||||||
f.write("<item id=\"cover\" href=\"" + filename[0] + filename[1] + "\" media-type=\"" + mt + "\"/>\n")
|
f.write("<item id=\"cover\" href=\"" + filename[0] + filename[1] + "\" media-type=\"" + mt + "\"/>\n")
|
||||||
reflist = []
|
reflist = []
|
||||||
for path in filelist:
|
for path in filelist:
|
||||||
folder = path[0].replace(dstdir + '/OEBPS','').lstrip('/')
|
folder = path[0].replace(os.path.join(dstdir,'OEBPS'),'').lstrip('/').lstrip('\\\\')
|
||||||
filename = getImageFileName(path[1])
|
filename = getImageFileName(path[1])
|
||||||
uniqueid = os.path.join(folder,filename[0]).replace('/','_')
|
uniqueid = os.path.join(folder,filename[0]).replace('/','_')
|
||||||
reflist.append(uniqueid)
|
reflist.append(uniqueid)
|
||||||
@@ -138,11 +146,11 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
|
|||||||
f.write("</spine>\n<guide>\n</guide>\n</package>\n")
|
f.write("</spine>\n<guide>\n</guide>\n</package>\n")
|
||||||
f.close()
|
f.close()
|
||||||
# finish with standard ePub folders
|
# finish with standard ePub folders
|
||||||
os.mkdir(dstdir + '/META-INF')
|
os.mkdir(os.path.join(dstdir,'META-INF'))
|
||||||
f = open(dstdir + '/mimetype', 'w')
|
f = open(os.path.join(dstdir,'mimetype'), 'w')
|
||||||
f.write('application/epub+zip')
|
f.write('application/epub+zip')
|
||||||
f.close()
|
f.close()
|
||||||
f = open(dstdir + '/META-INF/container.xml', 'w')
|
f = open(os.path.join(dstdir,'META-INF','container.xml'), 'w')
|
||||||
f.writelines(["<?xml version=\"1.0\"?>\n",
|
f.writelines(["<?xml version=\"1.0\"?>\n",
|
||||||
"<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\n",
|
"<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\">\n",
|
||||||
"<rootfiles>\n",
|
"<rootfiles>\n",
|
||||||
@@ -205,8 +213,8 @@ def genEpubStruct(path):
|
|||||||
filelist = []
|
filelist = []
|
||||||
chapterlist = []
|
chapterlist = []
|
||||||
cover = None
|
cover = None
|
||||||
os.mkdir(path + "/OEBPS/Text")
|
os.mkdir(os.path.join(path,'OEBPS','Text'))
|
||||||
for (dirpath, dirnames, filenames) in os.walk(path + "/OEBPS/Images/"):
|
for (dirpath, dirnames, filenames) in os.walk(os.path.join(path,'OEBPS','Images')):
|
||||||
chapter = False
|
chapter = False
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
filename = getImageFileName(file)
|
filename = getImageFileName(file)
|
||||||
@@ -215,13 +223,13 @@ def genEpubStruct(path):
|
|||||||
if "credit" in file.lower():
|
if "credit" in file.lower():
|
||||||
os.rename(os.path.join(dirpath,file), os.path.join(dirpath,'ZZZ999_'+file))
|
os.rename(os.path.join(dirpath,file), os.path.join(dirpath,'ZZZ999_'+file))
|
||||||
file = 'ZZZ999_'+file
|
file = 'ZZZ999_'+file
|
||||||
if "+" in file.lower():
|
if "+" in file.lower() or "#" in file.lower():
|
||||||
newfilename = file.replace('+','_')
|
newfilename = file.replace('+','_').replace('#','_')
|
||||||
os.rename(os.path.join(dirpath,file), os.path.join(dirpath,newfilename))
|
os.rename(os.path.join(dirpath,file), os.path.join(dirpath,newfilename))
|
||||||
file = newfilename
|
file = newfilename
|
||||||
filelist.append(buildHTML(dirpath,file))
|
filelist.append(buildHTML(dirpath,file))
|
||||||
if not chapter:
|
if not chapter:
|
||||||
chapterlist.append((dirpath.replace('/Images','/Text'),filelist[-1][1]))
|
chapterlist.append((dirpath.replace('Images','Text'),filelist[-1][1]))
|
||||||
chapter = True
|
chapter = True
|
||||||
if cover is None:
|
if cover is None:
|
||||||
cover = os.path.join(filelist[-1][0],'cover' + getImageFileName(filelist[-1][1])[1])
|
cover = os.path.join(filelist[-1][0],'cover' + getImageFileName(filelist[-1][1])[1])
|
||||||
@@ -256,7 +264,7 @@ def getWorkFolder(file):
|
|||||||
except OSError:
|
except OSError:
|
||||||
raise
|
raise
|
||||||
move(path,path + "_temp")
|
move(path,path + "_temp")
|
||||||
move(path + "_temp",path + "/OEBPS/Images/")
|
move(path + "_temp",os.path.join(path,'OEBPS','Images'))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def Copyright():
|
def Copyright():
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ class MainWindow:
|
|||||||
self.progressbar.stop()
|
self.progressbar.stop()
|
||||||
|
|
||||||
def convert(self):
|
def convert(self):
|
||||||
|
tkMessageBox.showerror('Starting conversion', "KCC will now start converting files. GUI can seem frozen, kindly wait until some message appears!")
|
||||||
profilekey = ProfileData.ProfileLabels[self.profile.get()]
|
profilekey = ProfileData.ProfileLabels[self.profile.get()]
|
||||||
argv = ["-p",profilekey]
|
argv = ["-p",profilekey]
|
||||||
if self.image_preprocess == 0:
|
if self.image_preprocess == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user