source: trunk/builder/scripts/templates/python.tl @ 5606

Last change on this file since 5606 was 5606, checked in by ldelgass, 9 years ago

merge r5602 from 1.3 branch

File size: 3.3 KB
Line 
1# ----------------------------------------------------------------------
2#  LANGUAGE:  Python API
3# ======================================================================
4#  AUTHOR:  Michael McLennan, Purdue University
5#  Copyright (c) 2004-2015  HUBzero Foundation, LLC
6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10language "Python" {
11  extension ".py"
12  command {python @tool/@@FILENAME@@ @driver}
13
14  main {# ----------------------------------------------------------------------
15#  MAIN PROGRAM - generated by the Rappture Builder
16# ----------------------------------------------------------------------
17import Rappture
18import sys
19import numpy as np
20
21# uncomment these to redirect stdout and stderr
22# to files for debugging.
23#sys.stderr = open('debug.err', 'w')
24#sys.stdout = open('debug.out', 'w')
25
26# open the XML file containing the run parameters
27io = Rappture.PyXml(sys.argv[1])
28
29#########################################################
30# Get input values from Rappture
31#########################################################
32@@INPUTS@@
33
34#########################################################
35#  Add your code here for the main body of your program
36#########################################################
37
38# spit out progress messages as you go along...
39Rappture.Utils.progress(0, "Starting...")
40Rappture.Utils.progress(5, "Loading data...")
41Rappture.Utils.progress(50, "Half-way there")
42Rappture.Utils.progress(100, "Done")
43
44#########################################################
45# Save output values back to Rappture
46#########################################################
47@@OUTPUTS@@
48
49io.close()
50sys.exit()
51}
52
53  input boolean {
54    code "\n# get input value for $path"
55    code "# returns value as string \"yes\" or \"no\""
56    code "$id = io\['$path.current'\].value == 'yes'"
57  }
58  input image {
59    code "\n# get input value for $path"
60    code "# returns base64-encoded image data"
61    code "$id = io\['$path.current'\].value"
62  }
63  input integer {
64    code "\n# get input value for $path"
65    code "$id = int(io\['$path.current'\].value)"
66  }
67  input number {
68    set units [attr get units]
69    if {$units ne ""} {
70      code "\n# get input value for $path and convert to $units"
71      code "str = io\['$path.current'\].value"
72      code "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")"
73    } else {
74      code "\n# get input value for $path"
75      code "$id = float(io\['$path.current'\].value)"
76    }
77  }
78  input * {
79    code "\n# get input value for $path"
80    code "$id = io\['$path.current'\].value"
81  }
82
83  output curve {
84    code "\n# save output value for $path"
85    code "# x and y should be lists or arrays -- modify as needed"
86    code "io\['$path.component.xy'\] = (x, y)"
87  }
88  output histogram {
89    code "\n# save output value for $path"
90    code "# x and y should be lists or arrays -- modify as needed"
91    code "# (x,h,w) = x-coord, height of bar, and width of bar"
92    code "io\['$path.component.xhw'\] = (x, h, w)"
93  }
94  output image {
95    code "\n# save output value for $path"
96    code "# data should be base64-encoded image data"
97    code "io\['$path.current'\] = imdata"
98  }
99  output * {
100    code "\n# save output value for $path"
101    code "io\['$path.current'\] = $id"
102  }
103}
Note: See TracBrowser for help on using the repository browser.