mirror of
https://github.com/ciromattia/kcc
synced 2026-06-25 15:54:02 +00:00
Optimized imports
This commit is contained in:
+8
-8
@@ -24,14 +24,14 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
|
||||||
import traceback
|
import traceback
|
||||||
import urllib2
|
import urllib2
|
||||||
import time
|
|
||||||
import comic2ebook
|
import comic2ebook
|
||||||
import kindlesplit
|
import kindlesplit
|
||||||
import socket
|
import socket
|
||||||
import string
|
from string import split
|
||||||
|
from time import sleep
|
||||||
|
from shutil import move
|
||||||
from psutil import virtual_memory
|
from psutil import virtual_memory
|
||||||
from KCC_rc_web import WebContent
|
from KCC_rc_web import WebContent
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||||
@@ -111,7 +111,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
|
|||||||
'alt="KCC Logo" src="' + GUIMain.webContent.logo + '" /> -</p>\n')
|
'alt="KCC Logo" src="' + GUIMain.webContent.logo + '" /> -</p>\n')
|
||||||
if len(GUIMain.completedWork) > 0 and not GUIMain.conversionAlive:
|
if len(GUIMain.completedWork) > 0 and not GUIMain.conversionAlive:
|
||||||
for key in sorted(GUIMain.completedWork.iterkeys()):
|
for key in sorted(GUIMain.completedWork.iterkeys()):
|
||||||
self.wfile.write('<p><a href="' + key + '">' + string.split(key, '.')[0] + '</a></p>\n')
|
self.wfile.write('<p><a href="' + key + '">' + split(key, '.')[0] + '</a></p>\n')
|
||||||
else:
|
else:
|
||||||
self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>'
|
self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>'
|
||||||
'Convert some files and refresh this page.</p>\n')
|
'Convert some files and refresh this page.</p>\n')
|
||||||
@@ -242,7 +242,7 @@ class KindleUnpackThread(QtCore.QRunnable):
|
|||||||
profile = self.work[1]
|
profile = self.work[1]
|
||||||
os.remove(item)
|
os.remove(item)
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
shutil.move(mobiPath, mobiPath + '_toclean')
|
move(mobiPath, mobiPath + '_toclean')
|
||||||
try:
|
try:
|
||||||
# MOBI file produced by KindleGen is hybrid. KF8 + M7 + Source header
|
# MOBI file produced by KindleGen is hybrid. KF8 + M7 + Source header
|
||||||
# KindleSplit is removing redundant data as we need only KF8 part for new Kindle models
|
# KindleSplit is removing redundant data as we need only KF8 part for new Kindle models
|
||||||
@@ -341,7 +341,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
currentJobs.append(unicode(GUI.JobList.item(i).text()))
|
currentJobs.append(unicode(GUI.JobList.item(i).text()))
|
||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
for job in currentJobs:
|
for job in currentJobs:
|
||||||
time.sleep(0.5)
|
sleep(0.5)
|
||||||
if not self.conversionAlive:
|
if not self.conversionAlive:
|
||||||
self.clean()
|
self.clean()
|
||||||
return
|
return
|
||||||
@@ -394,7 +394,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
worker.signals.result.connect(self.addResult)
|
worker.signals.result.connect(self.addResult)
|
||||||
self.pool.start(worker)
|
self.pool.start(worker)
|
||||||
self.pool.waitForDone()
|
self.pool.waitForDone()
|
||||||
time.sleep(0.5)
|
sleep(0.5)
|
||||||
self.kindlegenErrorCode = [0]
|
self.kindlegenErrorCode = [0]
|
||||||
for errors in self.workerOutput:
|
for errors in self.workerOutput:
|
||||||
if errors[0] != 0:
|
if errors[0] != 0:
|
||||||
@@ -420,7 +420,7 @@ class WorkerThread(QtCore.QThread):
|
|||||||
worker.signals.result.connect(self.addResult)
|
worker.signals.result.connect(self.addResult)
|
||||||
self.pool.start(worker)
|
self.pool.start(worker)
|
||||||
self.pool.waitForDone()
|
self.pool.waitForDone()
|
||||||
time.sleep(0.5)
|
sleep(0.5)
|
||||||
for success in self.workerOutput:
|
for success in self.workerOutput:
|
||||||
if not success:
|
if not success:
|
||||||
self.errors = True
|
self.errors = True
|
||||||
|
|||||||
+2
-2
@@ -24,6 +24,7 @@ import zipfile
|
|||||||
import rarfile
|
import rarfile
|
||||||
import locale
|
import locale
|
||||||
from subprocess import Popen, STDOUT, PIPE
|
from subprocess import Popen, STDOUT, PIPE
|
||||||
|
from shutil import move
|
||||||
|
|
||||||
|
|
||||||
class CBxArchive:
|
class CBxArchive:
|
||||||
@@ -94,8 +95,7 @@ class CBxArchive:
|
|||||||
if 'ComicInfo.xml' in adir:
|
if 'ComicInfo.xml' in adir:
|
||||||
adir.remove('ComicInfo.xml')
|
adir.remove('ComicInfo.xml')
|
||||||
if len(adir) == 1 and os.path.isdir(os.path.join(targetdir, adir[0])):
|
if len(adir) == 1 and os.path.isdir(os.path.join(targetdir, adir[0])):
|
||||||
import shutil
|
|
||||||
for f in os.listdir(os.path.join(targetdir, adir[0])):
|
for f in os.listdir(os.path.join(targetdir, adir[0])):
|
||||||
shutil.move(os.path.join(targetdir, adir[0], f), targetdir)
|
move(os.path.join(targetdir, adir[0], f), targetdir)
|
||||||
os.rmdir(os.path.join(targetdir, adir[0]))
|
os.rmdir(os.path.join(targetdir, adir[0]))
|
||||||
return targetdir
|
return targetdir
|
||||||
|
|||||||
+6
-6
@@ -25,14 +25,15 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import re
|
import re
|
||||||
import stat
|
import stat
|
||||||
import string
|
import string
|
||||||
|
from tempfile import mkdtemp
|
||||||
from shutil import move, copyfile, copytree, rmtree, make_archive
|
from shutil import move, copyfile, copytree, rmtree, make_archive
|
||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
from multiprocessing import Pool, freeze_support
|
from multiprocessing import Pool, freeze_support
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
|
from uuid import uuid4
|
||||||
try:
|
try:
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -41,6 +42,7 @@ import comic2panel
|
|||||||
import image
|
import image
|
||||||
import cbxarchive
|
import cbxarchive
|
||||||
import pdfjpgextract
|
import pdfjpgextract
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
|
|
||||||
def buildHTML(path, imgfile):
|
def buildHTML(path, imgfile):
|
||||||
@@ -169,7 +171,6 @@ def buildHTML(path, imgfile):
|
|||||||
|
|
||||||
|
|
||||||
def buildNCX(dstdir, title, chapters):
|
def buildNCX(dstdir, title, chapters):
|
||||||
from uuid import uuid4
|
|
||||||
options.uuid = str(uuid4())
|
options.uuid = str(uuid4())
|
||||||
options.uuid = options.uuid.encode('utf-8')
|
options.uuid = options.uuid.encode('utf-8')
|
||||||
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
||||||
@@ -537,7 +538,7 @@ def getWorkFolder(afile):
|
|||||||
if len(afile) > 240:
|
if len(afile) > 240:
|
||||||
raise UserWarning("Path is too long.")
|
raise UserWarning("Path is too long.")
|
||||||
if os.path.isdir(afile):
|
if os.path.isdir(afile):
|
||||||
workdir = tempfile.mkdtemp('', 'KCC-TMP-')
|
workdir = mkdtemp('', 'KCC-TMP-')
|
||||||
try:
|
try:
|
||||||
os.rmdir(workdir) # needed for copytree() fails if dst already exists
|
os.rmdir(workdir) # needed for copytree() fails if dst already exists
|
||||||
fullPath = os.path.join(workdir, 'OEBPS', 'Images')
|
fullPath = os.path.join(workdir, 'OEBPS', 'Images')
|
||||||
@@ -556,7 +557,7 @@ def getWorkFolder(afile):
|
|||||||
rmtree(path, True)
|
rmtree(path, True)
|
||||||
raise UserWarning("Failed to extract images.")
|
raise UserWarning("Failed to extract images.")
|
||||||
else:
|
else:
|
||||||
workdir = tempfile.mkdtemp('', 'KCC-TMP-')
|
workdir = mkdtemp('', 'KCC-TMP-')
|
||||||
cbx = cbxarchive.CBxArchive(afile)
|
cbx = cbxarchive.CBxArchive(afile)
|
||||||
if cbx.isCbxFile():
|
if cbx.isCbxFile():
|
||||||
try:
|
try:
|
||||||
@@ -628,7 +629,6 @@ def checkComicInfo(path, originalPath):
|
|||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
|
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
|
||||||
import unicodedata
|
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
#noinspection PyArgumentList
|
#noinspection PyArgumentList
|
||||||
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
|
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
|
||||||
@@ -684,7 +684,7 @@ def getDirectorySize(start_path='.'):
|
|||||||
|
|
||||||
|
|
||||||
def createNewTome():
|
def createNewTome():
|
||||||
tomePathRoot = tempfile.mkdtemp('', 'KCC-TMP-')
|
tomePathRoot = mkdtemp('', 'KCC-TMP-')
|
||||||
tomePath = os.path.join(tomePathRoot, 'OEBPS', 'Images')
|
tomePath = os.path.join(tomePathRoot, 'OEBPS', 'Images')
|
||||||
os.makedirs(tomePath)
|
os.makedirs(tomePath)
|
||||||
return tomePath, tomePathRoot
|
return tomePath, tomePathRoot
|
||||||
|
|||||||
Reference in New Issue
Block a user