librarian Package

librarian Package

card Module

Generic Card Class.

class librarian.card.Card(code=None, name=None, loaddict=None)[source]

Bases: object

The card stores general information about the card.
  • code: the unique identifier for this card.
  • name: name of this card to be displayed.
  • abilities: dict of phase ids containing a list of action descriptors.
  • attributes: list of special details this card has.
  • info: dict of any information you would like.

Card can be saved to, and loaded from, a string. Call str() on a Card instance or .save_string() on the instance. This will return a string that when evaluated using eval() can be unpacked into the Card constructor re-create that card. For example. original = Card(1, 'cool card') savestring = str(card) loaded = Card(*eval(savestring)) assert loaded == original

add_ability(phase, ability)[source]

Add the given ability to this Card under the given phase. Returns the length of the abilities for the given phase after the addition.

add_attribute(attribute)[source]

Add the given attribute to this Card. Returns the length of attributes after addition.

get_abilities(phase)[source]

Returns an ability list for the given phase ID.

get_info(key)[source]

Return a value in the info for this card with the given key.

has_attribute(attribute)[source]

Return true if this card contains the given attribute.

is_valid()[source]

Returns True if code is not 0 and self.name is not ‘’.

load(carddict)[source]

Takes a carddict as produced by Card.save and sets this card instances information to the previously saved cards information.

save()[source]

Converts the Card as is into a dictionary capable of reconstructing the card with Card.load or serialized to a string for storage.

set_info(key, value, append=True)[source]

Set any special info you wish to the given key. Each info is stored in a list and will be appended to rather then overriden unless append is False.

deck Module

Generic Card Class.

class librarian.deck.Deck(library=None, cards=None)[source]

Bases: object

A collection of possibly recuring cards stored as codes.

contains_card(code)[source]

Returns true if the given code is currently stored in this deck.

contains_info(key, value)[source]

Returns how many cards in the deck have the specified value under the specified key in their info data.

This method requires a library to be stored in the deck instance and will return None if there is no library.

contians_attribute(attribute)[source]

Returns how many cards in the deck have the specified attribute.

This method requires a library to be stored in the deck instance and will return None if there is no library.

get_card(index=-1, cache=True, remove=True)[source]

Retrieve a card any number of cards from the top. Returns a Card object loaded from a library if one is specified otherwise just it will simply return its code.

If index is not set then the top card will be retrieved.

If cache is set to True (the default) it will tell the library to cache the returned card for faster look-ups in the future.

If remove is true then the card will be removed from the deck before returning it.

move_top_cards(other, number=1)[source]

Move the top number of cards to the top of some other deck.

By default only one card will be moved if number is not specified.

remaining()[source]

Returns the number of remaining cards in the deck.

shuffle()[source]

Sort the cards in the deck into a random order..

top_cards(number=1, cache=True, remove=True)[source]

Retrieve the top number of cards as Librarian.Card objects in a list in order of top to bottom most card. Uses the decks .get_card and passes along the cache and remove arguments.

library Module

The Library class, an sqlite database of cards.

class librarian.library.Library(dbname, cachelimit=100, cardclass=<class 'librarian.card.Card'>)[source]

Bases: object

Library wraps an sqlite3 database that stores serialized cards.

Library also allows load and save hooks that allow a list of function to be called on each string as it is saved and loaded.

The Library constructor can take a cardclass argument which defaults to librarian.card.Card and is used to construct a card object when loading. A cardclass should be a subclass of librarian.card.Card and be able to take the original carddict constructor argument alone along with providing the original or equal Card.load and Card.save methods.

cache_card(card)[source]

Cache the card for faster future lookups. Removes the oldest card when the card cache stores more cards then this libraries cache limit.

cached(code)[source]

Return True if there is a card for the given code in the cache.

connection()[source]

Connect to the underlying database and return the connection.

create_db()[source]

Create the CARDS table in the sqlite3 database.

Return a list of codes and names pertaining to cards that have the given information values stored.

Can take a code integer, name string, abilities dict {phase: ability list/”*”}, attributes list, info dict {key, value list/”*”}.

In the above argument examples “*” is a string that may be passed instead of a list as the dict value to match anything that stores that key.

load_card(code, cache=True)[source]

Load a card with the given code from the database. This calls each save event hook on the save string before commiting it to the database.

Will cache each resulting card for faster future lookups with this method while respecting the libraries cache limit. However only if the cache argument is True.

Will return None if the card could not be loaded.

retrieve_all()[source]

A generator that iterates over each card in the library database.

This is best used in for loops as it will only load a card from the library as needed rather then all at once.

save_card(card, cache=False)[source]

Save the given card to the database. This calls each save event hook on the save string before commiting it to the database.

librarian.library.Where_filter_gen(*data)[source]

Generate an sqlite “LIKE” filter generator based on the given data. This functions arguments should be a N length series of field and data tuples.

Table Of Contents

Previous topic

librarian

Next topic

Contributing

This Page