Fix Python files:

* Prefer python2 to python that may point on python3 on modern installs.
* Fix indent/spaces consistency.
This commit is contained in:
Félix Piédallu
2018-01-10 13:38:36 +01:00
committed by Jehan
parent 769325e51b
commit 2265701268
19 changed files with 93 additions and 90 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Foreground Extraction Benchmark # Foreground Extraction Benchmark
# Copyright 2005 Sven Neumann <sven@gimp.org> # Copyright 2005 Sven Neumann <sven@gimp.org>
@ -79,22 +79,22 @@ def benchmark (folder, save_output):
mask_layer = mask.active_layer; mask_layer = mask.active_layer;
truth = pdb.gimp_file_load (truth_name, truth_name) truth = pdb.gimp_file_load (truth_name, truth_name)
convert_grayscale (truth) convert_grayscale (truth)
truth_layer = truth.active_layer; truth_layer = truth.active_layer;
unclassified = unclassified_pixels (mask_layer, truth_layer) unclassified = unclassified_pixels (mask_layer, truth_layer)
sys.stderr.write (os.path.basename (image_name)) sys.stderr.write (os.path.basename (image_name))
start = time.time () start = time.time ()
pdb.gimp_drawable_foreground_extract (image_layer, pdb.gimp_drawable_foreground_extract (image_layer,
FOREGROUND_EXTRACT_SIOX, FOREGROUND_EXTRACT_SIOX,
mask_layer) mask_layer)
end = time.time () end = time.time ()
sys.stderr.write (" ") sys.stderr.write (" ")
mask_layer.flush () mask_layer.flush ()
# Ignore errors when creating image displays; # Ignore errors when creating image displays;
# allows us to be used without a display. # allows us to be used without a display.
@ -112,38 +112,38 @@ def benchmark (folder, save_output):
misclassified = misclassified_pixels (mask_layer, truth_layer) misclassified = misclassified_pixels (mask_layer, truth_layer)
sys.stderr.write ("%d %d %.2f%% %.3fs\n" % sys.stderr.write ("%d %d %.2f%% %.3fs\n" %
(unclassified, misclassified, (unclassified, misclassified,
(misclassified * 100.0 / unclassified), (misclassified * 100.0 / unclassified),
end - start)) end - start))
total_unclassified += unclassified total_unclassified += unclassified
total_misclassified += misclassified total_misclassified += misclassified
total_time += end - start total_time += end - start
gimp.delete (truth) gimp.delete (truth)
if save_output: if save_output:
filename = os.path.join (folder, "output", name + '.png') filename = os.path.join (folder, "output", name + '.png')
pdb.gimp_file_save (mask, mask_layer, filename, filename) pdb.gimp_file_save (mask, mask_layer, filename, filename)
gimp.delete (mask) gimp.delete (mask)
# for loop ends # for loop ends
try: try:
gimp.delete (image_display) gimp.delete (image_display)
gimp.delete (mask_display) gimp.delete (mask_display)
except UnboundLocalError: except UnboundLocalError:
pass pass
sys.stderr.write ("Total: %d %d %.2f%% %.3fs\n" % sys.stderr.write ("Total: %d %d %.2f%% %.3fs\n" %
(total_unclassified, total_misclassified, (total_unclassified, total_misclassified,
(total_misclassified * 100.0 / total_unclassified), (total_misclassified * 100.0 / total_unclassified),
total_time)) total_time))
def convert_grayscale (image): def convert_grayscale (image):
if image.base_type != GRAY: if image.base_type != GRAY:
pdb.gimp_image_convert_grayscale (image) pdb.gimp_image_convert_grayscale (image)
def unclassified_pixels (mask, truth): def unclassified_pixels (mask, truth):
@ -174,7 +174,7 @@ def misclassified_pixels (mask, truth):
(mean, std_dev, median, pixels, (mean, std_dev, median, pixels,
count, percentile) = pdb.gimp_histogram (image.flatten (), count, percentile) = pdb.gimp_histogram (image.flatten (),
HISTOGRAM_VALUE, 255, 255) HISTOGRAM_VALUE, 255, 255)
return count return count

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 2003, 2005 Manish Singh <yosh@gimp.org> # Copyright (C) 2003, 2005 Manish Singh <yosh@gimp.org>
@ -58,7 +58,7 @@ preamble = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
postamble = """\n</pre>\n</body>\n</html>\n""" postamble = """\n</pre>\n</body>\n</html>\n"""
def colorxhtml(img, drawable, filename, raw_filename, def colorxhtml(img, drawable, filename, raw_filename,
source_type, characters, size, separate): source_type, characters, size, separate):
width = drawable.width width = drawable.width
height = drawable.height height = drawable.height
bpp = drawable.bpp bpp = drawable.bpp

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# GIMP Plug-in for the OpenRaster file format # GIMP Plug-in for the OpenRaster file format
# http://create.freedesktop.org/wiki/OpenRaster # http://create.freedesktop.org/wiki/OpenRaster

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
#coding: utf-8 #coding: utf-8
# #

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#Copyright (c) Manish Singh #Copyright (c) Manish Singh

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 2006 Manish Singh <yosh@gimp.org> # Copyright (C) 2006 Manish Singh <yosh@gimp.org>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
# Gimp-Python - allows the writing of Gimp plugins in Python. # Gimp-Python - allows the writing of Gimp plugins in Python.
# Copyright (C) 1997 James Henstridge <james@daa.com.au> # Copyright (C) 1997 James Henstridge <james@daa.com.au>
@ -119,8 +119,8 @@ def whirl_pinch(image, drawable, whirl, pinch, radius):
bot_p = '' bot_p = ''
for col in range(self.sel_x1, self.sel_x2): for col in range(self.sel_x1, self.sel_x2):
q, cx, cy = calc_undistorted_coords(self, col, q, cx, cy = calc_undistorted_coords(self, col,
row, whirl, pinch, row, whirl, pinch,
radius) radius)
if q: if q:
if cx >= 0: ix = int(cx) if cx >= 0: ix = int(cx)
else: ix = -(int(-cx) + 1) else: ix = -(int(-cx) + 1)

