src/reportlab/graphics/samples/runall.py
author robin
Tue, 19 Nov 2013 13:50:34 +0000
branchpy33
changeset 3794 398ea04239b5
parent 3721 0c93dd8ff567
child 4709 1dcf7b3f7127
permissions -rw-r--r--
string module usage minimization
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 inspect
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     6
import types
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     7
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
     8
def moduleClasses(mod):
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
     9
    def P(obj, m=mod.__name__, CT=type):
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    10
        return (type(obj)==CT and obj.__module__==m)
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    11
    try:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    12
        return inspect.getmembers(mod, P)[0][1]
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    13
    except:
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    14
        return None
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    15
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    16
def getclass(f):
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    17
    return moduleClasses(__import__(f))
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    18
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    19
def run(format, VERBOSE=0):
3794
398ea04239b5 string module usage minimization
robin
parents: 3721
diff changeset
    20
    formats = format.split( ',')
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    21
    for i in range(0, len(formats)):
3794
398ea04239b5 string module usage minimization
robin
parents: 3721
diff changeset
    22
        formats[i] == formats[i].strip().lower()
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    23
    allfiles = glob.glob('*.py')
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    24
    allfiles.sort()
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    25
    for fn in allfiles:
3794
398ea04239b5 string module usage minimization
robin
parents: 3721
diff changeset
    26
        f = fn.split('.')[0]
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    27
        c = getclass(f)
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    28
        if c != None:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    29
            print(c.__name__)
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    30
            try:
1907
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    31
                for fmt in formats:
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    32
                    if fmt:
12364c11185d Fix a typo.
johnprecedo
parents: 1905
diff changeset
    33
                        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
    34
                        if VERBOSE:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    35
                            print("  %s.%s" % (c.__name__, fmt))
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    36
            except:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    37
                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
    38
89c74d68f1f5 Directory of samples which mimic the standard Excel chart classes.
johnprecedo
parents:
diff changeset
    39
if __name__ == "__main__":
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    40
    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
    41
        run('pdf,pict,png')
1862
11f6cd4b0f07 Drawings can now do asString(format)
andy_robinson
parents: 1859
diff changeset
    42
    else:
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    43
        try:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    44
            if sys.argv[1] == "-h":
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    45
                print('usage: runall.py [FORMAT] [-h]')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    46
                print('   if format is supplied is should be one or more of pdf,gif,eps,png etc')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    47
                print('   if format is missing the following formats are assumed: pdf,pict,png')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    48
                print('   -h prints this message')
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    49
            else:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    50
                t = sys.argv[1:]
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    51
                for f in t:
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    52
                    run(f)
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    53
        except:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    54
            print('usage: runall.py [FORMAT][-h]')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    55
            print('   if format is supplied is should be one or more of pdf,gif,eps,png etc')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    56
            print('   if format is missing the following formats are assumed: pdf,pict,png')
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 2964
diff changeset
    57
            print('   -h prints this message')
1905
c4888fcec7b6 Now allows multiple formats and if you don't specify any will assume you
johnprecedo
parents: 1862
diff changeset
    58
            raise