pisces.commands.util#
Helper functions for command-line utilities.
- pisces.commands.util.dicts2rows(dicts, classes)[source]#
Expands lists of table dictionaries into table class instances.
- dictsdict
Keys are canonical table names, values are lists of row dicts for that table.
- classesdict
Keys are canonical table names, values are table classes.
- pisces.commands.util.get_files(file_list, file_check=None)[source]#
Return a sequence of file names from either a list of file names (trivial) or a text file list (presumable because there are too many files to use normal shell expansion).
Optionally, supply a file_check function that accepts a file name, and returns a boolean True if the file is the desired format. This only checks the first file, and raises an IOError if False, assuming all subsequent files will be the wrong format.
- pisces.commands.util.get_or_create_tables(session, prefix=None, create=True, **tables)[source]#
Load or create canonical ORM KB Core table classes.
- Parameters:
- sessionsqlalchemy.orm.Session
- prefixstr
Prefix for canonical table names, e.g. ‘myaccount.’ or ‘TA_’ (no owner/schema). Canonical table names are used if no prefix is provided.
- createbool
If True, create tables that don’t yet exist.
- Canonical table keyword/tablename string pairs, such as site=’other.site’,
- can override prefix. For example, you may want to use a different Lastid
- table, so that ids don’t start from 1.
- Returns:
- tablesdict
A mapping between canonical table names and SQLA declarative classes with the correct __tablename__. e.g. {‘origin’: Origin, …}