Fix Python files:

* Prefer python2 to python that may point on python3 on modern installs.
* Fix indent/spaces consistency.

(cherry picked from commit 2265701268)
This commit is contained in:
Félix Piédallu 2018-01-10 13:38:36 +01:00 committed by Jehan
parent 3c6f789ca5
commit 15075932be
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
# Copyright 2005 Sven Neumann <sven@gimp.org>
@ -79,22 +79,22 @@ def benchmark (folder, save_output):
mask_layer = mask.active_layer;
truth = pdb.gimp_file_load (truth_name, truth_name)
convert_grayscale (truth)
convert_grayscale (truth)
truth_layer = truth.active_layer;
unclassified = unclassified_pixels (mask_layer, truth_layer)
sys.stderr.write (os.path.basename (image_name))
start = time.time ()
start = time.time ()
pdb.gimp_drawable_foreground_extract (image_layer,
FOREGROUND_EXTRACT_SIOX,
mask_layer)
end = time.time ()
FOREGROUND_EXTRACT_SIOX,
mask_layer)
end = time.time ()
sys.stderr.write (" ")
mask_layer.flush ()
mask_layer.flush ()
# Ignore errors when creating image displays;
# allows us to be used without a display.
@ -112,38 +112,38 @@ def benchmark (folder, save_output):
misclassified = misclassified_pixels (mask_layer, truth_layer)
sys.stderr.write ("%d %d %.2f%% %.3fs\n" %
(unclassified, misclassified,
(misclassified * 100.0 / unclassified),
end - start))
(unclassified, misclassified,
(misclassified * 100.0 / unclassified),
end - start))
total_unclassified += unclassified
total_misclassified += misclassified
total_time += end - start
total_unclassified += unclassified
total_misclassified += misclassified
total_time += end - start
gimp.delete (truth)
if save_output:
filename = os.path.join (folder, "output", name + '.png')
pdb.gimp_file_save (mask, mask_layer, filename, filename)
if save_output:
filename = os.path.join (folder, "output", name + '.png')
pdb.gimp_file_save (mask, mask_layer, filename, filename)
gimp.delete (mask)
# for loop ends
try:
gimp.delete (image_display)
gimp.delete (mask_display)
gimp.delete (image_display)
gimp.delete (mask_display)
except UnboundLocalError:
pass
pass
sys.stderr.write ("Total: %d %d %.2f%% %.3fs\n" %
(total_unclassified, total_misclassified,
(total_misclassified * 100.0 / total_unclassified),
total_time))
(total_unclassified, total_misclassified,
(total_misclassified * 100.0 / total_unclassified),
total_time))
def convert_grayscale (image):
if image.base_type != GRAY:
pdb.gimp_image_convert_grayscale (image)
pdb.gimp_image_convert_grayscale (image)
def unclassified_pixels (mask, truth):
@ -174,7 +174,7 @@ def misclassified_pixels (mask, truth):
(mean, std_dev, median, pixels,
count, percentile) = pdb.gimp_histogram (image.flatten (),
HISTOGRAM_VALUE, 255, 255)
HISTOGRAM_VALUE, 255, 255)
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.
# 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.
# 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"""
def colorxhtml(img, drawable, filename, raw_filename,
source_type, characters, size, separate):
source_type, characters, size, separate):
width = drawable.width
height = drawable.height
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
# 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.
# 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
#

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# 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

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# 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
# 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 -*-
#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.
# 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.
# 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.
# 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.
# 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.
# Copyright (C) 1997 James Henstridge <james@daa.com.au>
@ -119,8 +119,8 @@ def whirl_pinch(image, drawable, whirl, pinch, radius):
bot_p = ''
for col in range(self.sel_x1, self.sel_x2):
q, cx, cy = calc_undistorted_coords(self, col,
row, whirl, pinch,
radius)
row, whirl, pinch,
radius)
if q:
if cx >= 0: ix = int(cx)
else: ix = -(int(-cx) + 1)

View File

@ -2,7 +2,12 @@
# called as "py-compile [--basedir DIR] PY_FILES ...
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
basedir=
@ -65,4 +70,3 @@ for file in string.split(files):
sys.stdout.flush()
py_compile.compile(path)
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.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
import sys,re
@ -50,51 +50,51 @@ class Path:
def readgimpfile (self, filedesc):
text = filedesc.readlines()
for line in text:
namematch = re.match ("Name: (.*)$", line)
if namematch:
path.name = namematch.group(1)
pointmatch = re.match ("TYPE: (\d) X: (\d+) Y: (\d+)", line)
if pointmatch:
if pointmatch.group (1) == "3":
path.gimppoints.append ([])
(x, y) = map (int, pointmatch.groups()[1:])
path.gimppoints[-1].append (map (int, pointmatch.groups()))
if self.bounds:
if self.bounds[0] > x: self.bounds[0] = x
if self.bounds[1] > y: self.bounds[1] = y
if self.bounds[2] < x: self.bounds[2] = x
if self.bounds[3] < y: self.bounds[3] = y
else:
self.bounds = [x,y,x,y]
namematch = re.match ("Name: (.*)$", line)
if namematch:
path.name = namematch.group(1)
pointmatch = re.match ("TYPE: (\d) X: (\d+) Y: (\d+)", line)
if pointmatch:
if pointmatch.group (1) == "3":
path.gimppoints.append ([])
(x, y) = map (int, pointmatch.groups()[1:])
path.gimppoints[-1].append (map (int, pointmatch.groups()))
if self.bounds:
if self.bounds[0] > x: self.bounds[0] = x
if self.bounds[1] > y: self.bounds[1] = y
if self.bounds[2] < x: self.bounds[2] = x
if self.bounds[3] < y: self.bounds[3] = y
else:
self.bounds = [x,y,x,y]
def makesvg (self):
for path in self.gimppoints:
if path:
start = path[0]
svg = "M %d %d " % tuple (start[1:])
path = path[1:]
while path:
curve = path [0:3]
path = path[3:]
if len (curve) == 2:
svg = svg + "C %d %d %d %d %d %d z " % tuple (
tuple (curve [0][1:]) +
tuple (curve [1][1:]) +
tuple (start [1:]))
if len (curve) == 3:
svg = svg + "C %d %d %d %d %d %d " % tuple (
tuple (curve [0][1:]) +
tuple (curve [1][1:]) +
tuple (curve [2][1:]))
self.svgpath = self.svgpath + svg
start = path[0]
svg = "M %d %d " % tuple (start[1:])
path = path[1:]
while path:
curve = path [0:3]
path = path[3:]
if len (curve) == 2:
svg = svg + "C %d %d %d %d %d %d z " % tuple (
tuple (curve [0][1:]) +
tuple (curve [1][1:]) +
tuple (start [1:]))
if len (curve) == 3:
svg = svg + "C %d %d %d %d %d %d " % tuple (
tuple (curve [0][1:]) +
tuple (curve [1][1:]) +
tuple (curve [2][1:]))
self.svgpath = self.svgpath + svg
def writesvgfile (self, outfile):
if self.svgpath:
svg = svgtemplate % (self.bounds[2]-self.bounds[0],
self.bounds[3]-self.bounds[1],
self.name,
-self.bounds[0], -self.bounds[1],
self.svgpath)
svg = svgtemplate % (self.bounds[2]-self.bounds[0],
self.bounds[3]-self.bounds[1],
self.name,
-self.bounds[0], -self.bounds[1],
self.svgpath)
else:
svg = emptysvgtemplate
outfile.write (svg)
@ -115,4 +115,3 @@ path = Path()
path.readgimpfile (infile)
path.makesvg()
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
@ -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
PyGraphViz binding or use this hack in agraph.py:
--- agraph.py.orig 2010-01-04 16:07:46.000000000 +0100
+++ agraph.py 2010-01-04 16:13:54.000000000 +0100
--- agraph.py.orig 2010-01-04 16:07:46.000000000 +0100
+++ agraph.py 2010-01-04 16:13:54.000000000 +0100
@@ -1154,7 +1154,8 @@ class AGraph(object):
raise IOError("".join(errors))
if len(errors)>0:
- raise IOError("".join(errors))
+ # Workaround exception throwing due to warning about cycles
+ pass
return "".join(data)
"""