예제 #1
0
def get_channel_ids_for_content_database_dir(content_database_dir):
    """
    Returns a list of channel IDs for the channel databases that exist in a content database directory.
    """

    # immediately return an empty list if the content database directory doesn't exist
    if not os.path.isdir(content_database_dir):
        return []

    # get a list of all the database files in the directory, and extract IDs
    db_list = fnmatch.filter(os.listdir(content_database_dir), '*.sqlite3')
    db_names = [db.split('.sqlite3', 1)[0] for db in db_list]

    # determine which database names are valid, and only use those ones
    valid_db_names = [name for name in db_names if is_valid_uuid(name)]
    invalid_db_names = set(db_names) - set(valid_db_names)
    if invalid_db_names:
        logging.warning("Ignoring databases in content database directory '{directory}' with invalid names: {names}"
                        .format(directory=content_database_dir, names=invalid_db_names))

    # empty database files are created if we delete a database file while the server is running and connected to it;
    # here, we delete and exclude such databases to avoid errors when we try to connect to them
    empty_db_files = set({})
    for db_name in valid_db_names:
        filename = os.path.join(content_database_dir, "{}.sqlite3".format(db_name))
        if os.path.getsize(filename) == 0:
            empty_db_files.add(db_name)
            os.remove(filename)
    if empty_db_files:
        logging.warning("Removing empty databases in content database directory '{directory}' with IDs: {names}"
                        .format(directory=content_database_dir, names=empty_db_files))
    valid_dbs = list(set(valid_db_names) - set(empty_db_files))

    return valid_dbs
예제 #2
0
def get_channel_ids_for_content_database_dir(content_database_dir):
    """
    Returns a list of channel IDs for the channel databases that exist in a content database directory.
    """
    db_list = fnmatch.filter(os.listdir(content_database_dir), '*.sqlite3')
    db_names = [db.split('.sqlite3', 1)[0] for db in db_list]
    valid_db_names = [name for name in db_names if is_valid_uuid(name)]
    invalid_db_names = set(db_names) - set(valid_db_names)

    if invalid_db_names:
        logging.warning(
            "Ignoring databases in content database directory '{directory}' with invalid names: {names}"
            .format(directory=content_database_dir, names=invalid_db_names))

    # empty database files are created if we delete a database file while the server is running and connected to it;
    # here, we delete and exclude such databases to avoid errors when we try to connect to them
    empty_db_files = set({})
    for db_name in valid_db_names:
        filename = os.path.join(content_database_dir,
                                "{}.sqlite3".format(db_name))
        if os.path.getsize(filename) == 0:
            empty_db_files.add(db_name)
            os.remove(filename)
    if empty_db_files:
        logging.warning(
            "Removing empty databases in content database directory '{directory}' with IDs: {names}"
            .format(directory=content_database_dir, names=empty_db_files))
    valid_dbs = list(set(valid_db_names) - set(empty_db_files))

    return valid_dbs
예제 #3
0
def get_channel_ids_for_content_database_dir(content_database_dir):
    """
    Returns a list of channel IDs for the channel databases that exist in a content database directory.
    """
    db_list = fnmatch.filter(os.listdir(content_database_dir), '*.sqlite3')
    db_names = [db.split('.sqlite3', 1)[0] for db in db_list]
    valid_db_names = [name for name in db_names if is_valid_uuid(name)]
    invalid_db_names = set(db_names) - set(valid_db_names)

    if invalid_db_names:
        logging.warning("Ignoring databases in content database directory '{directory}' with invalid names: {names}"
                        .format(directory=content_database_dir, names=invalid_db_names))

    return valid_db_names
예제 #4
0
def get_channel_ids_for_content_database_dir(content_database_dir):
    """
    Returns a list of channel IDs for the channel databases that exist in a content database directory.
    """

    # immediately return an empty list if the content database directory doesn't exist
    if not os.path.isdir(content_database_dir):
        return []

    # get a list of all the database files in the directory, and extract IDs
    db_list = fnmatch.filter(os.listdir(content_database_dir), "*.sqlite3")
    db_names = [db.split(".sqlite3", 1)[0] for db in db_list]

    # determine which database names are valid, and only use those ones
    valid_db_names = [name for name in db_names if is_valid_uuid(name)]
    invalid_db_names = set(db_names) - set(valid_db_names)
    if invalid_db_names:
        logger.warning(
            "Ignoring databases in content database directory '{directory}' with invalid names: {names}".format(
                directory=content_database_dir, names=invalid_db_names
            )
        )

    # nonexistent database files are created if we delete the files that have broken symbolic links;
    # empty database files are created if we delete a database file while the server is running and connected to it;
    # here, we delete and exclude such databases to avoid errors when we try to connect to them
    db_files_to_remove = set({})
    for db_name in valid_db_names:
        filename = os.path.join(content_database_dir, "{}.sqlite3".format(db_name))
        if not os.path.exists(filename) or os.path.getsize(filename) == 0:
            db_files_to_remove.add(db_name)
            os.remove(filename)

    if db_files_to_remove:
        err_msg = (
            "Removing nonexistent or empty databases in content database directory "
            "'{directory}' with IDs: {names}.\nPlease import the channels again."
        )
        logger.warning(
            err_msg.format(directory=content_database_dir, names=db_files_to_remove)
        )
    valid_dbs = list(set(valid_db_names) - set(db_files_to_remove))

    return valid_dbs