Esempio n. 1
0
def update_database(general_results_dict, instrument_results_dict):
    """Updates the ``filesystem_general`` and ``filesystem_instrument``
    database tables.

    Parameters
    ----------
    general_results_dict : dict
        A dictionary for the ``filesystem_general`` database table
    instrument_results_dict : dict
        A dictionary for the ``filesystem_instrument`` database table
    """

    engine.execute(FilesystemGeneral.__table__.insert(), general_results_dict)
    session.commit()

    # Add data to filesystem_instrument table
    for instrument in JWST_INSTRUMENT_NAMES:
        for filetype in instrument_results_dict[instrument]:
            new_record = {}
            new_record['date'] = instrument_results_dict['date']
            new_record['instrument'] = instrument
            new_record['filetype'] = filetype
            new_record['count'] = instrument_results_dict[instrument][
                filetype]['count']
            new_record['size'] = instrument_results_dict[instrument][filetype][
                'size']

            engine.execute(FilesystemInstrument.__table__.insert(), new_record)
            session.commit()
Esempio n. 2
0
def update_database(general_results_dict, instrument_results_dict,
                    central_storage_dict):
    """Updates the ``filesystem_general`` and ``filesystem_instrument``
    database tables.

    Parameters
    ----------
    general_results_dict : dict
        A dictionary for the ``filesystem_general`` database table
    instrument_results_dict : dict
        A dictionary for the ``filesystem_instrument`` database table
    central_storage_dict : dict
        A dictionary for the ``central_storage`` database table

    """
    logging.info('\tUpdating the database')

    engine.execute(FilesystemGeneral.__table__.insert(), general_results_dict)
    session.commit()

    # Add data to filesystem_instrument table
    for instrument in JWST_INSTRUMENT_NAMES:
        for filetype in instrument_results_dict[instrument]:
            new_record = {}
            new_record['date'] = instrument_results_dict['date']
            new_record['instrument'] = instrument
            new_record['filetype'] = filetype
            new_record['count'] = instrument_results_dict[instrument][
                filetype]['count']
            new_record['size'] = instrument_results_dict[instrument][filetype][
                'size']
            engine.execute(FilesystemInstrument.__table__.insert(), new_record)
            session.commit()

    # Add data to central_storage table
    arealist = [
        'logs', 'outputs', 'test', 'preview_images', 'thumbnails', 'all'
    ]
    for area in arealist:
        new_record = {}
        new_record['date'] = central_storage_dict['date']
        new_record['area'] = area
        new_record['size'] = central_storage_dict[area]['size']
        new_record['used'] = central_storage_dict[area]['used']
        new_record['available'] = central_storage_dict[area]['available']
        engine.execute(CentralStore.__table__.insert(), new_record)
        session.commit()

    session.close()