1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-21 20:38:57 +00:00

Job spec tree: Added a common base for workloads and sections

Added "JobSpecSource" as a base class for both section tree nodes and
workload entries. This adds a common interface between them for:
 - Resolving names
 - Storing configuration
 - References to parents
 - Getting IDs out of configuration
This commit is contained in:
Sebastian Goscik 2016-08-12 10:19:51 +01:00
parent b0e500e2a8
commit df17f79142
2 changed files with 45 additions and 9 deletions

View File

@ -20,7 +20,7 @@ from wlauto.exceptions import ConfigError
from wlauto.utils.misc import (get_article, merge_config_values) from wlauto.utils.misc import (get_article, merge_config_values)
from wlauto.utils.types import (identifier, integer, boolean, from wlauto.utils.types import (identifier, integer, boolean,
list_of_strings, toggle_set) list_of_strings, toggle_set)
from wlauto.core.configuration.tree import Node from wlauto.core.configuration.tree import SectionNode
########################## ##########################
### CONFIG POINT TYPES ### ### CONFIG POINT TYPES ###

View File

@ -13,24 +13,60 @@
# limitations under the License. # limitations under the License.
class Node(object): class JobSpecSource(object):
kind = ""
def __init__(self, config, parent=None):
self.config = config
self.parent = parent
@property
def id(self):
return self.config['id']
def name(self):
raise NotImplementedError()
class WorkloadEntry(JobSpecSource):
kind = "workload"
@property
def name(self):
if self.parent.id == "global":
return 'workload "{}"'.format(self.id)
else:
return 'workload "{}" from section "{}"'.format(self.id, self.parent.id)
class SectionNode(JobSpecSource):
kind = "section"
@property
def name(self):
if self.id == "global":
return "globally specified configuration"
else:
return 'section "{}"'.format(self.id)
@property @property
def is_leaf(self): def is_leaf(self):
return not bool(self.children) return not bool(self.children)
def __init__(self, value, parent=None): def __init__(self, config, parent=None):
self.workloads = [] super(SectionNode, self).__init__(config, parent=parent)
self.parent = parent self.workload_entries = []
self.children = [] self.children = []
self.config = value
def add_section(self, section): def add_section(self, section):
new_node = Node(section, parent=self) new_node = SectionNode(section, parent=self)
self.children.append(new_node) self.children.append(new_node)
return new_node return new_node
def add_workload(self, workload): def add_workload(self, workload_config):
self.workloads.append(workload) self.workload_entries.append(WorkloadEntry(workload_config, self))
def descendants(self): def descendants(self):
for child in self.children: for child in self.children: