Package mbuild :: Module plan
[frames] | no frames]

Source Code for Module mbuild.plan

 1  # -*- python -*- 
 2  #BEGIN_LEGAL 
 3  # 
 4  #Copyright (c) 2016 Intel Corporation 
 5  # 
 6  #  Licensed under the Apache License, Version 2.0 (the "License"); 
 7  #  you may not use this file except in compliance with the License. 
 8  #  You may obtain a copy of the License at 
 9  # 
10  #      http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  #  Unless required by applicable law or agreed to in writing, software 
13  #  distributed under the License is distributed on an "AS IS" BASIS, 
14  #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  #  See the License for the specific language governing permissions and 
16  #  limitations under the License. 
17  #   
18  #END_LEGAL 
19   
20  """Intermediate data structure produced by builders and sent to the 
21  dependence directed acyclic graph (DAG) that sequences execution. 
22   
23  Users who create their own builders to call python functions should emit 
24  an plan_t object and add it to the DAG. 
25  """ 
26   
27 -class plan_t(object):
28 """ 29 An object that the builders create and is passed to the DAG L{dag_t} to 30 order the tasks. This is used exclusively to create 31 L{command_t}'s. 32 """
33 - def __init__(self, command, args=None, env=None, input=None, output=None, name=None):
34 """ 35 Create an input record for the L{dag_t} describing a 36 command. The command can be a string to execute or a python 37 function or a list of strings and python functions. The python 38 function will be passed two arguments: args and env. args is 39 typically a list, but could be anything. 40 41 The input and output lists of files are used by the L{dag_t} to 42 order this command relative to other commands. 43 44 When the command is a python function, the python function is 45 called with two arguments: args and an env of type 46 L{env_t}. The args can be anything but are typically the 47 inputs to the python function and any information required to 48 generate the corresponding outputs. The python functions return 49 a 2-typle (retcode, stdout). 50 51 The input list: When the command is a python function, the 52 plan_t's input list contains at least the input files names 53 passed via args variable. The input list can be a superset 54 containing more stuff that might trigger the command 55 execution. 56 57 If the command does not produce a specific output, you can 58 specify a dummy file name to allow sequencing relative to 59 other commands. 60 61 @type command: string or python function or a list 62 @param command: string or python function. 63 64 @type args: list 65 @param args: (optional) arguments to the command if it is a python function 66 67 @type env: L{env_t} 68 @param env: (optional) an environment to pass to the python function 69 70 @type input: list 71 @param input: (optional) files upon which this command depends. 72 73 @type output: list 74 @param output: (optional) files which depend on this command. 75 76 @type name: string 77 @param name: (optional) short name to be used to identify the work/task 78 """ 79 self.command = command 80 self.args = args 81 self.env = env 82 self.input = input 83 self.output = output 84 self.name = name
85
86 - def __str__(self):
87 s = [] 88 if self.name: 89 s.append('NAME: ' + str(self.name)) 90 s.append('CMD: ' + str(self.command)) 91 s.append('INPUT: ' + str(self.input)) 92 s.append('OUTPUT: ' + str(self.output)) 93 return " ".join(s)
94