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