1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 17:56:30 +00:00

Fixes folder handling, subfolders and issues with spaces and # on filenames.

This commit is contained in:
Ciro Mattia Gonano
2013-01-29 00:08:31 +01:00
parent 1ce7a0040a
commit 05c8fe328e
4 changed files with 10 additions and 5 deletions

View File

@@ -114,6 +114,7 @@ and installed in `/usr/local/bin/`
- 2.1: Added basic error reporting - 2.1: Added basic error reporting
- 2.2: Added (valid!) ePub 2.0 output - 2.2: Added (valid!) ePub 2.0 output
Rename .zip files to .cbz to avoid overwriting Rename .zip files to .cbz to avoid overwriting
- 2.3: Fixed win32 ePub generation, folder handling, filenames with spaces and subfolders.
## TODO ## TODO
- Add gracefully exit for CBR if no rarfile.py and no unrar executable are found - Add gracefully exit for CBR if no rarfile.py and no unrar executable are found

2
kcc.py
View File

@@ -16,7 +16,7 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
# #
__version__ = '2.2' __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'

View File

@@ -50,13 +50,17 @@ def buildHTML(path,file):
filename = getImageFileName(file) filename = getImageFileName(file)
if filename is not None: if filename is not None:
postfix = '' postfix = ''
backref = 1
head = path head = path
while True: while True:
head, tail = os.path.split(head) head, tail = os.path.split(head)
if tail == 'Images': if tail == 'Images':
htmlpath = os.path.join(head,'Text') htmlpath = os.path.join(head,'Text',postfix)
break break
postfix = tail + "/" + postfix postfix = tail + "/" + postfix
backref += 1
if not os.path.exists(htmlpath):
os.makedirs(htmlpath)
htmlfile = os.path.join(htmlpath,filename[0] + '.html') 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",
@@ -66,7 +70,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/",postfix,file,"\" alt=\"",file,"\" /></div>\n", "<div><img src=\"","../" * backref,"Images/",postfix,file,"\" alt=\"",file,"\" /></div>\n",
"</body>\n", "</body>\n",
"</html>" "</html>"
]) ])
@@ -133,7 +137,7 @@ def buildOPF(profile, dstdir, title, filelist, cover=None):
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)
f.write("<item id=\"page_" + uniqueid + "\" href=\"" + os.path.join(folder.replace('Images/','Text/'),filename[0]) f.write("<item id=\"page_" + uniqueid + "\" href=\"" + os.path.join(folder.replace('Images','Text'),filename[0])
+ ".html\" media-type=\"application/xhtml+xml\"/>\n") + ".html\" media-type=\"application/xhtml+xml\"/>\n")
if '.png' == filename[1]: if '.png' == filename[1]:
mt = 'image/png' mt = 'image/png'

View File

@@ -155,7 +155,7 @@ class MainWindow:
if self.epub_only == 1: if self.epub_only == 1:
continue; continue;
try: try:
retcode = call("kindlegen " + epub_path, shell=True) retcode = call("kindlegen \"" + epub_path + "\"", shell=True)
if retcode < 0: if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode print >>sys.stderr, "Child was terminated by signal", -retcode
else: else: