summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/bin/generate_plan.py
blob: cdbc3bb3df1ff4a170f9350ad0ca15fa26ab15ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
import sys, os

sys.path.append (os.getenv ("DANCE_ROOT"))


def parse_args ():
    from optparse import OptionParser

    parser = OptionParser ("""usage %prog [options]
    Note that this script is very simple.  It assumes that the idl and mpc follow
    canonical and predictable patterns.""")

    parser.add_option ("-o", "--output", dest="output", action="store", type="string",
                       help="Output filename", default="Plan.cdp")
    parser.add_option ("--home", dest="homes", action="append", type="string",
                       help="Home types to be included")
    parser.add_option ("-c", "--component", dest="components", action="append",
                       type="string", help="Component types to be included")
    parser.add_option ("--homed-component", dest="homed_components", action="append",
                       type="string", help="Homed component types to be included")
    parser.add_option ("-u", "--uuid", dest="uuid", action="store",
                       type="string", help="UUID for the generated plan")
    parser.add_option ("-n", "--namespace", dest="namespace", action="store", default="",
                       type="string", help="IDL namespace any components may be in")
    
    (options, arguments) = parser.parse_args ()

    return (options, arguments)

def main ():
    (opts, args) = parse_args ()

    # compset = set (opts.homes) | set (opts.components) | set (homed_components)

    from PythonDAnCE import generator
    retval = ""
    retval += generator.header.template (opts.uuid)

    artifacts = {}
    
    if opts.namespace != "":
        opts.namespace += "_"

    #implementations
    if opts.homes is not None:
        for item in opts.homes:
            retval += generator.home_impl.template (item, opts.namespace)
            artifacts[item] = 1

    if opts.homed_components is not None:
        for item in opts.homed_components:
            retval += generator.homed_comp_impl.template (item)
            artifacts[item] = 1

    if opts.components is not None:
        for item in opts.components:
            retval += generator.comp_impl.template (item, opts.namespace)
            artifacts[item] = 1

    #instances
    if opts.homes is not None:
        for item in opts.homes:
            retval += generator.home_inst.template (item)
    
    if opts.homed_components is not None:
        for item in opts.homed_components:
            retval += generator.homed_comp_inst.template (item)
            
    if opts.components is not None:
        for item in opts.components:
            retval += generator.comp_inst.template (item, "", "", "NodeOne")
        
    #artifacts
    if artifacts is not None:
        for item in artifacts.keys():
            retval += generator.artifact.template(item)

    retval += generator.footer.template ()
    
    outfile = open (opts.output, 'w')
    outfile.write (retval)
    outfile.close ()
    

if __name__ == "__main__":
    main ()