~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Scripts/pilfile.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# 0.4 2003-09-30 fl   Expand wildcards on Windows; robustness tweaks
18
18
#
19
19
 
 
20
from __future__ import print_function
 
21
 
20
22
import site
21
23
import getopt, glob, sys
22
24
 
23
25
from PIL import Image
24
26
 
25
27
if len(sys.argv) == 1:
26
 
    print "PIL File 0.4/2003-09-30 -- identify image files"
27
 
    print "Usage: pilfile [option] files..."
28
 
    print "Options:"
29
 
    print "  -f  list supported file formats"
30
 
    print "  -i  show associated info and tile data"
31
 
    print "  -v  verify file headers"
32
 
    print "  -q  quiet, don't warn for unidentified/missing/broken files"
 
28
    print("PIL File 0.4/2003-09-30 -- identify image files")
 
29
    print("Usage: pilfile [option] files...")
 
30
    print("Options:")
 
31
    print("  -f  list supported file formats")
 
32
    print("  -i  show associated info and tile data")
 
33
    print("  -v  verify file headers")
 
34
    print("  -q  quiet, don't warn for unidentified/missing/broken files")
33
35
    sys.exit(1)
34
36
 
35
37
try:
36
38
    opt, args = getopt.getopt(sys.argv[1:], "fqivD")
37
 
except getopt.error, v:
38
 
    print v
 
39
except getopt.error as v:
 
40
    print(v)
39
41
    sys.exit(1)
40
42
 
41
43
verbose = quiet = verify = 0
43
45
for o, a in opt:
44
46
    if o == "-f":
45
47
        Image.init()
46
 
        id = Image.ID[:]
47
 
        id.sort()
48
 
        print "Supported formats:"
 
48
        id = sorted(Image.ID)
 
49
        print("Supported formats:")
49
50
        for i in id:
50
 
            print i,
 
51
            print(i, end=' ')
51
52
        sys.exit(1)
52
53
    elif o == "-i":
53
54
        verbose = 1
73
74
for file in globfix(args):
74
75
    try:
75
76
        im = Image.open(file)
76
 
        print "%s:" % file, im.format, "%dx%d" % im.size, im.mode,
 
77
        print("%s:" % file, im.format, "%dx%d" % im.size, im.mode, end=' ')
77
78
        if verbose:
78
 
            print im.info, im.tile,
79
 
        print
 
79
            print(im.info, im.tile, end=' ')
 
80
        print()
80
81
        if verify:
81
82
            try:
82
83
                im.verify()
83
84
            except:
84
85
                if not quiet:
85
 
                    print "failed to verify image",
86
 
                    print "(%s:%s)" % (sys.exc_type, sys.exc_value)
87
 
    except IOError, v:
 
86
                    print("failed to verify image", end=' ')
 
87
                    print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
 
88
    except IOError as v:
88
89
        if not quiet:
89
 
            print file, "failed:", v
 
90
            print(file, "failed:", v)
90
91
    except:
91
92
        import traceback
92
93
        if not quiet:
93
 
            print file, "failed:", "unexpected error"
 
94
            print(file, "failed:", "unexpected error")
94
95
            traceback.print_exc(file=sys.stdout)