yawning_titan.networks.network_db.NetworkDB#

class yawning_titan.networks.network_db.NetworkDB[source]#

Bases: object

The NetworkDB class extends YawningTitanDB.

The below code blocks demonstrate how to use the NetworkDB class.

  • Instantiate the Network DB:

    >>> from yawning_titan.networks.network_db import NetworkDB, NetworkSchema
    >>> db = NetworkDB()
    
  • Search for all network that have set_random_entry_nodes == True.

    >>> db.search(NetworkSchema.SET_RANDOM_ENTRY_NODES == True)
    

Methods

all

Get all Network from the network DB.

count

Count how many docs are in the db.

get

Get a network config document from its uuid.

insert

Insert a Network into the DB as .json.

rebuild_db

Rebuild the db.

remove

Remove a Network.

remove_by_cond

Remove Network.

reset_default_networks_in_db

Reset the default network in the db.

search

Searches the Network with a NetworkSchema query.

show

Show details of all entries in the db.

update

Update a Network.

upsert

Upsert a Network.

insert(network, name=None, description=None, author=None)[source]#

Insert a Network into the DB as .json.

Parameters:
  • network – An instance of Network DocMetadata. DocMetadata. DocMetadata.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The inserted Network.

all()[source]#

Get all Network from the network DB.

Returns:

A list of Network.

show(verbose=False)[source]#

Show details of all entries in the db.

Parameters:

verbose – If True, all doc metadata details are shown, otherwise just the name is shown.

get(uuid)[source]#

Get a network config document from its uuid.

Parameters:

uuid – A target document uuid.

Returns:

The network config document as an instance of Network if the uuid exists, otherwise None.

search(query)[source]#

Searches the Network with a NetworkSchema query.

Parameters:

query – A YawningTitanQuery.

Returns:

A list of Network.

count(cond=None)[source]#

Count how many docs are in the db. Extends tinydb.table.Table.count.

A YawningTitanQuery can be used to filter the count.

Parameters:

cond – An optional YawningTitanQuery. Has a default value of None.

Returns:

The number of docs counted.

update(network, name=None, description=None, author=None)[source]#

Update a Network. in the db.

Parameters:
  • network – An instance of Network.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The updated Network.

upsert(network, name=None, description=None, author=None)[source]#

Upsert a Network. in the db.

Parameters:
  • network – An instance of Network.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The upserted Network.

remove(network)[source]#

Remove a Network. from the db.

Parameters:

network – An instance of Network.

Returns:

The uuid of the removed Network.

remove_by_cond(cond)[source]#

Remove Network. from the db that match the query.

Parameters:

cond – A YawningTitanQuery.

Returns:

The list of uuids of the removed Network.

reset_default_networks_in_db(force=False)[source]#

Reset the default network in the db.

Achieves this by loading the default yawning_titan/networks/_package_data/network.json db file into TinyDB, then iterating over all docs and forcing an update of each one in the main networks db from its uuid if they do not match.

Parameters:

force – Forces a reset without checking for equality when True. Has a default value of False.

rebuild_db()[source]#

Rebuild the db.

Actions taken:

Warning

This function completely rebuilds the database. Any custom networks saved in the db will be lost. The default networks can be reset using the reset_default_networks_in_db() function.