The bfly package

definitions

  • We refer to system paths relative to ./. The path ./ gives the root folder of the butterfly source. You can see this path with these commands in a bash shell.
git clone https://github.com/Rhoana/butterfly
cd butterfly && pwd
  • We call all folders in the bfly package “layers”.
    • You can import them like from bfly import CoreLayer,
    • Or, import from them like from bfly.CoreLayer import *,

All layers

You can import bfly from ./ or with bfly installed.

You can from bfly import any layer.

import bfly
from bfly import DatabaseLayer, AccessLayer
from bfly import QueryLayer, ImageLayer, UtilityLayer

All CoreLayer

bfly.CoreLayer

alias of bfly.CoreLayer

bfly.DatabaseLayer

alias of bfly.CoreLayer.DatabaseLayer

bfly.AccessLayer

alias of bfly.CoreLayer.AccessLayer

The bfly classes

class bfly.Butterfly(_argv)[source]

Starts bfly.Webserver and runs update_db().

We pass the database from update_db() to a new bfly.Webserver.

Parameters:_argv (list) – passed through parse_argv()
_log_info = {'level': 20, 'filename': 'bfly.log'}

path to log and the log priority level

_db_type = 'Nodb'

class of DatabaseLayer

_db_path = 'bfly.db'

relative path to .db file

_bfly_config

dict – all data from UtilityLayer.rh_config

_runtime

UtilityLayer.RUNTIME – has settings for CoreLayer

static get_parser()[source]

Makes an argv parser for Butterfly.

Returns:map from argv lists to args and keywords
Return type:argparse.ArgumentParser
parse_argv(argv)[source]

Converts argv list to dictionary with defaults.

Parameters:argv (list) – parsed as sys.argv by argparse
Returns:
  • port (int) – for bfly.Webserver
  • exp (str) – path to config or folder of data
  • out (str) – path to save config from folder
Return type:dict
update_db()[source]

Starts DatabaseLayer. _db_type.

Creates the DatabaseLayer with the path from _db_path and with all values from _runtime.

Runs DatabaseLayer.load_config() with paths from _bfly_config.

class bfly.Webserver(db, config)[source]

Starts the CoreLayer.Core and tornado web app.

Sends the db argument to the new CoreLayer.Core.

Parameters:
_maxbuffer = 209715200

Max bytes of memory for _webapp

_db

bfly.Butterfly._db_type – Taken from first argument db

_core

CoreLayer.Core – Also given the db argument

RUNTIME

RUNTIME – Shared runtime instance with _db

_webapp

tornado.web.Application – Allow access to content at /api and /ocp with API and OCP

_server

tornado.web.Application.IOLoop – Allows us to stop the webapp. It is the webapp’s IOLoop instance. Only set after start() starts _webapp.

_port

int – Only set after port passed to start()

start(_port)[source]

Starts the _webapp on the given port

Sets two new class attributes:
Parameters:_port (int) – The port number to serve all entry points
Returns:The _server needed to stop the _webapp
Return type:tornado.IOLoop
stop()[source]

Stops the _webapp.

Adds a _server`.``stop`` callback to _server. This stops _server, which is also known as the _webapp’s IOLoop.

Parameters:_port (int) – The port number to serve all entry points. Also sets the class attribute _port

The bfly commands

bfly.__main__.bfly()[source]

Makes the bfly.Butterfly that does everything. Type bfly in a shell after bfly installed.

usage: bfly [-h] [-e EXP] [-o OUT] [port] Host a butterfly server! positional arguments: port port >1024 for hosting this server optional arguments: -h, –help show this help message and exit -e EXP, –exp EXP path/of/all/data or path/to/config -o OUT, –out OUT path to output yaml config file