pyxb_builder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 28
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B build_xmlschema_wrappers() 0 44 6
1
from SCons.Script import *
2
3
4
def build_xmlschema_wrappers(target, source, env):
5
    '''
6
        SCons needs real file names, so the main script must use proper file
7
        name suffixes for the Python file.
8
9
        PyXBGen, however, wants no .py suffix, otherwise modules are generated.
10
        Therefore, we strip the suffix before calling PyXBGen.
11
12
        Wee also need to use a proper "--binding-root" parameter, otherwise
13
        the path names become part of the generated Python module names
14
    '''
15
16
    sources = [str(src) for src in source]
17
18
    # Targets are the Python modules to be generated
19
    # If they all share the same directory prefix, then strip it and
20
    # use it as binding root. This gives relative imports in the generated
21
    # Python code, which is nicer
22
    prefix = ""
23
    all_same_prefix = True
24
    for t in target:
25
        new_prefix = str(t).rsplit('/', 1)[0]
26
        if new_prefix != prefix:
27
            if prefix == "":
28
                prefix = new_prefix
29
            else:
30
                all_same_prefix = False
31
        prefix = new_prefix
32
33
    if all_same_prefix:
34
        targets = [str(trg).rsplit('/', 1)[1].rsplit('.')[0] for trg in target]
35
        modulespec = ['-u %s -m %s' % (src, trg)
36
                      for src, trg in zip(sources, targets)]
37
        cmdline = 'pyxbgen --binding-root=' + \
38
            prefix + ' ' + ' '.join(modulespec)
39
    else:
40
        targets = [str(trg).rsplit('.')[0] for trg in target]
41
        modulespec = ['-u %s -m %s' % (src, trg)
42
                      for src, trg in zip(sources, targets)]
43
        cmdline = 'pyxbgen ' + ' '.join(modulespec)
44
45
    print cmdline
46
    if os.system(cmdline) != 0:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable os does not seem to be defined.
Loading history...
47
        raise Exception('Execution of pyxbgen failed.')
48
49
50
# Define Builder for Django config file from settings INI file
51
pyxbbuilder = Builder(action=build_xmlschema_wrappers)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Builder does not seem to be defined.
Loading history...
52