View File

@ -2,7 +2,12 @@
# called as "py-compile [--basedir DIR] PY_FILES ... # called as "py-compile [--basedir DIR] PY_FILES ...
if [ -z "$PYTHON" ]; then if [ -z "$PYTHON" ]; then
PYTHON=python if [[ -x "$(command -v python2)" ]]; then
PYTHON=python2
else
# Let's hope it's Python2
PYTHON=python
fi
fi fi
basedir= basedir=
@ -65,4 +70,3 @@ for file in string.split(files):
sys.stdout.flush() sys.stdout.flush()
py_compile.compile(path) py_compile.compile(path)
print" 2>/dev/null || : print" 2>/dev/null || :

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
""" """
defcheck.py -- Consistency check for the .def files. defcheck.py -- Consistency check for the .def files.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
import sys,re import sys,re
@ -50,51 +50,51 @@ class Path:
def readgimpfile (self, filedesc): def readgimpfile (self, filedesc):
text = filedesc.readlines() text = filedesc.readlines()
for line in text: for line in text:
namematch = re.match ("Name: (.*)$", line) namematch = re.match ("Name: (.*)$", line)
if namematch: if namematch:
path.name = namematch.group(1) path.name = namematch.group(1)
pointmatch = re.match ("TYPE: (\d) X: (\d+) Y: (\d+)", line) pointmatch = re.match ("TYPE: (\d) X: (\d+) Y: (\d+)", line)
if pointmatch: if pointmatch:
if pointmatch.group (1) == "3": if pointmatch.group (1) == "3":
path.gimppoints.append ([]) path.gimppoints.append ([])
(x, y) = map (int, pointmatch.groups()[1:]) (x, y) = map (int, pointmatch.groups()[1:])
path.gimppoints[-1].append (map (int, pointmatch.groups())) path.gimppoints[-1].append (map (int, pointmatch.groups()))
if self.bounds: if self.bounds:
if self.bounds[0] > x: self.bounds[0] = x if self.bounds[0] > x: self.bounds[0] = x
if self.bounds[1] > y: self.bounds[1] = y if self.bounds[1] > y: self.bounds[1] = y
if self.bounds[2] < x: self.bounds[2] = x if self.bounds[2] < x: self.bounds[2] = x
if self.bounds[3] < y: self.bounds[3] = y if self.bounds[3] < y: self.bounds[3] = y
else: else:
self.bounds = [x,y,x,y] self.bounds = [x,y,x,y]
def makesvg (self): def makesvg (self):
for path in self.gimppoints: for path in self.gimppoints:
if path: if path:
start = path[0] start = path[0]
svg = "M %d %d " % tuple (start[1:]) svg = "M %d %d " % tuple (start[1:])
path = path[1:] path = path[1:]
while path: while path:
curve = path [0:3] curve = path [0:3]
path = path[3:] path = path[3:]
if len (curve) == 2: if len (curve) == 2:
svg = svg + "C %d %d %d %d %d %d z " % tuple ( svg = svg + "C %d %d %d %d %d %d z " % tuple (
tuple (curve [0][1:]) + tuple (curve [0][1:]) +
tuple (curve [1][1:]) + tuple (curve [1][1:]) +
tuple (start [1:])) tuple (start [1:]))
if len (curve) == 3: if len (curve) == 3:
svg = svg + "C %d %d %d %d %d %d " % tuple ( svg = svg + "C %d %d %d %d %d %d " % tuple (
tuple (curve [0][1:]) + tuple (curve [0][1:]) +
tuple (curve [1][1:]) + tuple (curve [1][1:]) +
tuple (curve [2][1:])) tuple (curve [2][1:]))
self.svgpath = self.svgpath + svg self.svgpath = self.svgpath + svg
def writesvgfile (self, outfile): def writesvgfile (self, outfile):
if self.svgpath: if self.svgpath:
svg = svgtemplate % (self.bounds[2]-self.bounds[0], svg = svgtemplate % (self.bounds[2]-self.bounds[0],
self.bounds[3]-self.bounds[1], self.bounds[3]-self.bounds[1],
self.name, self.name,
-self.bounds[0], -self.bounds[1], -self.bounds[0], -self.bounds[1],
self.svgpath) self.svgpath)
else: else:
svg = emptysvgtemplate svg = emptysvgtemplate
outfile.write (svg) outfile.write (svg)
@ -115,4 +115,3 @@ path = Path()
path.readgimpfile (infile) path.readgimpfile (infile)
path.makesvg() path.makesvg()
path.writesvgfile (outfile) path.writesvgfile (outfile)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python2
""" """
module-dependencies.py -- GIMP library and core module dependency constructor module-dependencies.py -- GIMP library and core module dependency constructor
@ -24,18 +24,18 @@ with dependencies between GIMP library and core modules. Run it from
the source root. Note that you'll either need the very latest the source root. Note that you'll either need the very latest
PyGraphViz binding or use this hack in agraph.py: PyGraphViz binding or use this hack in agraph.py:
--- agraph.py.orig 2010-01-04 16:07:46.000000000 +0100 --- agraph.py.orig 2010-01-04 16:07:46.000000000 +0100
+++ agraph.py 2010-01-04 16:13:54.000000000 +0100 +++ agraph.py 2010-01-04 16:13:54.000000000 +0100
@@ -1154,7 +1154,8 @@ class AGraph(object): @@ -1154,7 +1154,8 @@ class AGraph(object):
raise IOError("".join(errors)) raise IOError("".join(errors))
if len(errors)>0: if len(errors)>0:
- raise IOError("".join(errors)) - raise IOError("".join(errors))
+ # Workaround exception throwing due to warning about cycles + # Workaround exception throwing due to warning about cycles
+ pass + pass
return "".join(data) return "".join(data)
""" """