def generate_profile_location_zcml(self, source, target):
    if source.stereotype('pyegg:stub'):
        return

    targetclass = read_target_node(source, target.target)
    module = targetclass.parent
    blocks = module.blocks()
    egg = egg_source(source)
    eggtarget = read_target_node(egg, target.target)

    tgv = TaggedValues(source)
    #name = tgv.direct('name', 'generator:profile', None)

    set_zcml_directive(eggtarget, 'configure.zcml', 'utility', 'name',
            implicit_dotted_path(source),
            provides="agx.core.interfaces.IProfileLocation",
            component=implicit_dotted_path(source))
示例#2
0
def generate_profile_location_zcml(self, source, target):
    if source.stereotype('pyegg:stub'):
        return

    targetclass = read_target_node(source, target.target)
    module = targetclass.parent
    blocks = module.blocks()
    egg = egg_source(source)
    eggtarget = read_target_node(egg, target.target)

    tgv = TaggedValues(source)
    #name = tgv.direct('name', 'generator:profile', None)

    set_zcml_directive(eggtarget,
                       'configure.zcml',
                       'utility',
                       'name',
                       implicit_dotted_path(source),
                       provides="agx.core.interfaces.IProfileLocation",
                       component=implicit_dotted_path(source))
def generate_profile_location(self, source, target):
    targetclass = read_target_node(source, target.target)
    module = targetclass.parent

    ifspec = {
        'path': 'agx.core.interfaces.IProfileLocation',
        'name': 'IProfileLocation',
    }
    tok = token(str(targetclass.uuid), False, realizes=[])
    if ifspec not in tok.realizes:
        tok.realizes.append(ifspec)

    tgv = TaggedValues(source)
    name = tgv.direct('profile_name', 'generator:profile', None)
    if not name:
        name=source.name
        #msg = 'profile_name tagged value not defined for %s!' % source.name
        #raise ValueError(msg)

    imps = Imports(module)
    frompath = '.'.join(ifspec['path'].split('.')[:-1])
    imps.set(frompath, [[ifspec['name'], None]])

    attributenames = [att.targets[0] for att in targetclass.attributes()]
    if 'name' not in attributenames:
        att = Attribute()
        att.__name__ = att.uuid
        targetclass[att.name] = att
        att.targets = ['name']
        att.value = "'%s.profile.uml'" % name

    if 'package' not in attributenames:
        att = Attribute()
        att.__name__ = att.uuid
        targetclass[att.name] = att
        att.targets = ['package']
        att.value = dotted_path(source.parent)
        imps.set('', [[att.value, None]])
        # remove the import from this class
        init = targetclass.parent.parent['__init__.py']
        fromimp = '.'.join(implicit_dotted_path(source).split('.')[:-1])
        imps = [imp for imp in init.imports() if imp.fromimport == fromimp]
        for imp in imps:
            init.detach(str(imp.uuid))
示例#4
0
def generate_profile_location(self, source, target):
    targetclass = read_target_node(source, target.target)
    module = targetclass.parent

    ifspec = {
        'path': 'agx.core.interfaces.IProfileLocation',
        'name': 'IProfileLocation',
    }
    tok = token(str(targetclass.uuid), False, realizes=[])
    if ifspec not in tok.realizes:
        tok.realizes.append(ifspec)

    tgv = TaggedValues(source)
    name = tgv.direct('profile_name', 'generator:profile', None)
    if not name:
        name = source.name
        #msg = 'profile_name tagged value not defined for %s!' % source.name
        #raise ValueError(msg)

    imps = Imports(module)
    frompath = '.'.join(ifspec['path'].split('.')[:-1])
    imps.set(frompath, [[ifspec['name'], None]])

    attributenames = [att.targets[0] for att in targetclass.attributes()]
    if 'name' not in attributenames:
        att = Attribute()
        att.__name__ = att.uuid
        targetclass[att.name] = att
        att.targets = ['name']
        att.value = "'%s.profile.uml'" % name

    if 'package' not in attributenames:
        att = Attribute()
        att.__name__ = att.uuid
        targetclass[att.name] = att
        att.targets = ['package']
        att.value = dotted_path(source.parent)
        imps.set('', [[att.value, None]])
        # remove the import from this class
        init = targetclass.parent.parent['__init__.py']
        fromimp = '.'.join(implicit_dotted_path(source).split('.')[:-1])
        imps = [imp for imp in init.imports() if imp.fromimport == fromimp]
        for imp in imps:
            init.detach(str(imp.uuid))
def generate_sqlalchemy_config(self, source, target):
    tgt = read_target_node(source, target.target)
    if IModule.providedBy(tgt):
        # target is a module, then its ok
        module = tgt
        target_dir = module.parent
    else:
        # fetch __init__.py
        module = tgt['__init__.py']
        target_dir = tgt
    
    
    # first lets create sqla_config.py that does all the config situps
    fname = 'sqla_config.py'
    package_name = implicit_dotted_path(source)
    templ = JinjaTemplate()
    target_dir.factories[fname] = JinjaTemplate
    templ.template = templatepath(fname) + '.jinja'
    target_dir[fname] = templ
    target_dir[fname].params = {'engine_name':'default', 'package_name':dotted_path(source)}
    
    # now lets call config_db from the __init__.py
    imps = Imports(module)
    imps.set('sqla_config', 'config_db')
    main = module.functions('main')[0]
    term = 'config.make_wsgi_app'
    make_app = main.blocks(term)[0]
    lines = make_app.lines
    # find occurrence of line in block
    index = -1
    found = False
    for i in range(len(lines)):
        if term in lines[i]:
            index = i
        if 'config_db' in lines[i]:
            found = True
            
    tok = token('config', True, main=main, module=module)
    if index != -1 and not found:
        lines.insert(index, 'config_db(config)')