src/reportlab/graphics/samples/runall.py
author rgbecker
Wed, 03 Sep 2008 16:10:51 +0000
changeset 2964 32352db0d71e
parent 2200 reportlab/graphics/samples/runall.py@be0cfccc662a
child 3721 0c93dd8ff567
permissions -rw-r--r--
reportlab-2.2: second stage of major re-org
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2200
be0cfccc662a Fixed up tabs and whitespace in all source files
andy_robinson
parents: 1907
diff changeset
     1
# runs all the GUIedit charts in this directory -
1859
89c74d68f1f5 Directory of samples which mimic the standard Excel chart classes.
johnprecedo
parents:
diff changeset
     2
# makes a PDF sample for eaxh existing chart type
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     3
import sys
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     4
import glob
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     5
import string
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     6
import inspect
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     7
import types
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     8
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     9
def moduleClasses(mod):
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    10
    def P(obj, m=mod.__name__, CT=types.ClassType):
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    11
        return (type(obj)==CT and obj.__module__==m)
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    12
    try:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    13
        return inspect.getmembers(mod, P)[0][1]
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    14
    except:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    15
        return None
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    16
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    17
def getclass(f):
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    18
    return moduleClasses(__import__(f))
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    19
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    20
def run(format, VERBOSE=0):
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    21
    formats = string.split(format, ',')
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    22
    for i in range(0, len(formats)):
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    23
        formats[i] == string.lower(string.strip(formats[i]))
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    24
    allfiles = glob.glob('*.py')
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    25
    allfiles.sort()
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    26
    for fn in allfiles:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    27
        f = string.split(fn, '.')[0]
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    28
        c = getclass(f)
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    29
        if c != None:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    30
            print c.__name__
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    31
            try:
1907
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    32
                for fmt in formats:
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    33
                    if fmt:
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    34
                        c().save(formats=[fmt],outDir='.',fnRoot=c.__name__)
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    35
                        if VERBOSE:
1907
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    36
                            print "  %s.%s" % (c.__name__, fmt)
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    37
            except:
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    38
                print "  COULDN'T CREATE '%s.%s'!" % (c.__name__, format)
1859
89c74d68f1f5 Directory of samples which mimic the standard Excel chart classes.
johnprecedo
parents:
diff changeset
    39
89c74d68f1f5 Directory of samples which mimic the standard Excel chart classes.
johnprecedo
parents:
diff changeset
    40
if __name__ == "__main__":
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    41
    if len(sys.argv) == 1:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    42
        run('pdf,pict,png')
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    43
    else:
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    44
        try:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    45
            if sys.argv[1] == "-h":
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    46
                print 'usage: runall.py [FORMAT] [-h]'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    47
                print '   if format is supplied is should be one or more of pdf,gif,eps,png etc'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    48
                print '   if format is missing the following formats are assumed: pdf,pict,png'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    49
                print '   -h prints this message'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    50
            else:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    51
                t = sys.argv[1:]
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    52
                for f in t:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    53
                    run(f)
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    54
        except:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    55
            print 'usage: runall.py [FORMAT][-h]'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    56
            print '   if format is supplied is should be one or more of pdf,gif,eps,png etc'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    57
            print '   if format is missing the following formats are assumed: pdf,pict,png'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    58
            print '   -h prints this message'
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    59
            raise