Beispiel #1
0
def drop(configpath, mysqlcfg, verbose, debug):
    """drop databases from a MySQL server"""
    mysql_info = read_mysql_config(mysqlcfg, "mysql")
    account = HostAccount(
        mysql_info["host"],
        mysql_info["user"],
        mysql_info["passwd"],
        port=mysql_info["port"],
    )
    server = DbConnection(account, db_name="PARENT", pool_recycle=36000)
    cursor = server.cursor()
    release, remote_path, local_path, species_dbs = read_config(configpath)
    content = get_db_name(account=account, release=str(release))
    content = [str(n) for n in content]
    dbnames = reduce_dirnames(content, species_dbs)

    click.echo("The following databases will be deleted:")
    click.echo("\n".join("  %s" % d for d in dbnames))
    try:
        click.confirm("Confirm you want to delete the databases", abort=True)
    except click.exceptions.Abort:
        click.echo("EXITING")
        exit(0)

    for dbname in dbnames:
        click.echo(f"Dropping {dbname}")
        _drop_db(cursor, dbname)

    if verbose:
        display_dbs(cursor, release)

    cursor.close()
Beispiel #2
0
 def test_get_all_available(self):
     """should return a listing of all the available databases on the
     indicated server"""
     available = get_db_name()
     # make sure we have a compara db present -- a crude check on
     # correctness
     one_valid = False
     for db in available:
         if db.type == "compara":
             one_valid = True
             break
     self.assertEqual(one_valid, True)
     # now check that when we request available under a specific version
     # that we only receive valid ones back
     available = get_db_name(release="46")
     for db in available:
         self.assertEqual(db.release, "46")
Beispiel #3
0
def display_available_dbs(account, release=None):
    """displays the available Ensembl databases at the nominated host"""
    db_list = get_db_name(account=account, db_type="core", release=release)
    db_list += get_db_name(account=account, db_type="compara", release=release)
    rows = []
    for db_name in db_list:
        species_name = db_name.species
        if species_name:
            common_name = Species.get_common_name(db_name.species, level="ignore")

        if "compara" in db_name.name:
            species_name = common_name = "-"
        rows.append([db_name.release, db_name.name, species_name, common_name])

    table = make_table(
        header=["Release", "Db Name", "Species", "Common Name"], data=rows, space=2
    )
    table = table.sorted(["Release", "Db Name"])
    table.legend = (
        "Values of 'None' indicate cogent does not have a value for that database name."
    )
    return table
Beispiel #4
0
 def test_getdb(self):
     """should discover human entries correctly"""
     for name, db_name in [
         ("human", "homo_sapiens_core_49_36k"),
         ("mouse", "mus_musculus_core_49_37b"),
         ("rat", "rattus_norvegicus_core_49_34s"),
         ("platypus", "ornithorhynchus_anatinus_core_49_1f"),
     ]:
         result = get_db_name(species=name, db_type="core", release="49")
         self.assertEqual(len(result), 1)
         result = result[0]
         self.assertEqual(result.name, db_name)
         self.assertEqual(result.release, "49")
Beispiel #5
0
def show(release, mysqlcfg):
    """shows databases corresponding to release"""
    if mysqlcfg.name == _mycfg:
        click.secho(f"{show.help}\n")
        click.secho("use --help for more options")

        exit()

    mysql_info = read_mysql_config(mysqlcfg, "mysql")
    account = HostAccount(
        mysql_info["host"],
        mysql_info["user"],
        mysql_info["passwd"],
        port=mysql_info["port"],
    )
    names = get_db_name(account=account, release=str(release))
    click.echo(f"Databases at host='{account.host}' for release={release}")
    if names:
        click.echo("\n".join("  %s" % n for n in names))
    else:
        click.echo("  None")