mirror of
https://github.com/ciromattia/kcc
synced 2025-12-15 18:56:28 +00:00
Code cleanup
This commit is contained in:
2
kcc.py
2
kcc.py
@@ -26,7 +26,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
try:
|
try:
|
||||||
# noinspection PyUnresolvedReferences
|
#noinspection PyUnresolvedReferences
|
||||||
from PyQt4 import QtCore, QtGui, QtNetwork
|
from PyQt4 import QtCore, QtGui, QtNetwork
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "ERROR: PyQT4 is not installed!"
|
print "ERROR: PyQT4 is not installed!"
|
||||||
|
|||||||
@@ -77,11 +77,12 @@ class HTMLStripper(HTMLParser):
|
|||||||
return ''.join(self.fed)
|
return ''.join(self.fed)
|
||||||
|
|
||||||
|
|
||||||
#noinspection PyAttributeOutsideInit,PyShadowingBuiltins
|
|
||||||
class WebServerHandler(BaseHTTPRequestHandler):
|
class WebServerHandler(BaseHTTPRequestHandler):
|
||||||
|
#noinspection PyShadowingBuiltins
|
||||||
def log_message(self, format, *args):
|
def log_message(self, format, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
#noinspection PyAttributeOutsideInit
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
if self.path == '/':
|
if self.path == '/':
|
||||||
self.path = '/index.html'
|
self.path = '/index.html'
|
||||||
@@ -145,7 +146,6 @@ class WebServerHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_error(404, 'File Not Found: %s' % self.path)
|
self.send_error(404, 'File Not Found: %s' % self.path)
|
||||||
|
|
||||||
|
|
||||||
#noinspection PyBroadException
|
|
||||||
class WebServerThread(QtCore.QThread):
|
class WebServerThread(QtCore.QThread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtCore.QThread.__init__(self)
|
QtCore.QThread.__init__(self)
|
||||||
@@ -159,7 +159,7 @@ class WebServerThread(QtCore.QThread):
|
|||||||
try:
|
try:
|
||||||
# Sweet cross-platform one-liner to get LAN ip address
|
# Sweet cross-platform one-liner to get LAN ip address
|
||||||
lIP = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1][0]
|
lIP = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1][0]
|
||||||
except:
|
except StandardError:
|
||||||
# Sadly it can fail on some Linux configurations
|
# Sadly it can fail on some Linux configurations
|
||||||
lIP = None
|
lIP = None
|
||||||
try:
|
try:
|
||||||
@@ -172,14 +172,13 @@ class WebServerThread(QtCore.QThread):
|
|||||||
self.emit(QtCore.SIGNAL("addMessage"), '<b>Content server</b> started on port 4242.', 'info')
|
self.emit(QtCore.SIGNAL("addMessage"), '<b>Content server</b> started on port 4242.', 'info')
|
||||||
while self.running:
|
while self.running:
|
||||||
self.server.handle_request()
|
self.server.handle_request()
|
||||||
except:
|
except StandardError:
|
||||||
self.emit(QtCore.SIGNAL("addMessage"), '<b>Content server</b> failed to start!', 'error')
|
self.emit(QtCore.SIGNAL("addMessage"), '<b>Content server</b> failed to start!', 'error')
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyBroadException
|
|
||||||
class VersionThread(QtCore.QThread):
|
class VersionThread(QtCore.QThread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QtCore.QThread.__init__(self)
|
QtCore.QThread.__init__(self)
|
||||||
@@ -191,7 +190,7 @@ class VersionThread(QtCore.QThread):
|
|||||||
try:
|
try:
|
||||||
XML = urllib2.urlopen('http://kcc.vulturis.eu/Version.php')
|
XML = urllib2.urlopen('http://kcc.vulturis.eu/Version.php')
|
||||||
XML = parse(XML)
|
XML = parse(XML)
|
||||||
except Exception:
|
except StandardError:
|
||||||
return
|
return
|
||||||
latestVersion = XML.childNodes[0].getElementsByTagName('latest')[0].childNodes[0].toxml()
|
latestVersion = XML.childNodes[0].getElementsByTagName('latest')[0].childNodes[0].toxml()
|
||||||
if tuple(map(int, (latestVersion.split(".")))) > tuple(map(int, (__version__.split(".")))):
|
if tuple(map(int, (latestVersion.split(".")))) > tuple(map(int, (__version__.split(".")))):
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import locale
|
|||||||
from subprocess import Popen, STDOUT, PIPE
|
from subprocess import Popen, STDOUT, PIPE
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyBroadException
|
|
||||||
class CBxArchive:
|
class CBxArchive:
|
||||||
def __init__(self, origFileName):
|
def __init__(self, origFileName):
|
||||||
self.origFileName = origFileName
|
self.origFileName = origFileName
|
||||||
@@ -51,7 +50,7 @@ class CBxArchive:
|
|||||||
elif f.endswith('/'):
|
elif f.endswith('/'):
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.join(targetdir, f))
|
os.makedirs(os.path.join(targetdir, f))
|
||||||
except:
|
except StandardError:
|
||||||
pass # the dir exists so we are going to extract the images only.
|
pass # the dir exists so we are going to extract the images only.
|
||||||
else:
|
else:
|
||||||
filelist.append(f)
|
filelist.append(f)
|
||||||
@@ -66,7 +65,7 @@ class CBxArchive:
|
|||||||
elif f.endswith('/'):
|
elif f.endswith('/'):
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.join(targetdir, f))
|
os.makedirs(os.path.join(targetdir, f))
|
||||||
except:
|
except StandardError:
|
||||||
pass # the dir exists so we are going to extract the images only.
|
pass # the dir exists so we are going to extract the images only.
|
||||||
else:
|
else:
|
||||||
filelist.append(f.encode(locale.getpreferredencoding()))
|
filelist.append(f.encode(locale.getpreferredencoding()))
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ def fileImgProcess_tick(output):
|
|||||||
|
|
||||||
|
|
||||||
def fileImgProcess(work):
|
def fileImgProcess(work):
|
||||||
#noinspection PyBroadException
|
|
||||||
try:
|
try:
|
||||||
afile = work[0]
|
afile = work[0]
|
||||||
dirpath = work[1]
|
dirpath = work[1]
|
||||||
@@ -391,7 +390,7 @@ def fileImgProcess(work):
|
|||||||
img2.rotated = True
|
img2.rotated = True
|
||||||
applyImgOptimization(img2, opt, 0)
|
applyImgOptimization(img2, opt, 0)
|
||||||
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
img2.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
except:
|
except StandardError:
|
||||||
return str(sys.exc_info()[1])
|
return str(sys.exc_info()[1])
|
||||||
|
|
||||||
|
|
||||||
@@ -710,7 +709,7 @@ def splitDirectory(path, mode):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnboundLocalVariable
|
#noinspection PyUnboundLocalVariable
|
||||||
def preSplitDirectory(path):
|
def preSplitDirectory(path):
|
||||||
if getDirectorySize(os.path.join(path, 'OEBPS', 'Images')) > 262144000:
|
if getDirectorySize(os.path.join(path, 'OEBPS', 'Images')) > 262144000:
|
||||||
# Detect directory stucture
|
# Detect directory stucture
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from shutil import rmtree, copytree, move
|
|||||||
from optparse import OptionParser, OptionGroup
|
from optparse import OptionParser, OptionGroup
|
||||||
from multiprocessing import Pool, freeze_support
|
from multiprocessing import Pool, freeze_support
|
||||||
try:
|
try:
|
||||||
# noinspection PyUnresolvedReferences
|
#noinspection PyUnresolvedReferences
|
||||||
from PIL import Image, ImageStat
|
from PIL import Image, ImageStat
|
||||||
if tuple(map(int, ('2.2.1'.split(".")))) > tuple(map(int, (Image.PILLOW_VERSION.split(".")))):
|
if tuple(map(int, ('2.2.1'.split(".")))) > tuple(map(int, (Image.PILLOW_VERSION.split(".")))):
|
||||||
print "ERROR: Pillow 2.2.1 or newer is required!"
|
print "ERROR: Pillow 2.2.1 or newer is required!"
|
||||||
@@ -93,8 +93,8 @@ def splitImage_tick(output):
|
|||||||
splitWorkerPool.terminate()
|
splitWorkerPool.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
#noinspection PyUnboundLocalVariable
|
||||||
def splitImage(work):
|
def splitImage(work):
|
||||||
#noinspection PyBroadException
|
|
||||||
try:
|
try:
|
||||||
path = work[0]
|
path = work[0]
|
||||||
name = work[1]
|
name = work[1]
|
||||||
@@ -156,7 +156,6 @@ def splitImage(work):
|
|||||||
for panel in panelsCleaned:
|
for panel in panelsCleaned:
|
||||||
panels.append(panel)
|
panels.append(panel)
|
||||||
if opt.debug:
|
if opt.debug:
|
||||||
# noinspection PyUnboundLocalVariable
|
|
||||||
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
|
debugImage.save(os.path.join(path, fileExpanded[0] + '-debug.png'), 'PNG')
|
||||||
|
|
||||||
# Create virtual pages
|
# Create virtual pages
|
||||||
@@ -195,7 +194,7 @@ def splitImage(work):
|
|||||||
str(pageNumber) + '.png'), 'PNG')
|
str(pageNumber) + '.png'), 'PNG')
|
||||||
pageNumber += 1
|
pageNumber += 1
|
||||||
os.remove(filePath)
|
os.remove(filePath)
|
||||||
except:
|
except StandardError:
|
||||||
return str(sys.exc_info()[1])
|
return str(sys.exc_info()[1])
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +203,6 @@ def Copyright():
|
|||||||
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals())
|
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals())
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyBroadException
|
|
||||||
def main(argv=None, qtGUI=None):
|
def main(argv=None, qtGUI=None):
|
||||||
global options, GUI, splitWorkerPool, splitWorkerOutput
|
global options, GUI, splitWorkerPool, splitWorkerOutput
|
||||||
parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
|
parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user