Exemplo n.º 1
0
    def test_list(self):
        Tag = xmltuple('Tag',
                       'tag', ['foo', 'bar'],
                       types={
                           'foo': int,
                           'bar': int
                       })
        List = xmllist('List', 'list', Tag)
        list_ = List([Tag(1, 2), Tag(3, 4), Tag(5, 6)])
        self.assertEqual(list_.to_xml(),
                         List.from_xml(list_.to_xml()).to_xml())

        self.assertListEqual(list_.to_object(),
                             List.from_xml(list_.to_xml()).to_object())

        List2 = xmllist('List2', 'list2', 'tag')
        list2 = List2([1, 2, 3, 4])
        self.assertEqual(list2.to_xml(),
                         List2.from_xml(list2.to_xml()).to_xml())

        List3 = xmllist('List3', 'list3', 'tag', ['id', 'foo'])
        list3 = List3([6, 66], 4, 'bar')
        self.assertEqual(list3.to_xml(),
                         List3.from_xml(list3.to_xml()).to_xml())

        self.assertGreater(len(list(list2)), len(list(list_)))
Exemplo n.º 2
0
                        types=_field_types)

SimpleField = defaultify_init(_SimpleField, 'SimpleField', **_field_defaults)

_LinkedField = xmltuple('LinkedField',
                        'linkedField', [*_field_attrs, 'linkType'], [LinkType],
                        types=_field_types)

LinkedField = defaultify_init(_LinkedField, 'LinkedField', **_field_defaults)

FormFields = xmlall('FormFields',
                    'fields',
                    simple=SimpleField,
                    linked=LinkedField)

RowNames = xmllist('RowNames', 'rows', 'rowName')

_FormGroup = xmltuple('FormGroup', 'formGroup', ['legend', 'rows'], [RowNames])

FormGroup = defaultify_init(_FormGroup, 'FormGroup', rows=lambda s: RowNames())

FormGroups = xmllist('FormGroups', 'groups', FormGroup)

_FormDescription = xmltuple('FormDescription', 'formDescription',
                            ['schema', 'tableName', 'fields', 'groups'],
                            [FormFields, FormGroups])

FormDescription = defaultify_init(_FormDescription,
                                  'FormDescription',
                                  fields=lambda s: FormFields(),
                                  groups=lambda s: FormGroups())
Exemplo n.º 3
0
    isAuto=False,
    isVisible=True,
    isRequired=False,
    linkRequired=False,
    linkMultiple=False,
    type='link',
    isUnique=False,
    linkType=lambda s: TableLinkType(TableLinkType.SIMPLE)
    if s.fkName else TableLinkType(TableLinkType.LINKED))

SortOrder = xmlenum('SortOrder', 'sort', ASC='asc', DESC='desc')

SortColumn = xmltuple('SortColumn', 'sortColumn', ['rowName', 'sort'],
                      [SortOrder])

DefaultSort = xmllist('DefaultSort', 'defaultSort', SortColumn)

TableColumns = xmlall('TableColumns',
                      'columns',
                      normal=TableColumn,
                      linked=LinkedTableColumn)

DisplayColumn = xmltuple('DisplayColumn',
                         'displayColumn',
                         ['rowName', 'linkRowName', 'isMultiple'],
                         types={'isMultiple': caster.bool_cast})

DisplayColumns = xmllist('DisplayColumns', 'displayColumns', DisplayColumn)

__Table = xmltuple(
    '__Table', 'tableEntry', [
Exemplo n.º 4
0
import logging
import os
from fnmatch import fnmatch

from ermaket.api.config import Config
from ermaket.api.system.hierarchy import Activation
from ermaket.utils import get_project_root
from ermaket.utils.xml import RootMixin, xmllist, xmltuple

__all__ = ['Script', 'ScriptList', 'Activations']

Activations = xmllist('Activations', 'activations', Activation)

Script = xmltuple('Script',
                  'script', ['path', 'activations'], [Activations],
                  kws=['id'],
                  types={'id': int})

_ScriptList = xmllist('ScriptList', 'scripts', Script)


class ScriptList(_ScriptList, RootMixin):
    def __init__(self, xml=None, scripts=None):
        self._config = Config()
        args, kwargs = self._init_root(
            xml,
            self._config.XML["ScriptListAttributes"],
            values=scripts,
        )
        super().__init__(*args, **kwargs)
Exemplo n.º 5
0
from .elements import (_element_attrs, _element_children_classes, _element_kws,
                       _element_types)
from ermaket.utils.xml import xmllist, xmltuple, xmltag

__all__ = ['Section', 'Children']

ChildId = xmltag('ChildId', 'childId', int)
Children = xmllist('Children', 'children', ChildId)
_Section = xmltuple('_Section', 'section', [*_element_attrs, 'children'],
                    [*_element_children_classes, Children], _element_kws,
                    _element_types)


class Section(_Section):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if self.children is None:
            self.children = Children()
        self._children = None

    def resolve_children(self, func):
        self._children = []
        for child_id in self.children:
            child = func(child_id)
            if child:
                self._children.append(child)
        return self.children.values

    def set_child_ids(self, ids):
        self._children = None
Exemplo n.º 6
0
SystemAction = xmlenum('SystemAction',
                       'action',
                       REGTOKEN='regToken',
                       PASSTOKEN='passToken')

Button = xmltuple('Button',
                  'button', [
                      'text', 'location', 'icon', 'column', 'tooltip',
                      'variant', 'scriptId', 'action'
                  ], [Location, SystemAction],
                  types={
                      'scriptId': lambda v: int(v) if v is not None else None,
                      'column': lambda v: int(v) if v is not None else None,
                  })
Buttons = xmllist('Buttons', 'buttonList', Button)

# Triggers
Activation = xmlenum(
    'Activation',
    'activation',
    OPEN='open',  # Before opening the hierarchy element
    AFTEROPEN='afterOpen',  # After opening the hierarchy element
    READ='read',  # Read this table
    TRANSACTION='transaction',  # Transaction (global)
    LOGIN='******',  # Login (global)
    LOGOUT='logout',  # Logout (global)
    CALL='call'  # For internal use
)

_activations = {
Exemplo n.º 7
0
            [AccessRight(t.text) for t in tag.find_all(AccessRight._tag_name)])

    def to_object(self, add_name=False):
        res = {
            "role": self.role_name,
            "access": [t.to_object() for t in self.access_types]
        }
        if add_name:
            res['_tag_name'] = self._tag_name
        return res


RoleAccess.__repr__ = make_repr('role_name', 'access_types')

_AccessRights = xmllist('AccessRights',
                        'accessRights',
                        RoleAccess,
                        kws=['inherit'])


class AccessRights(_AccessRights):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if len(args) == len(kwargs) == 0:
            self.inherit = True
        elif not self.inherit:
            self.inherit = False
        else:
            self.inherit = self.inherit == 'True' or self.inherit is True

    def copy_rights(self, other):
        self.values = copy.deepcopy(other.values)