model.util.export¶
Utility script to export a scenario to a file.
Attributes¶
Functions¶
|
Take a collection of related objects, and set the foreign key IDs on the local and remote side of each relationship |
|
Loads the maximum sequence number for each table in the database. Can be used to determine the starting point for |
|
Take an object and disconnect it from the database session. This will make it a pure Python object. |
|
Extracts the scenario with the given ID from the database. It will be turned into a set of Base objects, which are |
Module Contents¶
- model.util.export.ALL_CLASSES_WITH_SCENARIO_ID¶
- model.util.export.ALL_PURE_ASSOC_CLASSES¶
- model.util.export.ALL_TABLE_CLASSES¶
- model.util.export.start_counting_foreign_keys_at(start, objs)¶
Take a collection of related objects, and set the foreign key IDs on the local and remote side of each relationship to values >= the given start value. This is useful when importing a scenario, as it allows to set the IDs of the objects to be imported to values that are not already present in the database. :param start: A dictionary containing the starting value for each class. :param objs: A list of Base objects. :return: The same list of Base objects, but with the foreign key IDs set to values >= the given start value.
- Parameters:
start (Dict[str, int])
objs (List[eflips.model.Base])
- Return type:
List[eflips.model.Base]
- model.util.export.get_or_update_max_sequence_number(conn, do_update=False)¶
Loads the maximum sequence number for each table in the database. Can be used to determine the starting point for the sequence numbers when importing a scenario. Or to fix the sequence numbers after importing a scenario. :param conn: An open database connection (PostgreSQL or SQLite). :param do_update: If True, the sequence counters will also be updated in the database to continue counting after the maximum sequence number. :return: A dictionary containing the maximum sequence number for each table.
- Parameters:
conn (psycopg2.extensions.connection | sqlite3.Connection)
do_update (bool)
- Return type:
Dict[str, int]
- model.util.export.disconnect_obj(obj)¶
Take an object and disconnect it from the database session. This will make it a pure Python object.
This is done by - setting the primary key to None - setting the object to transient state - setting all ids for the foreign keys to None
- Parameters:
obj (eflips.model.Base) – An SQLAlchemy object.
- Returns:
The same object, but disconnected from the database session.
- Return type:
eflips.model.Base
- model.util.export.extract_scenario(scenario_id, session)¶
Extracts the scenario with the given ID from the database. It will be turned into a set of Base objects, which are no longer attached to the database. :param scenario_id: The ID of the scenario to extract. :param session: An active database session. :return: A list of Base objects representing the scenario.
- Parameters:
scenario_id (int)
session (sqlalchemy.orm.Session)
- Return type:
List[eflips.model.Base]
- model.util.export.args¶