Пример #1
0
def sql_config(self, source, target):
    """writes the sql config.
    """
    nsmap = {
        None: 'http://namespaces.zope.org/zope',
        'saconfig':'http://namespaces.zope.org/db',
    }
    tg = read_target_node(source, target.target)
    conf = zcautils.get_zcml(tg, 'configure.zcml', nsmap=nsmap)
    tgv = TaggedValues(source)

    engine_name = tgv.direct('engine_name', 'sql:z3c_saconfig', 'default')
    engine_url = tgv.direct(
        'engine_url', 'sql:z3c_saconfig', 'sqlite:///test.db')
    session_name = tgv.direct('session_name', 'sql:z3c_saconfig', 'default')

    zcautils.set_zcml_directive(
        tg, 'configure.zcml', 'include', 'package',
        'z3c.saconfig', file='meta.zcml')
    zcautils.set_zcml_directive(
        tg, 'configure.zcml', 'saconfig:engine', 'name',
        engine_name, url=engine_url)
    zcautils.set_zcml_directive(
        tg, 'configure.zcml', 'saconfig:session', 'name',
        session_name, engine=engine_name)
def make_generators(self, source, target):
    if source.stereotype('pyegg:stub'):
        return
    egg = egg_source(source)
    eggtarget = read_target_node(egg, target.target)
    zcml = get_zcml(eggtarget, 'configure.zcml',
                    nsmap={None: 'http://namespaces.zope.org/zope', 
                           'agx': 'http://namespaces.zope.org/agx'})
    tgv = TaggedValues(source)

    # if transform isnt specified as tgv, get it from dependency relations to
    # other generators
    transform = tgv.direct('transform', 'generator:generator', None)
    if not transform:
        transforms = token(str(source.uuid), True, transforms=[]).transforms
        if len(transforms) > 1:
            msg = 'Currently only one transform per generator allowed (%s)'
            msg = msg % source.name
            raise ValueError(msg)
        elif len(transforms) == 1:
            transform = transforms[0].name

    if not transform:
        transform = 'uml2fs'

    # if depends isnt specified as tgv, get it from dependency relations to
    # transforms
    depend = tgv.direct('depends', 'generator:generator', None)
    if not depend:
        depends = token(str(source.uuid), True, depends_on=[]).depends_on
        if len(depends) > 1:
            msg = 'Currently only one depends per generator allowed (%s)'
            msg = msg % source.name
            raise ValueError(msg)
        elif len(depends) == 1:
            depend = depends[0].name

    if not depend:
        depend = 'NO'

    directives = zcml.filter(tag='agx:generator', attr='name')

    directive = None
    for d in directives:
        if d.attrs['name'] == source.name:
            directive = d
            break

    if not directive:
        directive = SimpleDirective(name='agx:generator', parent=zcml)

    directive.attrs['name'] = source.name
    directive.attrs['transform'] = transform
    directive.attrs['depends'] = depend

    set_zcml_directive(eggtarget, 'configure.zcml', 'agx:generator',
                       'name', source.name, overwrite=True)
def prepare_zcml(self, source, target):
    """Prepares zcml for generator stuff, therefore the check.
    """
    try:
        tok = token(str(source.uuid), False, is_generator_egg=False)
        if tok.is_generator_egg:
            package = read_target_node(source,target.target)
            nsmap = {
                None: "http://namespaces.zope.org/zope",
                'agx': "http://namespaces.zope.org/agx",
            }
            zcml = get_zcml(package, 'configure.zcml', nsmap=nsmap)
            set_zcml_directive(package, 'configure.zcml', 'include',
                               'package', 'agx.generator.pyegg')
    except ComponentLookupError:
        # if we dont have a token, do nothing
        pass
Пример #4
0
def prepare_zcml(self, source, target):
    """Prepares zcml for generator stuff, therefore the check.
    """
    try:
        tok = token(str(source.uuid), False, is_generator_egg=False)
        if tok.is_generator_egg:
            package = read_target_node(source, target.target)
            nsmap = {
                None: "http://namespaces.zope.org/zope",
                'agx': "http://namespaces.zope.org/agx",
            }
            zcml = get_zcml(package, 'configure.zcml', nsmap=nsmap)
            set_zcml_directive(package, 'configure.zcml', 'include', 'package',
                               'agx.generator.pyegg')
    except ComponentLookupError:
        # if we dont have a token, do nothing
        pass
def typeview(self, source, target):
    schema = getschemaclass(source, target)
    klass = read_target_node(source, target.target)
    module = schema.parent
    if IModule.providedBy(module):
        directory = module.parent
    else:
        directory = module
    nsmap = {
        None: 'http://namespaces.zope.org/zope',
        'plone': 'http://namespaces.plone.org/plone',
        'grok': 'http://namespaces.zope.org/grok',
    }
    zcmlfile = get_zcml(directory, 'configure.zcml', nsmap=nsmap)

    # include grok:grok directive if not set yet
    set_zcml_directive(directory, 'configure.zcml', 'grok:grok', 'package',
                       '.')

    classname = '%sView' % klass.classname
    if module.classes(classname):
        view = module.classes(classname)[0]
    else:
        view = python.Class()
        module[uuid.uuid4()] = view
    view.classname = classname

    if not 'dexterity.DisplayForm' in view.bases:
        view.bases.append('dexterity.DisplayForm')

    context = "grok.context(%s)" % schema.classname
    require = "grok.require('zope2.View')"

    context_exists = False
    require_exists = False

    for block in view.blocks():
        for line in block.lines:
            if line == context:
                context_exists = True
            if line == require:
                require_exists = True

    block = python.Block()
    block.__name__ = str(uuid.uuid4())

    if not context_exists:
        block.lines.append(context)
    if not require_exists:
        block.lines.append(require)

    if block.lines:
        view.insertfirst(block)

    template = False
    for attr in view.attributes():
        if 'template' in attr.targets:
            template = attr
            break

    if not template:
        template = python.Attribute()
        template.targets = ['template']
        view[str(uuid.uuid4())] = template

    template.value = "PageTemplate('templates/%s.pt')" \
        % klass.classname.lower()

    imp = Imports(module)
    imp.set('plone.directives', [['dexterity', None]])
    imp.set('five', [['grok', None]])
    imp.set('grokcore.view.components', [['PageTemplate', None]])

    directory = module.parent
    template_name = '%s.pt' % klass.classname.lower()
    template = 'templates/%s' % template_name
    if not 'templates' in directory:
        directory['templates'] = Directory()

    templates = directory['templates']
    templates.factories['.pt'] = XMLTemplate

    if template_name not in templates:
        pt = templates[template_name] = XMLTemplate()
        pt.template = 'agx.generator.dexterity:templates/displayform.pt'
def typeview(self, source, target):
    schema = getschemaclass(source,target)
    klass = read_target_node(source, target.target)
    module = schema.parent
    if IModule.providedBy(module):
        directory = module.parent
    else:
        directory = module
    nsmap = {
        None: 'http://namespaces.zope.org/zope',
        'plone': 'http://namespaces.plone.org/plone',
        'grok': 'http://namespaces.zope.org/grok',
    }
    zcmlfile = get_zcml(directory, 'configure.zcml', nsmap=nsmap)

    # include grok:grok directive if not set yet
    set_zcml_directive(directory, 'configure.zcml',
                       'grok:grok', 'package', '.')

    classname = '%sView' % klass.classname
    if module.classes(classname):
        view = module.classes(classname)[0]
    else:
        view = python.Class()
        module[uuid.uuid4()] = view
    view.classname = classname

    if not 'dexterity.DisplayForm' in view.bases:
        view.bases.append('dexterity.DisplayForm')

    context = "grok.context(%s)" % schema.classname
    require = "grok.require('zope2.View')"

    context_exists = False
    require_exists = False

    for block in view.blocks():
        for line in block.lines:
            if line == context:
                context_exists = True
            if line == require:
                require_exists = True

    block = python.Block()
    block.__name__ = str(uuid.uuid4())

    if not context_exists:
        block.lines.append(context)
    if not require_exists:
        block.lines.append(require)

    if block.lines:
        view.insertfirst(block)

    template = False
    for attr in view.attributes():
        if 'template' in attr.targets:
            template = attr
            break

    if not template:
        template = python.Attribute()
        template.targets = ['template']
        view[str(uuid.uuid4())] = template

    template.value = "PageTemplate('templates/%s.pt')" \
        % klass.classname.lower()

    imp = Imports(module)
    imp.set('plone.directives', [['dexterity', None]])
    imp.set('five', [['grok', None]])
    imp.set('grokcore.view.components', [['PageTemplate', None]])

    directory = module.parent
    template_name = '%s.pt' % klass.classname.lower()
    template = 'templates/%s' % template_name
    if not 'templates' in directory:
        directory['templates'] = Directory()

    templates = directory['templates']
    templates.factories['.pt'] = XMLTemplate

    if template_name not in templates:
        pt = templates[template_name] = XMLTemplate()
        pt.template = 'agx.generator.dexterity:templates/displayform.pt'
Пример #7
0
def make_generators(self, source, target):
    if source.stereotype('pyegg:stub'):
        return
    egg = egg_source(source)
    eggtarget = read_target_node(egg, target.target)
    zcml = get_zcml(eggtarget,
                    'configure.zcml',
                    nsmap={
                        None: 'http://namespaces.zope.org/zope',
                        'agx': 'http://namespaces.zope.org/agx'
                    })
    tgv = TaggedValues(source)

    # if transform isnt specified as tgv, get it from dependency relations to
    # other generators
    transform = tgv.direct('transform', 'generator:generator', None)
    if not transform:
        transforms = token(str(source.uuid), True, transforms=[]).transforms
        if len(transforms) > 1:
            msg = 'Currently only one transform per generator allowed (%s)'
            msg = msg % source.name
            raise ValueError(msg)
        elif len(transforms) == 1:
            transform = transforms[0].name

    if not transform:
        transform = 'uml2fs'

    # if depends isnt specified as tgv, get it from dependency relations to
    # transforms
    depend = tgv.direct('depends', 'generator:generator', None)
    if not depend:
        depends = token(str(source.uuid), True, depends_on=[]).depends_on
        if len(depends) > 1:
            msg = 'Currently only one depends per generator allowed (%s)'
            msg = msg % source.name
            raise ValueError(msg)
        elif len(depends) == 1:
            depend = depends[0].name

    if not depend:
        depend = 'NO'

    directives = zcml.filter(tag='agx:generator', attr='name')

    directive = None
    for d in directives:
        if d.attrs['name'] == source.name:
            directive = d
            break

    if not directive:
        directive = SimpleDirective(name='agx:generator', parent=zcml)

    directive.attrs['name'] = source.name
    directive.attrs['transform'] = transform
    directive.attrs['depends'] = depend

    set_zcml_directive(eggtarget,
                       'configure.zcml',
                       'agx:generator',
                       'name',
                       source.name,
                       overwrite=True)