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

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/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:
 
1
#! /usr/local/bin/python
 
2
#
 
3
# The Python Imaging Library.
 
4
# $Id$
 
5
#
 
6
# a utility to identify image files
 
7
#
 
8
# this script identifies image files, extracting size and
 
9
# pixel mode information for known file formats.  Note that
 
10
# you don't need the PIL C extension to use this module.
 
11
#
 
12
# History:
 
13
# 0.0 1995-09-01 fl   Created
 
14
# 0.1 1996-05-18 fl   Modified options, added debugging mode
 
15
# 0.2 1996-12-29 fl   Added verify mode
 
16
# 0.3 1999-06-05 fl   Don't mess up on class exceptions (1.5.2 and later)
 
17
# 0.4 2003-09-30 fl   Expand wildcards on Windows; robustness tweaks
 
18
#
 
19
 
 
20
import site
 
21
import getopt, glob, sys
 
22
 
 
23
from PIL import Image
 
24
 
 
25
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"
 
33
    sys.exit(1)
 
34
 
 
35
try:
 
36
    opt, args = getopt.getopt(sys.argv[1:], "fqivD")
 
37
except getopt.error, v:
 
38
    print v
 
39
    sys.exit(1)
 
40
 
 
41
verbose = quiet = verify = 0
 
42
 
 
43
for o, a in opt:
 
44
    if o == "-f":
 
45
        Image.init()
 
46
        id = Image.ID[:]
 
47
        id.sort()
 
48
        print "Supported formats:"
 
49
        for i in id:
 
50
            print i,
 
51
        sys.exit(1)
 
52
    elif o == "-i":
 
53
        verbose = 1
 
54
    elif o == "-q":
 
55
        quiet = 1
 
56
    elif o == "-v":
 
57
        verify = 1
 
58
    elif o == "-D":
 
59
        Image.DEBUG = Image.DEBUG + 1
 
60
 
 
61
def globfix(files):
 
62
    # expand wildcards where necessary
 
63
    if sys.platform == "win32":
 
64
        out = []
 
65
        for file in files:
 
66
            if glob.has_magic(file):
 
67
                out.extend(glob.glob(file))
 
68
            else:
 
69
                out.append(file)
 
70
        return out
 
71
    return files
 
72
 
 
73
for file in globfix(args):
 
74
    try:
 
75
        im = Image.open(file)
 
76
        print "%s:" % file, im.format, "%dx%d" % im.size, im.mode,
 
77
        if verbose:
 
78
            print im.info, im.tile,
 
79
        print
 
80
        if verify:
 
81
            try:
 
82
                im.verify()
 
83
            except:
 
84
                if not quiet:
 
85
                    print "failed to verify image",
 
86
                    print "(%s:%s)" % (sys.exc_type, sys.exc_value)
 
87
    except IOError, v:
 
88
        if not quiet:
 
89
            print file, "failed:", v
 
90
    except:
 
91
        import traceback
 
92
        if not quiet:
 
93
            print file, "failed:", "unexpected error"
 
94
            traceback.print_exc(file=sys.stdout)