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
build
dist
ESRF_Orange3_Add_on.egg-info
Orange/version.py
doc/build
*.so
*.pyd
*.pyc
MANIFEST
# Cython generated files
__pycache__
# Editor files
.idea
.idea/*
*~
.project
.pydevproject
.settings/*
.DS_Store
# Windows temp files
Thumbs.db
# PyLint, Coverage reports
.pylint_cache/*
htmlcov/*
# Tmp files
*tmp
tmp*
*.edf
*.info
*.cfg
*.xml
*.db
*.tar.bz2
dataset/
datasets/
*.egg-info*
# notebook checkpoints
*.ipynb_checkpoints/
# notebook nbconvert
*.nbconvert.ipynb
# octave files
octave-workspace
doc/scheme_uml_class_diag.png

40.8 KB | W: | H:

doc/scheme_uml_class_diag.png

44.6 KB | W: | H:

doc/scheme_uml_class_diag.png
doc/scheme_uml_class_diag.png
doc/scheme_uml_class_diag.png
doc/scheme_uml_class_diag.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -61,8 +61,8 @@ class Link(object):
_JSON_SINK_NODE_ID = 'sink_node_id'
_JSON_LINK_ID = 'link_id'
def __init__(self, source_node, sink_node, source_channel, sink_channel,
id=None):
def __init__(self, source_node, sink_node, source_channel='default',
sink_channel='default', id=None):
self.id = get_next_link_free_id() if id is None else id
if isinstance(source_node, int):
self.source_node_id = source_node
......
......@@ -86,6 +86,7 @@ class Node(object):
_JSON_PROCESS_PT = 'process_pt'
_JSON_ID = 'id'
_JSON_PROPERTIES = 'properties'
_JSON_ERROR_HANDLER = 'error_handler'
def __init__(self, processing_pt, id=None, properties=None,
error_handler=None):
......@@ -209,11 +210,19 @@ class Node(object):
:return: json description of the node
:rtype: dict
"""
return {
res = {
self._JSON_PROCESS_PT: self.process_pt,
self._JSON_ID: self.id,
self._JSON_PROPERTIES: self.properties,
}
res.update(self._get_error_handler_json())
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
def from_json(json_data):
......@@ -264,3 +273,16 @@ class WorkflowException(Exception):
self.errorMessage = msg
self.data = data
self.traceBack = traceBack
class ErrorHandler(Node):
'''
TODO
'''
def __init__(self, processing_pt, id=None, properties=None):
super(ErrorHandler, self).__init__(processing_pt=processing_pt, id=id,
properties=properties,
error_handler=None)
def _get_error_handler_json(self):
return {}
\ No newline at end of file
......@@ -36,6 +36,7 @@ import pprint
import base64
import pickle
import logging
import typing
from .node import Node
from .link import Link
from ast import literal_eval
......@@ -47,15 +48,16 @@ class Scheme(object):
"""
class to define a workflow scheme from nodes and links
:param list nodes:
:param list links:
:param typing.Iterable nodes: set of Node
:param typing.Iterable list links: set of Link
"""
_JSON_DESCRIPTION = 'description'
_JSON_TITLE = 'title'
_JSON_NODES = 'nodes'
_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,
title=title)
......@@ -116,19 +118,19 @@ class Scheme(object):
res.append(node)
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`
:param output_file: name of the output file.
:type: str
"""
if output_file.lower.endswith('.json'):
if output_file.lower().endswith('.json'):
self.save_as_json(output_file)
else:
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
......@@ -139,7 +141,7 @@ class Scheme(object):
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
......@@ -203,6 +205,12 @@ class Scheme(object):
return links
def to_json(self):
"""
Convert scheme to json
:return: json dict
:rtype: dict
"""
return {
self._JSON_DESCRIPTION: self.description,
self._JSON_TITLE: self.title,
......@@ -211,7 +219,15 @@ class Scheme(object):
}
@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()
try:
scheme.load_from_json_file(json_file_path)
......@@ -221,7 +237,7 @@ class Scheme(object):
else:
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
......@@ -437,14 +453,47 @@ class Scheme(object):
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='',
description=description)
def contains_control_nodes(nodes_list: typing.Iterable):
"""
Return the list of the 'control' nodes.
:param typing.Iterable nodes_list:
:return:
"""
for _node in nodes_list:
if _node.endless or contains_control_nodes(_node.upstream_nodes):
return True
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":
return literal_eval(string)
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