cape.attdb.writedb: Write DataKit processed data to file

This module provides a function to write processed data for a given DataKit. It works within the context of a “DataKit collection” (i.e. a repo containing one or more DataKit packages) and is knowledgeable about the dependencies between DataKits within the collection.

cape.attdb.writedb.genr8_modsequence(modnames, **kw)

Create a sequence of modules that satisfy all requirements

Call:
>>> dbnames, modnames = genr8_modsequence(modnames, **kw)
Inputs:
modnames: tuple[str]

Names of module names to process

reqs, dependencies: {True} | False

Also process any modules listed in REQUIREMENTS in each module in a

prefix: {None} | str

Optional user-specified prefix

Outputs:
dbnames: list[str]

List of DB_NAME for modules corresponding to modnames

modnames: list[str]

Modules in order that satisfies all dependencies

Versions:
  • 2021-07-17 @ddalle: Version 1.0

  • 2021-08-20 @ddalle: Version 1.1; prefix option

cape.attdb.writedb.get_dbname(mod)

Get database name from a module

Call:
>>> dbname = get_dbname(mod)
Inputs:
mod: module

DataKit module

Outputs:
dbname: str

Database name, from mod.DATAKIT_LOADER or mod.__name__

Versions:
  • 2021-08-20 @ddalle: Version 1.0

cape.attdb.writedb.get_fullmodname(modname, prefix=None, **kw)

Append prefix to module name if necessary

For example "v004" might become "sls10afa.v004"

Call:
>>> modname = get_fullmodname(modname, prefix=None)
Inputs:
modname: str

Module name, possibly missing top-level prefix

prefix: {None} | str

Optional user-specified prefix

Outputs:
modname: str

Full module name for import, possibly prepended

Versions:
  • 2021-08-20 @ddalle: Version 1.0

  • 2021-09-15 @ddalle: Version 1.1; better prefix check

cape.attdb.writedb.get_prefix(prefix=None, **kw)

Determine module name prefix based on current folder

Call:
>>> prefix = get_prefix(prefix=None, **kw)
Inputs:
prefix: {None} | str

Optional user-specified prefix

Outputs:
prefix: str

User-specified prefix or package from setuptools.find_packages()

Versions:
  • 2021-08-20 @ddalle: Version 1.0

cape.attdb.writedb.import_dbname(mod, dbname, **kw)

Import a module by DB_NAME instead of module spec

Call:
>>> mod2 = import_dbname(mod, dbname)
Inputs:
mod: module

Parent module

dbname: str

DB name like "SLS-10-D-AFA-004"

prefix: {None} | str

Optional user-specified prefix

Outputs:
mod2: module

Second module, having DB name matching dbname

Versions:
  • 2021-07-16 @ddalle: Version 1.0

  • 2021-08-20 @ddalle: Version 1.1; prefix option

cape.attdb.writedb.import_module(modname=None, prefix=None, **kw)

Import module from (possibly abbrev.) name

Call:
>>> mod = import_module(modname=None)
Inputs:
modname: None | str

Module name, possibly missing top-level prefix

prefix: {None} | str

Optional user-specified prefix

Outputs:
mod: module

Module with (possibly prefixed) name rev

Versions:
  • 2021-07-16 @ddalle: Version 1.0 (ATT-VM-CLVTOPS-003)

  • 2021-08-20 @ddalle: Version 1.1
    • automated default PREFIX

    • support empty modname

cape.attdb.writedb.main()

Main command-line interface function

Call:
>>> main()
Versions:
  • 2021-07-15 @ddalle: Version 1.0

  • 2021-07-17 @ddalle: Version 2.0
    • Move to write_dbs()

    • Add dependency tracking

    • Add -F option

  • 2021-08-20 @ddalle: Version 3.0
    • Generalize for cape

    • Add write_func option

cape.attdb.writedb.write_db(modname, **kw)

Convert source data to formatted datakit files

Call:
>>> write_db(modname, **kw)
Inputs:
modnames: tuple[str]

Names of module names to process

prefix: {None} | str

Optional user-specified prefix

f: True | {False}

Overwrite existing data files

write_func, func: {"write_db"} | str

Name of function to use to write formatted files

Versions:
  • 2017-07-13 @ddalle: Version 1.0

  • 2018-12-27 @ddalle: Version 2.0; using importlib

  • 2021-07-15 @ddalle: Version 2.1; Generalize for TNA/S-53

  • 2021-08-20 @ddalle: Version 3.0
    • move to cape from ATT-VM-CLVTOPS-003

    • generalize prefix using setuptools.find_packages()

    • add prefix, write_func kwargs

cape.attdb.writedb.write_dbs(*a, **kw)

Write one or more datakit modules, with dependencies

Call:
>>> write_dbs(*modnames, **kw)
Inputs:
modnames: tuple[str]

Names of modules to write, like "db0001"

prefix: {None} | str

Optional user-specified prefix

f, force: True | {False}

Overwrite any modules in a

F, force_all, force-all: True | {False}

Overwrite all modules, including dependencies

reqs, dependencies: {True} | False

Also process any modules listed in REQUIREMENTS in each modul in a

write: {True} | False

Flag to write databases (otherwise just print dependencies)

write_func, func: {"write_db"} | str

Name of function to use to write formatted files

Versions:
  • 2021-07-17 @ddalle: Version 1.0

  • 2021-07-19 @ddalle: Version 1.1; add write option

  • 2021-08-20 @ddalle: Version 1.2; generalize prefix