reportlab/graphics/samples/runall.py
author johnprecedo
Thu, 17 Apr 2003 12:30:27 +0000
changeset 1905 c4888fcec7b6
parent 1862 11f6cd4b0f07
child 1907 12364c11185d
permissions -rw-r--r--
Now allows multiple formats and if you don't specify any will assume you want PDF, PICT and PNG.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1859
89c74d68f1f5 Directory of samples which mimic the standard Excel chart classes.
johnprecedo
parents:
diff changeset
     1
# runs all the GUIedit charts in this directory - 
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:
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    32
                for f in formats:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    33
                    if f:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    34
                        c().save(formats=[f],outDir='.',fnRoot=c.__name__)
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    35
                        if VERBOSE:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    36
                            print "  %s.%s" % (c.__name__, f)
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
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    60