Commit e8222be6 authored by payno's avatar payno

Merge branch 'test_moml' into 'master'

Test moml

Closes #6

See merge request !1
parents 1ba331cc cb2098be
# Build files
# Cython generated files
# Editor files
# Windows temp files
# PyLint, Coverage reports
# Tmp files
# notebook checkpoints
# notebook nbconvert
# octave files

40.8 KB | W: | H:


44.6 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
...@@ -61,8 +61,8 @@ class Link(object): ...@@ -61,8 +61,8 @@ class Link(object):
_JSON_SINK_NODE_ID = 'sink_node_id' _JSON_SINK_NODE_ID = 'sink_node_id'
_JSON_LINK_ID = 'link_id' _JSON_LINK_ID = 'link_id'
def __init__(self, source_node, sink_node, source_channel, sink_channel, def __init__(self, source_node, sink_node, source_channel='default',
id=None): sink_channel='default', id=None): = get_next_link_free_id() if id is None else id = get_next_link_free_id() if id is None else id
if isinstance(source_node, int): if isinstance(source_node, int):
self.source_node_id = source_node self.source_node_id = source_node
...@@ -86,6 +86,7 @@ class Node(object): ...@@ -86,6 +86,7 @@ class Node(object):
_JSON_PROCESS_PT = 'process_pt' _JSON_PROCESS_PT = 'process_pt'
_JSON_ID = 'id' _JSON_ID = 'id'
_JSON_PROPERTIES = 'properties' _JSON_PROPERTIES = 'properties'
_JSON_ERROR_HANDLER = 'error_handler'
def __init__(self, processing_pt, id=None, properties=None, def __init__(self, processing_pt, id=None, properties=None,
error_handler=None): error_handler=None):
...@@ -209,11 +210,19 @@ class Node(object): ...@@ -209,11 +210,19 @@ class Node(object):
:return: json description of the node :return: json description of the node
:rtype: dict :rtype: dict
""" """
return { res = {
self._JSON_PROCESS_PT: self.process_pt, self._JSON_PROCESS_PT: self.process_pt,
self._JSON_ID:, self._JSON_ID:,
} }
return res
def _get_error_handler_json(self):
error_handler_json = self._error_handler.to_json() if self._error_handler else {}
return {
self._JSON_ERROR_HANDLER: error_handler_json,
@staticmethod @staticmethod
def from_json(json_data): def from_json(json_data):
...@@ -264,3 +273,16 @@ class WorkflowException(Exception): ...@@ -264,3 +273,16 @@ class WorkflowException(Exception):
self.errorMessage = msg self.errorMessage = msg = data = data
self.traceBack = traceBack self.traceBack = traceBack
class ErrorHandler(Node):
def __init__(self, processing_pt, id=None, properties=None):
super(ErrorHandler, self).__init__(processing_pt=processing_pt, id=id,
def _get_error_handler_json(self):
return {}
\ No newline at end of file
...@@ -36,6 +36,7 @@ import pprint ...@@ -36,6 +36,7 @@ import pprint
import base64 import base64
import pickle import pickle
import logging import logging
import typing
from .node import Node from .node import Node
from .link import Link from .link import Link
from ast import literal_eval from ast import literal_eval
...@@ -47,15 +48,16 @@ class Scheme(object): ...@@ -47,15 +48,16 @@ class Scheme(object):
""" """
class to define a workflow scheme from nodes and links class to define a workflow scheme from nodes and links
:param list nodes: :param typing.Iterable nodes: set of Node
:param list links: :param typing.Iterable list links: set of Link
""" """
_JSON_DESCRIPTION = 'description' _JSON_DESCRIPTION = 'description'
_JSON_TITLE = 'title' _JSON_TITLE = 'title'
_JSON_NODES = 'nodes' _JSON_NODES = 'nodes'
_JSON_LINKS = 'links' _JSON_LINKS = 'links'
def __init__(self, nodes=None, links=None, description=None, title=None): def __init__(self, nodes:typing.Iterable=None, links:typing.Iterable=None,
description: str=None, title: str=None):
self._reset(nodes=nodes, links=links, description=description, self._reset(nodes=nodes, links=links, description=description,
title=title) title=title)
...@@ -116,19 +118,19 @@ class Scheme(object): ...@@ -116,19 +118,19 @@ class Scheme(object):
res.append(node) res.append(node)
return res return res
def save_to(self, output_file): def save_to(self, output_file: str):
""" """
Save the scheme as an xml formated file to `stream` Save the scheme as an xml formated file to `stream`
:param output_file: name of the output file. :param output_file: name of the output file.
:type: str :type: str
""" """
if output_file.lower.endswith('.json'): if output_file.lower().endswith('.json'):
self.save_as_json(output_file) self.save_as_json(output_file)
else: else:
self.save_as_xml(output_file) self.save_as_xml(output_file)
def save_as_xml(self, output_file): def save_as_xml(self, output_file: str):
""" """
save current scheme to a default xml format save current scheme to a default xml format
...@@ -139,7 +141,7 @@ class Scheme(object): ...@@ -139,7 +141,7 @@ class Scheme(object):
tree.write(output_file) tree.write(output_file)
def save_as_json(self, output_file): def save_as_json(self, output_file: str):
""" """
save current scheme to a default json format save current scheme to a default json format
...@@ -203,6 +205,12 @@ class Scheme(object): ...@@ -203,6 +205,12 @@ class Scheme(object):
return links return links
def to_json(self): def to_json(self):
Convert scheme to json
:return: json dict
:rtype: dict
return { return {
self._JSON_DESCRIPTION: self.description, self._JSON_DESCRIPTION: self.description,
self._JSON_TITLE: self.title, self._JSON_TITLE: self.title,
...@@ -211,7 +219,15 @@ class Scheme(object): ...@@ -211,7 +219,15 @@ class Scheme(object):
} }
@staticmethod @staticmethod
def from_json_file(json_file_path): def from_json_file(json_file_path: str):
Create and load Scheme from a json file
:param str json_file_path: json file
:return: Scheme fitting the json description
:rtype: Scheme
:raises: ValueError if file not found or invalid
scheme = Scheme() scheme = Scheme()
try: try:
scheme.load_from_json_file(json_file_path) scheme.load_from_json_file(json_file_path)
...@@ -221,7 +237,7 @@ class Scheme(object): ...@@ -221,7 +237,7 @@ class Scheme(object):
else: else:
return scheme return scheme
def load_from_json_file(self, json_file_path): def load_from_json_file(self, json_file_path: str):
""" """
:param str json_file_path: path to the json file containing the scheme :param str json_file_path: path to the json file containing the scheme
...@@ -437,14 +453,47 @@ class Scheme(object): ...@@ -437,14 +453,47 @@ class Scheme(object):
node.load_handlers() node.load_handlers()
def contains_control_nodes(nodes_list): class SubScheme(Scheme, Node):
Define a sub-scheme of the workflow (or subworkflow). SubScheme are
as Scheme expect that they are not 'root'.
:param nodes: set of Node
:type: typing.Iterable
:param links: set of Node
:type: typing.Iterable
:param description: description of the subscheme
:type: str
:param error_handler: ErrorHandler
def __init__(self, nodes: typing.Iterable, links: typing.Iterable,
description: str=None, error_handler=None):
Node.__init__(self, processing_pt=None, error_handler=error_handler)
Scheme.__init__(self, nodes=nodes, links=links, title='',
def contains_control_nodes(nodes_list: typing.Iterable):
Return the list of the 'control' nodes.
:param typing.Iterable nodes_list:
for _node in nodes_list: for _node in nodes_list:
if _node.endless or contains_control_nodes(_node.upstream_nodes): if _node.endless or contains_control_nodes(_node.upstream_nodes):
return True return True
return False return False
def loads(string, format): def loads(string: str, format: str) -> object:
"""load stream from the given format.
:param str string: stream to load
:param str format: format
:return: object contained in the stream
:rtype: object
if format == "literal": if format == "literal":
return literal_eval(string) return literal_eval(string)
elif format == "json": elif format == "json":
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment