abcd package

Submodules

abcd.authentication module

Classes related to facilitating authentication by the backend of some credentials gathered by the frontend.

class abcd.authentication.AuthToken(username)[source]

Bases: object

username
exception abcd.authentication.AuthenticationError(message)[source]

Bases: exceptions.Exception

class abcd.authentication.Credentials(username=None)[source]

Bases: object

username

Get the username

Returns:The username
class abcd.authentication.UsernameAndPassword(username, password)[source]

Bases: abcd.authentication.Credentials

password

abcd.backend module

The backend interface that must be implemented by any structure storage library that wants to be compliant with this framework.

In general implementations of this class should perform translation from to commands understood by the native storage format being used be it SQL, a filesystem, MongoDB or others.

class abcd.backend.Backend[source]

Bases: object

add_keys(auth_token, filter, kvp)[source]

Adds key-value pairs to the selectd configurations

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • filter (dictionary?) – Filter (in MongoDB query language)
  • kvp (dict) – Key-value pairs to be added
Return type:

AddKvpResult

authenticate(credentials)[source]

Take a set of credentials and return an authorisation token or raise an exception

Parameters:credentials (Credentials) – The credentials, a subclass of

:py:class:Credentials :return: :rtype: AuthToken

close()[source]
find(auth_token, filter, sort, limit, keys, omit)[source]

Find entries that match the filter

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • filter (list of Conditions) – Filter
  • sort (dict) – Dictionary where keys are columns byt which to sort end values are either abcd.Direction.ASCENDING or abcd.Direction.DESCENDING
  • limit (int) – limit the number of returned entries
  • keys (list) – keys to be returned. None for all.
  • omit (bool) – if True, the keys parameter will be interpreted as the keys to omit (all keys except the ones specified will be returned).
Returns:

Return type:

Iterator to the Atoms object

insert(auth_token, atoms)[source]

Take the Atoms object or an iterable to the Atoms and insert it to the database

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • atoms (Atoms or Atoms iterable) – Atoms to insert
Returns:

Returns a result that holds a list of ids at which the objects were inserted and a message

Return type:

InsertResult

is_open()[source]
list(auth_token)[source]

List all the databases the user has access to

Parameters:auth_token (AuthToken) – Authorisation token
Return type:list
open()[source]
remove(auth_token, filter, just_one)[source]

Remove entries from the databse that match the filter

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • filter (dictionary?) – Filter (in MongoDB query language)
  • just_one (bool) – remove not more than one entry
Returns:

Returns a result that holds the number of removed entries and a message

Return type:

RemoveResult

remove_keys(auth_token, filter, keys)[source]

Removes specified keys from selected configurations

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • filter (dictionary?) – Filter (in MongoDB query language)
  • keys (dict) – Keys to be removed
Return type:

RemoveKeysResult

update(auth_token, atoms, upsert, replace)[source]

Take the atoms object and find an entry in the database with the same unique id. If one exists, the old entry gets updated with the new entry.

Parameters:
  • auth_token (AuthToken) – Authorisation token
  • atoms (Atoms or Atoms iterable) – Atoms to insert
  • upsert (bool) – Insert configurations even if they don’t correspond to any existing ones
  • replace (bool) – If a given configuration already exists, replace it
Returns:

Return type:

UpdateResult

exception abcd.backend.CommunicationError(message)[source]

Bases: exceptions.Exception

Error which is raised by the backend if communication with remote fails

class abcd.backend.Cursor[source]

Bases: object

count()[source]
next()[source]
abcd.backend.Direction

alias of Enum

exception abcd.backend.ReadError(message)[source]

Bases: exceptions.Exception

Error which is raised by the backend if read fails

exception abcd.backend.WriteError(message)[source]

Bases: exceptions.Exception

Error which is raised by the backend if write fails

abcd.backend.enum(*sequential)[source]

abcd.cli module

abcd.cli.main()[source]
abcd.cli.print_result(result, multiconfig_files, database)[source]
abcd.cli.run(args, sys_args, verbosity)[source]
abcd.cli.to_stderr(*args)[source]

Prints to stderr

abcd.cli.untar_and_delete(tar_files, path_prefix)[source]
abcd.cli.untar_file(fileobj, path_prefix)[source]

