flake8 and tidy up

This commit is contained in:
Hugo 2018-09-26 14:38:44 +03:00
parent f13c150f00
commit ae415907cb

View File

@ -41,7 +41,7 @@ if sys.platform.startswith('win'):
if hasattr(shutil, 'which'): if hasattr(shutil, 'which'):
which = shutil.which which = shutil.which
else: else:
# Python < 3.3 # Python 2
import distutils.spawn import distutils.spawn
which = distutils.spawn.find_executable which = distutils.spawn.find_executable
for binary in ('gswin32c', 'gswin64c', 'gs'): for binary in ('gswin32c', 'gswin64c', 'gs'):
@ -62,7 +62,7 @@ def has_ghostscript():
subprocess.check_call(['gs', '--version'], stdout=devnull) subprocess.check_call(['gs', '--version'], stdout=devnull)
return True return True
except OSError: except OSError:
# no ghostscript # No Ghostscript
pass pass
return False return False
@ -97,9 +97,9 @@ def Ghostscript(tile, size, fp, scale=1):
os.close(in_fd) os.close(in_fd)
infile = infile_temp infile = infile_temp
# ignore length and offset! # Ignore length and offset!
# ghostscript can read it # Ghostscript can read it
# copy whole file to read in ghostscript # Copy whole file to read in Ghostscript
with open(infile_temp, 'wb') as f: with open(infile_temp, 'wb') as f:
# fetch length of fp # fetch length of fp
fp.seek(0, 2) fp.seek(0, 2)
@ -115,13 +115,13 @@ def Ghostscript(tile, size, fp, scale=1):
lengthfile -= len(s) lengthfile -= len(s)
f.write(s) f.write(s)
# Build ghostscript command # Build Ghostscript command
command = ["gs", command = ["gs",
"-q", # quiet mode "-q", # quiet mode
"-g%dx%d" % size, # set output geometry (pixels) "-g%dx%d" % size, # set output geometry (pixels)
"-r%fx%f" % res, # set input DPI (dots per inch) "-r%fx%f" % res, # set input DPI (dots per inch)
"-dBATCH", # exit after processing "-dBATCH", # exit after processing
"-dNOPAUSE", # don't pause between pages, "-dNOPAUSE", # don't pause between pages
"-dSAFER", # safe mode "-dSAFER", # safe mode
"-sDEVICE=ppmraw", # ppm driver "-sDEVICE=ppmraw", # ppm driver
"-sOutputFile=%s" % outfile, # output file "-sOutputFile=%s" % outfile, # output file
@ -136,7 +136,7 @@ def Ghostscript(tile, size, fp, scale=1):
raise WindowsError('Unable to locate Ghostscript on paths') raise WindowsError('Unable to locate Ghostscript on paths')
command[0] = gs_windows_binary command[0] = gs_windows_binary
# push data through ghostscript # push data through Ghostscript
try: try:
with open(os.devnull, 'w+b') as devnull: with open(os.devnull, 'w+b') as devnull:
startupinfo = None startupinfo = None
@ -232,7 +232,7 @@ class EpsImageFile(ImageFile.ImageFile):
try: try:
m = split.match(s) m = split.match(s)
except re.error as v: except re.error:
raise SyntaxError("not an EPS file") raise SyntaxError("not an EPS file")
if m: if m:
@ -247,7 +247,7 @@ class EpsImageFile(ImageFile.ImageFile):
self.size = box[2] - box[0], box[3] - box[1] self.size = box[2] - box[0], box[3] - box[1]
self.tile = [("eps", (0, 0) + self.size, offset, self.tile = [("eps", (0, 0) + self.size, offset,
(length, box))] (length, box))]
except: except Exception:
pass pass
else: else: