Exemplo n.º 1
0
def setup_app(command, conf, vars):
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)
    
    # Create the tables if they don't already exist
    get_metadata().create_all(bind=Session.bind)

    services_parent = conf.get('phyloplumber_services_parent')
    u = conf.get('symlink_phyloplumber_services')
    use_symlink = u and (u.upper() in ['1', 'T', 'Y', 'TRUE', 'YES'])
    if use_symlink:
        install_cmd = os.symlink
    else:
        install_cmd = shutil.copy2

    if services_parent:
        installed_services_file = os.path.join(services_parent, 'phyloplumber_services', 'installed.txt')
        dest_dir = os.path.join(conf['here'], 'phyloplumber', 'controllers')
        template_dest_dir = os.path.join(conf['here'], 'phyloplumber', 'service_templates')
        if os.path.exists(installed_services_file):
            for line in open(installed_services_file, 'rU'):
                n = line.strip()
                if not n:
                    continue
                py_name = n + '.py'
                src_dir = os.path.join(services_parent, 'phyloplumber_services', n)
                src = os.path.join(src_dir, py_name)
                if os.path.exists(src):
                    dest = os.path.join(dest_dir, py_name)
                    if os.path.exists(dest):
                        log.warn('"%(dest)s" exists, this controller is not being replaced' % {'dest' : dest}) 
                    else:
                        install_cmd(src, dest)
                    templates_dir = os.path.join(src_dir, 'templates')
                    if not os.path.exists(templates_dir):
                        continue
                    for f in os.path.listdir(templates_dir):
                        dest = os.path.join(template_dest_dir, f)
                        if os.path.exists(dest):
                            log.warn('"%(dest)s" exists, this template is not being replaced' % {'dest' : dest}) 
                        else:
                            src = os.path.join(templates_dir, f)
                            install_cmd(src, dest)
                else:
                    log.warn('Installed service %(service)s not found at %(path)s' % {'service' : n, 'path' : src})
Exemplo n.º 2
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    #meta.Session.configure(bind=engine)
    sm = orm.sessionmaker(autoflush=True, autocommit=False, bind=engine)
    meta.engine = engine
    meta.Session = orm.scoped_session(sm)
    meta.set_metadata(schema.MetaData(bind=engine))



    t_group = schema.Table("PhyloplumberGroup", meta.get_metadata(),
        schema.Column('id', sa.types.Integer,
            schema.Sequence('group_seq_id', optional=True), primary_key=True),
        schema.Column("name", sa.types.String, nullable=False),
        )
    
    t_user = schema.Table("PhyloplumberUser", meta.metadata,
        schema.Column('id', sa.types.Integer,
            schema.Sequence('user_seq_id', optional=True), primary_key=True),
        schema.Column("username", sa.types.String, nullable=False),
        schema.Column("fullname", sa.types.String, nullable=False),
        schema.Column("date_created", sa.types.DateTime, nullable=False),
        schema.Column("email", sa.types.DateTime, nullable=False),
        )
    
    t_project = schema.Table("PhyloplumberProject", meta.metadata,
        schema.Column('id', sa.types.String, primary_key=True),
        schema.Column('read_group', sa.types.Integer, schema.ForeignKey('PhyloplumberGroup.id')),
        schema.Column('write_group', sa.types.Integer, schema.ForeignKey('PhyloplumberGroup.id')),
        schema.Column('creator', sa.types.Integer, schema.ForeignKey('PhyloplumberUser.id')),
        )

    t_process = schema.Table("PhyloplumberProcess", meta.metadata,
        schema.Column("id", sa.types.String, nullable=False, primary_key=True),
        schema.Column("parent_dirname", sa.types.String, nullable=False),
        schema.Column("launch_timestamp", sa.types.DateTime, nullable=False),
        schema.Column("invocation", sa.types.String, nullable=False),
        schema.Column("label", sa.types.String, nullable=False),
        schema.Column("status", sa.types.Integer, nullable=False),
        schema.Column("service_name", sa.types.String, nullable=False), # this is the controller that launched the job
        schema.Column("read_group", sa.types.Integer, schema.ForeignKey('PhyloplumberGroup.id')),
        schema.Column("write_group", sa.types.Integer, schema.ForeignKey('PhyloplumberGroup.id')),
        )
    
    t_group_user = schema.Table('PhyloplumberGroupUser', meta.metadata,
        schema.Column('id', sa.types.Integer,
            schema.Sequence('groupuser_seq_id', optional=True), primary_key=True),
        schema.Column('groupid', sa.types.Integer, schema.ForeignKey('PhyloplumberGroup.id')),
        schema.Column('userid', sa.types.Integer, schema.ForeignKey('PhyloplumberUser.id')),
        schema.Column("parent_dirname", sa.types.String, nullable=False),
    )
    
    
    orm.mapper(PhyloplumberGroup, t_group)
    orm.mapper(PhyloplumberUser, t_user)
    orm.mapper(PhyloplumberProject, t_project)
    orm.mapper(PhyloplumberProcess, t_process)
    orm.mapper(PhyloplumberGroupUser, t_group_user)