def drop_databases(debug, yes, connection): """Drop all databases.""" set_debug_param(debug) if yes or click.confirm( 'Do you really want to delete the databases for {}?'.format( ', '.join(managers))): for name, Manager in managers.items(): m = Manager(connection=connection) click.echo('deleting {}'.format(name)) m.drop_all()
def setUp(self): """Create temporary file.""" self.fd, self.path = tempfile.mkstemp() self.connection = 'sqlite:///' + self.path # create temporary database self.manager = Manager.from_connection(connection=self.connection)
def drop(debug, yes, connection): """Drop ComPath DB.""" set_debug_param(debug) if yes or click.confirm('Do you really want to delete the ComPath DB'): m = Manager.from_connection(connection=connection) click.echo('Deleting ComPath DB') m.drop_all() m.create_all()
def populate(debug, connection, delete_first): """Populate all registered Bio2BEL pathway packages.""" set_debug_param(debug) for name, Manager in managers.items(): m = Manager(connection=connection) log.info('populating %s at %s', name, m.engine.url) if delete_first: click.echo('deleting {}'.format(name)) m.drop_all() m.create_all() click.echo('populating {}'.format(name)) m.populate()
def load_hierarchy(*, connection=None, curator_email=None): """Load the hierarchical relationships for the managers containing them. :param Optional[str] connection: :param Optional[str] curator_email: email of the admin """ compath_manager = Manager.from_connection(connection) curator = compath_manager.get_user_by_email( email=curator_email if curator_email else ADMIN_EMAIL) if not curator: raise EnvironmentError( 'There is no user with the email "{}". Please create it with the "make_user" command using ' 'the command line interface of Compath') for pathway_database, ExternalManager in managers.items(): pathway_db_manager = ExternalManager() if not hasattr(pathway_db_manager, 'has_hierarchy'): continue log.info("Loading hierarchies for {}".format(pathway_database)) pathways = pathway_db_manager.get_all_pathways() if pathway_database == 'reactome': pathways = _reactome_wrapper(pathways) log.info("Searching for hierarchical relationships in {} {} pathways". format(len(pathways), pathway_database)) counter_mappings_created = create_hierarchical_mappings( pathways, compath_manager, pathway_database, curator) log.info("{} hierarchical mappings created in {}".format( counter_mappings_created, pathway_database))
def init_app(self, app): """Overwrite init app method.""" super().init_app(app) self.manager = Manager(engine=self.engine, session=self.session)
def manage(ctx, connection): """Manage the database.""" ctx.obj = Manager.from_connection(connection) Base.metadata.bind = ctx.obj.engine Base.query = ctx.obj.session.query_property() ctx.obj.create_all()