Exemple #1
0
def __syntax_tree_helper(parent, item):
    """
    Tree builder helper function.

    This investigates the JSON nodes and builds the proper input file tree for MooseDocs.
    """

    if item is None:
        return

    if 'actions' in item:
        for key, action in item['actions'].iteritems():
            if ('parameters' in action) and action['parameters'] and \
            ('isObjectAction' in action['parameters']):
                MooseObjectActionNode(parent, key, action)
            else:
                ActionNode(parent, key, action)

    if 'star' in item:
        __syntax_tree_helper(parent, item['star'])

    if ('types' in item) and item['types']:
        for key, obj in item['types'].iteritems():
            __add_moose_object_helper(parent, key, obj)

    if ('subblocks' in item) and item['subblocks']:
        for k, v in item['subblocks'].iteritems():
            node = SyntaxNode(parent, k)
            __syntax_tree_helper(node, v)

    if ('subblock_types' in item) and item['subblock_types']:
        for k, v in item['subblock_types'].iteritems():
            __add_moose_object_helper(parent, k, v)
Exemple #2
0
def app_syntax(exe,
               remove=None,
               allow_test_objects=False,
               hide=None,
               alias=None):
    """
    Creates a tree structure representing the MooseApp syntax for the given executable.
    """
    common.check_type('exe', exe, str)
    common.check_type('remove', remove, (type(None), dict, list, set))
    common.check_type('hide', hide, (type(None), dict, list, set))
    common.check_type('allow_test_objects', allow_test_objects, bool)

    try:
        raw = mooseutils.runExe(exe, ['--json', '--allow-test-objects'])
        raw = raw.split('**START JSON DATA**\n')[1]
        raw = raw.split('**END JSON DATA**')[0]
        tree = json.loads(raw, object_pairs_hook=collections.OrderedDict)
        raw = mooseutils.runExe(exe, ['--registry-hit'])
        raw = raw.split('### START REGISTRY DATA ###\n')[1]
        raw = raw.split('### END REGISTRY DATA ###')[0]
        reg = mooseutils.hit_load(raw)

    except Exception as e:  #pylint: disable=broad-except
        LOG.error("Failed to execute the MOOSE executable '%s':\n%s", exe,
                  e.message)
        sys.exit(1)

    root = SyntaxNode(None, '')
    for key, value in tree['blocks'].iteritems():
        node = SyntaxNode(root, key)
        __syntax_tree_helper(node, value)

    hidden = set()
    if isinstance(hide, dict):
        for value in hide.itervalues():
            hidden.update(value)
    elif isinstance(hide, (list, set)):
        hidden.update(hide)

    if hidden:
        for node in anytree.PreOrderIter(root):
            if node.fullpath in hidden:
                node.hidden = True

    #TODO: When the new registration methods are added to the --json dump, this will not be needed.
    # Add groups from --registry-hit output
    object_groups = collections.defaultdict(set)
    action_groups = collections.defaultdict(set)

    for node in reg.children[0].children[0]:
        object_groups[node['name']].add(node['label'].replace('App', ''))

    for node in reg.children[0].children[1]:
        action_groups[node['name']].add(node['label'].replace('App', ''))
        action_groups[node['class']].add(node['label'].replace('App', ''))

    for node in anytree.PreOrderIter(root):
        if isinstance(node, MooseObjectNode):
            node._groups.update(object_groups[node.name])  #pylint: disable=protected-access
        elif isinstance(node, ActionNode):
            node._groups.update(action_groups[node.name])  #pylint: disable=protected-access
            for task in node.tasks:
                node._groups.update(action_groups[task])  #pylint: disable=protected-access

    # Remove
    removed = set()
    if isinstance(remove, dict):
        for value in remove.itervalues():
            removed.update(value)
    elif isinstance(remove, (list, set)):
        removed.update(remove)

    if removed:
        for node in anytree.PreOrderIter(root):
            if any(n.fullpath == prefix for n in node.path
                   for prefix in removed):
                node.removed = True

    if not allow_test_objects:
        for node in anytree.PreOrderIter(root):
            if all([group.endswith('Test') for group in node.groups]):
                node.removed = True

    # Alias
    if alias:
        for node in anytree.PreOrderIter(root):
            for k, v in alias.iteritems():
                if node.fullpath == k:
                    node.alias = unicode(v)

    return root