abcd.config module

config.py

Interact with configuration files and data files.

For testing, set XDG_CONFIG_HOME and XDG_DATA_HOME to avoid destroying existing files.

class abcd.config.ConfigFile(module, *args, **kwargs)[source]

Bases: ConfigParser.SafeConfigParser

Generic configuration file for specific parts of the code.

delete()[source]
exists()[source]

Return True if the config file already exists.

initialise(data=None, overwrite=True)[source]

Create a new configuration file. If data is a dict the new configuration file will include the data as {section: {key: value}}

abcd.query module

exception abcd.query.QueryError(message)[source]

Bases: exceptions.Exception

abcd.query.elements2numbers(elements)[source]
abcd.query.interpret(query)[source]

Translates a single query to the MongoDB format

abcd.query.is_float(n)[source]
abcd.query.is_int(n)[source]
abcd.query.translate(queries_lst)[source]

Translates a list of queries to the MongoDB format

abcd.query.update(d1, d2)[source]

Update dictionary d1 with d2

abcd.results module

class abcd.results.AddKvpResult(modified_ids, no_of_kvp_added, msg=None)[source]

Bases: abcd.results.Result

modified_ids
no_of_kvp_added
class abcd.results.InsertResult(inserted_ids, skipped_ids, msg=None)[source]

Bases: abcd.results.Result

inserted_ids
skipped_ids
class abcd.results.RemoveKeysResult(modified_ids, no_of_keys_removed, msg=None)[source]

Bases: abcd.results.Result

modified_ids
no_of_keys_removed
class abcd.results.RemoveResult(removed_count=1, msg=None)[source]

Bases: abcd.results.Result

removed_count

The number of entries removed :return: The number of entries removed

class abcd.results.Result(msg=None)[source]

Bases: object

msg
class abcd.results.UpdateResult(updated_ids, skipped_ids, upserted_ids, replaced_ids, msg=None)[source]

Bases: abcd.results.Result

replaced_ids
skipped_ids
updated_ids
upserted_ids

abcd.structurebox module

class abcd.structurebox.StructureBox(backend)[source]

Bases: object

class BackendOpen(backend)[source]
StructureBox.add_keys(auth_token, filter, kvp)[source]
StructureBox.authenticate(credentials)[source]
StructureBox.find(auth_token, filter, sort={}, limit=0, keys=None, omit_keys=False)[source]
StructureBox.insert(auth_token, atoms)[source]
StructureBox.list(auth_token)[source]
StructureBox.remove(auth_token, filter, just_one=True)[source]
StructureBox.remove_keys(auth_token, filter, keys)[source]
StructureBox.update(auth_token, atoms, upsert=False, replace=False)[source]

abcd.table module

abcd.table.atoms_list2dict(atoms_it)[source]

Converts an Atoms iterator into a plain, one-level-deep list of dicts

abcd.table.format_value(value, key)[source]

Applies special formatting for some key-value pairs

abcd.table.print_keys_table(atoms_list, border=True, truncate=True, show_keys=[], omit_keys=[])[source]

Prints two tables: Intersection table and Union table, and shows min and max values for each key

abcd.table.print_kvps(kvps)[source]

Takes a list of tuples, where each tuple is a key-value pair, and prints it.

abcd.table.print_long_row(atoms)[source]

Prints full information about one configuration

abcd.table.print_rows(atoms_list, border=True, truncate=True, show_keys=[], omit_keys=[])[source]

Prints a full table

abcd.table.trim(val, length)[source]

Trim the string if it’s longer than “length” (and add dots at the end)

abcd.util module

abcd.util.atoms2dict(atoms, plain_arrays=False)[source]

Converts the Atoms object to a dictionary. If plain_arrays is True, numpy arrays are converted to lists.

abcd.util.dict2atoms(d, plain_arrays=False)[source]

Converts a dictionary created with atoms2dict back to atoms.

abcd.util.filter_keys(keys_list, keys, omit_keys)[source]

Decides which keys to show given keys and omit_keys

abcd.util.get_info_and_arrays(atoms, plain_arrays)[source]

Extracts the info and arrays dictionaries from the Atoms object. If plain_arrays is True, numpy arrays are converted to lists.