cqparts.catalogue package

Submodules

cqparts.catalogue.catalogue module

class cqparts.catalogue.catalogue.Catalogue

Bases: object

iter_items()

Iterate through every item in the catalogue.

Returns:iterator for every item
Return type:generator

Note

Must be overridden by inheriting class

cqparts.catalogue.json module

class cqparts.catalogue.json.JSONCatalogue(filename, clean=False)

Bases: cqparts.catalogue.catalogue.Catalogue

Catalogue with JSON storage using tinydb.

For more information, read Catalogue.

__init__(filename, clean=False)
Parameters:
  • filename (str) – name of catalogue file
  • clean (bool) – if set, catalogue is deleted, to be re-populatd from scratch

If a new database is created, a _dbinfo table is added with version & module information to assist backward compatibility.

add(id, obj, criteria={}, force=False, _check_id=True)

Add a Component instance to the database.

Parameters:
  • id (str) – unique id of entry, can be anything
  • obj (Component) – component to be serialized, then added to the catalogue
  • criteria (dict) – arbitrary search criteria for the entry
  • force (bool) – if True, entry is forcefully overwritten if it already exists. Otherwise an exception is raised
  • _check_id (bool) – if False, duplicate id is not tested
Raises:
  • TypeError – on parameter issues
  • ValueError – if a duplicate db entry is detected (and force is not set)
Returns:

index of new entry

Return type:

int

close()

Close the database, and commit any changes to file.

dbinfo

Database information (at time of creation), mainly intended for future-proofing.

Returns:information about database’s initial creation
Return type:dict
deserialize_item(data)

Create a Component from a database search result.

Parameters:data (dict) – result from find(), or an element of search()
Returns:deserialized object instance
Return type:Component
find(*args, **kwargs)

Performs the same action as search() but asserts a single result.

Returns:

Raises:
get(*args, **kwargs)

Combination of find() and deserialize_item(); the result from find() is deserialized and returned.

Input is a tinydb query.

Returns:deserialized object instance
Return type:Component
get_query()

Passthrough to return a tinydb.Query instance. (mostly implemented so importing tinydb is not mandatory to search the catalogue)

Returns:tinydb query instance
Return type:tinydb.Query
iter_items()

Iterate through all items in the catalogue

Returns:iterator for each item
Return type:generator
search(*args, **kwargs)

Passthrough to Table.search() for the items table.

So catalogue.search(...) equivalent to catalogue.db.table('items').search(...).

Returns:entries in items table that positively match given search criteria.
Return type:list of items table entries

Module contents

class cqparts.catalogue.Catalogue

Bases: object

iter_items()

Iterate through every item in the catalogue.

Returns:iterator for every item
Return type:generator

Note

Must be overridden by inheriting class

class cqparts.catalogue.JSONCatalogue(filename, clean=False)

Bases: cqparts.catalogue.catalogue.Catalogue

Catalogue with JSON storage using tinydb.

For more information, read Catalogue.

__init__(filename, clean=False)
Parameters:
  • filename (str) – name of catalogue file
  • clean (bool) – if set, catalogue is deleted, to be re-populatd from scratch

If a new database is created, a _dbinfo table is added with version & module information to assist backward compatibility.

add(id, obj, criteria={}, force=False, _check_id=True)

Add a Component instance to the database.

Parameters:
  • id (str) – unique id of entry, can be anything
  • obj (Component) – component to be serialized, then added to the catalogue
  • criteria (dict) – arbitrary search criteria for the entry
  • force (bool) – if True, entry is forcefully overwritten if it already exists. Otherwise an exception is raised
  • _check_id (bool) – if False, duplicate id is not tested
Raises:
  • TypeError – on parameter issues
  • ValueError – if a duplicate db entry is detected (and force is not set)
Returns:

index of new entry

Return type:

int

close()

Close the database, and commit any changes to file.

dbinfo

Database information (at time of creation), mainly intended for future-proofing.

Returns:information about database’s initial creation
Return type:dict
deserialize_item(data)

Create a Component from a database search result.

Parameters:data (dict) – result from find(), or an element of search()
Returns:deserialized object instance
Return type:Component
find(*args, **kwargs)

Performs the same action as search() but asserts a single result.

Returns:

Raises:
get(*args, **kwargs)

Combination of find() and deserialize_item(); the result from find() is deserialized and returned.

Input is a tinydb query.

Returns:deserialized object instance
Return type:Component
get_query()

Passthrough to return a tinydb.Query instance. (mostly implemented so importing tinydb is not mandatory to search the catalogue)

Returns:tinydb query instance
Return type:tinydb.Query
iter_items()

Iterate through all items in the catalogue

Returns:iterator for each item
Return type:generator
search(*args, **kwargs)

Passthrough to Table.search() for the items table.

So catalogue.search(...) equivalent to catalogue.db.table('items').search(...).

Returns:entries in items table that positively match given search criteria.
Return type:list of items table entries