Exemple #3
0
def app_syntax(exe,
               remove=None,
               allow_test_objects=False,
               hide=None,
               alias=None):
    """
    Creates a tree structure representing the MooseApp syntax for the given executable.
    """
    common.check_type('exe', exe, str)
    common.check_type('remove', remove, (type(None), dict, list, set))
    common.check_type('hide', hide, (type(None), dict, list, set))
    common.check_type('allow_test_objects', allow_test_objects, bool)

    try:
        raw = mooseutils.runExe(exe, ['--json', '--allow-test-objects'])
        raw = raw.split('**START JSON DATA**\n')[1]
        raw = raw.split('**END JSON DATA**')[0]
        tree = json.loads(raw, object_pairs_hook=collections.OrderedDict)

    except Exception as e:  #pylint: disable=broad-except
        LOG.error("Failed to execute the MOOSE executable '%s':\n%s", exe,
                  e.message)
        sys.exit(1)

    root = SyntaxNode(None, '')
    for key, value in tree['blocks'].iteritems():
        node = SyntaxNode(root, key)
        __syntax_tree_helper(node, value)

    hidden = set()
    if isinstance(hide, dict):
        for value in hide.itervalues():
            hidden.update(value)
    elif isinstance(hide, (list, set)):
        hidden.update(hide)

    if hidden:
        for node in anytree.PreOrderIter(root):
            if node.fullpath in hidden:
                node.hidden = True

    # Remove
    removed = set()
    if isinstance(remove, dict):
        for value in remove.itervalues():
            removed.update(value)
    elif isinstance(remove, (list, set)):
        removed.update(remove)

    if removed:
        for node in anytree.PreOrderIter(root):
            if any(n.fullpath == prefix for n in node.path
                   for prefix in removed):
                node.removed = True

    if not allow_test_objects:
        for node in anytree.PreOrderIter(root):
            if node.groups and all(
                [group.endswith('TestApp') for group in node.groups]):
                node.removed = True

    # Alias
    if alias:
        for node in anytree.PreOrderIter(root):
            for k, v in alias.iteritems():
                if node.fullpath == k:
                    node.alias = unicode(v)

    return root
Exemple #4
0
def app_syntax(exe, remove=None, allow_test_objects=False, hide=None, alias=None):
    """
    Creates a tree structure representing the MooseApp syntax for the given executable.
    """
    common.check_type('exe', exe, str)
    common.check_type('remove', remove, (type(None), dict, list, set))
    common.check_type('hide', hide, (type(None), dict, list, set))
    common.check_type('allow_test_objects', allow_test_objects, bool)

    try:
        raw = mooseutils.runExe(exe, ['--json', '--allow-test-objects'])
        raw = raw.split('**START JSON DATA**\n')[1]
        raw = raw.split('**END JSON DATA**')[0]
        tree = json.loads(raw, object_pairs_hook=collections.OrderedDict)

    except Exception as e: #pylint: disable=broad-except
        LOG.error("Failed to execute the MOOSE executable '%s':\n%s", exe, e.message)
        sys.exit(1)

    root = SyntaxNode('', None)
    for key, value in tree['blocks'].iteritems():
        node = SyntaxNode(key, root)
        __syntax_tree_helper(node, value)

    hidden = set()
    if isinstance(hide, dict):
        for value in hide.itervalues():
            hidden.update(value)
    elif isinstance(hide, (list, set)):
        hidden.update(hide)

    if hidden:
        for node in anytree.PreOrderIter(root):
            if node.fullpath in hidden:
                node.hidden = True

    # Remove
    removed = set()
    if isinstance(remove, dict):
        for value in remove.itervalues():
            removed.update(value)
    elif isinstance(remove, (list, set)):
        removed.update(remove)

    if removed:
        for node in anytree.PreOrderIter(root):
            if any(n.fullpath == prefix for n in node.path for prefix in removed):
                node.removed = True

    if not allow_test_objects:
        for node in anytree.PreOrderIter(root):
            if node.groups and all([group.endswith('TestApp') for group in node.groups]):
                node.removed = True

    # Alias
    if alias:
        for node in anytree.PreOrderIter(root):
            for k, v in alias.iteritems():
                if node.fullpath == k:
                    node.alias = unicode(v)

    # Remove <RESIDUAL>
    for node in anytree.PreOrderIter(root):
        if node.name.endswith('<RESIDUAL>'):
            node.alias = node.fullpath
            node.name = node.name[:-10]

    return root