Exemple #1
0
    def nodes(self):
        nodes = OrderedDict()
        linemap = {}
        for line in self.section.nodes:
            try:
                nodename, node = find_obj(line, True)
            except (AttributeError, ModuleNotFoundError):
                raise ConfigError(
                    f'Collection {self.name!r} cannot find node {line!r}')

            node = Node.from_dag_node(node)

            if node in linemap:
                raise ConfigError(
                    f'Collection {self.name!r} node {line!r} already listed as {linemap[node]!r}'
                )
            linemap[node] = line
            if nodename in nodes:
                raise ConfigError(
                    f'Collection {self.name!r} duplicate name {nodename!r}')
            if not node.schema:
                raise ConfigError(
                    f'Collection {self.name!r} node {line!r} does not define schema'
                )
            nodes[nodename] = node
        return nodes
Exemple #2
0
 def nodes(self):
     nodes = OrderedDict()
     linemap = {}
     for line in self.section.nodes:
         nodename, node = find_obj(line, True)
         if node in linemap:
             raise ConfigError(
                 self.section, 'nodes',
                 '%s already listed as %s' % (line, linemap[node]))
         linemap[node] = line
         if nodename in nodes:
             raise ConfigError(self.section, 'nodes',
                               'duplicate name %s' % (nodename, ))
         nodes[nodename] = node
     return nodes
Exemple #3
0
 def detail_summary_widgets(self):
     nodes = self.nodes
     try:
         return [nodes[x] for x in self.section.detail_summary_widgets]
     except KeyError as exc:
         raise ConfigError(
             f'Collection {self.name!r}: unknown node {exc} in detail_summary_widgets'
         )
 def nodes(self):
     nodes = OrderedDict()
     linemap = {}
     for line in self.section.nodes:
         try:
             nodename, node = utils.find_obj(line, True)
         except AttributeError:
             raise ConfigError(self.section, 'nodes', 'Cannot find node %s' % line)
         if node in linemap:
             raise ConfigError(self.section, 'nodes',
                               '%s already listed as %s' %
                               (line, linemap[node]))
         linemap[node] = line
         if nodename in nodes:
             raise ConfigError(self.section, 'nodes', 'duplicate name %s' % (nodename,))
         if not node.schema:
             raise ConfigError(self.section, 'nodes', '%s does not define a schema!' % (line,))
         nodes[nodename] = node
     return nodes
 def sortorder(self):
     listing_sort = self.section.listing_sort
     try:
         sortorder = listing_sort[1]
         orders = ['ascending', 'descending']
         return {x: x for x in orders}[sortorder]
     except IndexError:
         return 'ascending'
     except KeyError:
         raise ConfigError(self.section, 'listing_sort',
                           '{} not in [{}]'.format(sortorder, ', '.join(orders)))
Exemple #6
0
 def sortorder(self):
     listing_sort = self.section.listing_sort
     try:
         sortorder = listing_sort[1]
         orders = ['ascending', 'descending']
         return {x: x for x in orders}[sortorder]
     except IndexError:
         return 'ascending'
     except KeyError:
         raise ConfigError(
             f'Collection {self.name!r} {sortorder} not in {orders}')
Exemple #7
0
def postprocess_functree(name, arguments):
    if name == 'rows':
        if len(arguments) == 0:
            return {}

        try:
            field, default = arguments
        except ValueError:
            raise ConfigError(
                "'rows' takes zero or two arguments, column name and default value",
            ) from None

        return ('map', {}, ('idx', field), default)

    return (name, *(postprocess_functree(*x) for x in arguments))
Exemple #8
0
 def summary_items(self):
     summary = []
     for line in self.section.listing_summary:
         item = make_summary_item(line)
         dct = item._asdict()
         functree = parse_function(item.function)
         try:
             functree = postprocess_functree(*functree)
         except ConfigError as exc:
             raise ConfigError(
                 f'Collection {self.name!r} listing_summary: {exc}'
             ) from None
         dct['function'] = functree
         summary.append(dct)
     return summary