The UtilityLayer

You can import from ./ or with bfly installed.

from bfly import UtilityLayer

Or, in scripts in some directories:

# if './bfly/' in sys.path
from CoreLayer.AccessLayer import UtilityLayer
# if './bfly/CoreLayer/' in sys.path
from AccessLayer import UtilityLayer
# if './bfly/CoreLayer/AccessLayer' in sys.path
from QueryLayer import UtilityLayer
# if './bfly/CoreLayer/AccessLayer/QueryLayer' in sys.path
import UtilityLayer

UtilityLayer

Provieds Keywords, Logging templates, and an argument handler.

UtilityLayer.BFLY_CONFIG

dict – Loads all data from the rh-config givenby the rh_config module.

UtilityLayer.PORT = 2001
UtilityLayer.DB_TYPE = 'Nodb'
UtilityLayer.DB_PATH = 'bfly.db'

You can import UtilityLayer from bfly, CoreLayer, AccessLayer, and QueryLayer.

UtilityLayer classes

class UtilityLayer.INPUT[source]

Keywords to read input files and requests All the attributes and their attributes store a mutable VALUE of and type, and some store a static NAME that should always be used externally.

METHODS

NamedStruct – All methods for RequestHandler requests

GROUP

NamedStruct – All groups from the UtilityLayer.BFLY_CONFIG

FEATURES

NamedStruct – All features for /api/entity_feature requests

POSITION

NamelessStruct – Center coordintates for Database.load_config() All coordinates for RequestHandler requests

RESOLUTION

NamelessStruct – All resolutions for RequestHandler requests

INFO

NamelessStruct – Formats for /api/channel_metadata requests and id for /api/entity_feature requests

IMAGE

NamelessStruct – Formats and views for RequestHandler data or mask requests.

class UtilityLayer.RUNTIME[source]

Keywords passed between classes and layers. All the attributes and their attributes store a mutable VALUE of and type, and some store a static NAME that should always be used externally.

TILE

NamelessStruct – For QueryLayer.TileQuery

IMAGE

NamelessStruct – For QueryLayer.DataQuery

CACHE

NamelessStruct – For CoreLayer.Cache

DB

NamelessStruct – For DatabaseLayer

class UtilityLayer.OUTPUT[source]

Keywords used for writing out from server. All the attributes and their attributes store a mutable VALUE of and type, and some store a static NAME that should always be used externally.

INFO

NamelessStruct – Outputs for /api/channel_metadata requests

FEATURES

NamelessStruct – Outputs for /api/entity_feature requests

Private classes

class UtilityLayer.NamedStruct(_name, **_keywords)[source]

It’s a NamelessStruct with a NAME attribute.

Parameters:
  • _name (str) – The name becomes NAME
  • _keywords (dict) – Each keyword becomes an attribute
NAME

str – This is a constant used externally whenever passing the VALUE attribute between classes, methods, and external files. All NamedStruct or NamelessStruct with a NamedStruct attribute can access the NameStruct with the NAME as a dictionary key such as parent[‘a_name’].

LIST

list – see NamelessStruct.LIST

VALUE

anything – see NamelessStruct.VALUE

Methods

_n_get(name)

Get a NamedStruct attribute by NAME.

Parameters:name (str) – The NAME attribute of the requested NamedStruct.
class UtilityLayer.NamelessStruct(**_keywords)[source]

Provides a dictionary-like class interface

Parameters:_keywords (dict) – Each keyword becomes an attribute
VALUE

anything – Any instance has its own mutable VALUE.

LIST

list – All unique attributes are given here. If ‘LIST’ is given as a keyword, the orderof the attributes given in the ‘LIST’ keywordis preserved at the top of the LIST.

Methods

_n_get(name)[source]

Get a NamedStruct attribute by NAME.

Parameters:name (str) – The NAME attribute of the requested NamedStruct.
__contains__(key)[source]

Check for names or attributes in instance

__getitem__(key)[source]

Get any attribute as if from a dictionary

If the attribute is a NamedStruct, then the key can be either the attribute or the NAME of the attribute. The key is first used as an attribute and then used as a NAME with _n_get() if not an attribute.

Parameters:key (str) – The attribute to get
get(key, default=None)[source]

Get any attribute with a default value

This returns __getitem__() or default.

Parameters:
  • key (str) – The attribute to get
  • default (anything) – The value if attribute is not found.
__weakref__

list of weak references to the object (if defined)

UtilityLayer functions

UtilityLayer.to_argv(*args, **flags)

Turns arguments and keywords into a list

Parameters:
  • args (list) – All in list must be able to become str
  • flags (dict) – All keys,values in dict must be able to become str
Returns:

Allows argparse.ArgumentParser to handle a list and dictionary in the same way that it would handle sys.argv.

Return type:

list

The Settings module

Loads Settings from UtilityLayer.rh_config

UtilityLayer.Settings.LOG_PATH

int – Write logs to bfly.log or ‘log-path’ from config

UtilityLayer.Settings.DB_TYPE

int – Use Unqlite database or ‘db-type’ from config

UtilityLayer.Settings.DB_PATH

int – Write data to bfly.db or ‘db-path’ from config

UtilityLayer.Settings.PORT

int – Serve on 2001 or ‘port’ from config

UtilityLayer.Settings.MAX_CACHE_SIZE

int – Cache 1024^3 bytes or 1024^2 times ‘max-cache-size’in megabytes from config

UtilityLayer.Settings.BFLY_CONFIG

dict – Values from ‘bfly’ key of config

UtilityLayer.Settings.config

dict – From UtilityLayer.rh_config.config

UtilityLayer.Settings.config_filename

str – From UtilityLayer.rh_config.config_filename

The rh_config module

Loads config from the path config_filename

UtilityLayer.rh_config.config_filename

str – Tries environment variable “RH_CONFIG_FILENAME” but defaults to ~/.rh-config.yaml.

UtilityLayer.rh_config.config

dict – Loaded from a yaml file at config_filename