diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py
index db1f1b3..25b8626 100644
--- a/kcc/KCC_gui.py
+++ b/kcc/KCC_gui.py
@@ -24,14 +24,14 @@ __docformat__ = 'restructuredtext en'
import os
import sys
-import shutil
import traceback
import urllib2
-import time
import comic2ebook
import kindlesplit
import socket
-import string
+from string import split
+from time import sleep
+from shutil import move
from psutil import virtual_memory
from KCC_rc_web import WebContent
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
@@ -111,7 +111,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
'alt="KCC Logo" src="' + GUIMain.webContent.logo + '" /> -
\n')
if len(GUIMain.completedWork) > 0 and not GUIMain.conversionAlive:
for key in sorted(GUIMain.completedWork.iterkeys()):
- self.wfile.write('' + string.split(key, '.')[0] + '
\n')
+ self.wfile.write('' + split(key, '.')[0] + '
\n')
else:
self.wfile.write('No downloads are available.
'
'Convert some files and refresh this page.
\n')
@@ -242,7 +242,7 @@ class KindleUnpackThread(QtCore.QRunnable):
profile = self.work[1]
os.remove(item)
mobiPath = item.replace('.epub', '.mobi')
- shutil.move(mobiPath, mobiPath + '_toclean')
+ move(mobiPath, mobiPath + '_toclean')
try:
# 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
@@ -341,7 +341,7 @@ class WorkerThread(QtCore.QThread):
currentJobs.append(unicode(GUI.JobList.item(i).text()))
GUI.JobList.clear()
for job in currentJobs:
- time.sleep(0.5)
+ sleep(0.5)
if not self.conversionAlive:
self.clean()
return
@@ -394,7 +394,7 @@ class WorkerThread(QtCore.QThread):
worker.signals.result.connect(self.addResult)
self.pool.start(worker)
self.pool.waitForDone()
- time.sleep(0.5)
+ sleep(0.5)
self.kindlegenErrorCode = [0]
for errors in self.workerOutput:
if errors[0] != 0:
@@ -420,7 +420,7 @@ class WorkerThread(QtCore.QThread):
worker.signals.result.connect(self.addResult)
self.pool.start(worker)
self.pool.waitForDone()
- time.sleep(0.5)
+ sleep(0.5)
for success in self.workerOutput:
if not success:
self.errors = True
diff --git a/kcc/cbxarchive.py b/kcc/cbxarchive.py
index f20359c..010ee64 100644
--- a/kcc/cbxarchive.py
+++ b/kcc/cbxarchive.py
@@ -24,6 +24,7 @@ import zipfile
import rarfile
import locale
from subprocess import Popen, STDOUT, PIPE
+from shutil import move
class CBxArchive:
@@ -94,8 +95,7 @@ class CBxArchive:
if 'ComicInfo.xml' in adir:
adir.remove('ComicInfo.xml')
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])):
- 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]))
return targetdir
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py
index 5526c7a..2ee8155 100755
--- a/kcc/comic2ebook.py
+++ b/kcc/comic2ebook.py
@@ -25,14 +25,15 @@ __docformat__ = 'restructuredtext en'
import os
import sys
-import tempfile
import re
import stat
import string
+from tempfile import mkdtemp
from shutil import move, copyfile, copytree, rmtree, make_archive
from optparse import OptionParser, OptionGroup
from multiprocessing import Pool, freeze_support
from xml.dom.minidom import parse
+from uuid import uuid4
try:
from PyQt4 import QtCore
except ImportError:
@@ -41,6 +42,7 @@ import comic2panel
import image
import cbxarchive
import pdfjpgextract
+import unicodedata
def buildHTML(path, imgfile):
@@ -169,7 +171,6 @@ def buildHTML(path, imgfile):
def buildNCX(dstdir, title, chapters):
- from uuid import uuid4
options.uuid = str(uuid4())
options.uuid = options.uuid.encode('utf-8')
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
@@ -537,7 +538,7 @@ def getWorkFolder(afile):
if len(afile) > 240:
raise UserWarning("Path is too long.")
if os.path.isdir(afile):
- workdir = tempfile.mkdtemp('', 'KCC-TMP-')
+ workdir = mkdtemp('', 'KCC-TMP-')
try:
os.rmdir(workdir) # needed for copytree() fails if dst already exists
fullPath = os.path.join(workdir, 'OEBPS', 'Images')
@@ -556,7 +557,7 @@ def getWorkFolder(afile):
rmtree(path, True)
raise UserWarning("Failed to extract images.")
else:
- workdir = tempfile.mkdtemp('', 'KCC-TMP-')
+ workdir = mkdtemp('', 'KCC-TMP-')
cbx = cbxarchive.CBxArchive(afile)
if cbx.isCbxFile():
try:
@@ -628,7 +629,6 @@ def checkComicInfo(path, originalPath):
def slugify(value):
# Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
- import unicodedata
if isinstance(value, str):
#noinspection PyArgumentList
value = unicodedata.normalize('NFKD', unicode(value, 'latin1')).encode('ascii', 'ignore')
@@ -684,7 +684,7 @@ def getDirectorySize(start_path='.'):
def createNewTome():
- tomePathRoot = tempfile.mkdtemp('', 'KCC-TMP-')
+ tomePathRoot = mkdtemp('', 'KCC-TMP-')
tomePath = os.path.join(tomePathRoot, 'OEBPS', 'Images')
os.makedirs(tomePath)
return tomePath, tomePathRoot