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 *
,
- You can import them like
- We call all folders in the
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 runsupdate_db()
.We pass the database from
update_db()
to a newbfly.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 forCoreLayer
-
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 - port (int) – for
-
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 newCoreLayer.Core
.Parameters: - db (
bfly.Butterfly._db_type
) – A fully-loaded database - config (dict) – Used in
AccessLayer.RequestHandler
-
_db
¶ bfly.Butterfly._db_type
– Taken from first argumentdb
-
_core
¶ CoreLayer.Core
– Also given thedb
argument
-
_webapp
¶ tornado.web.Application
– Allow access to content at /api and /ocp withAPI
andOCP
-
_server
¶ tornado.web.Application.IOLoop
– Allows us to stop thewebapp
. It is thewebapp
’s IOLoop instance. Only set afterstart()
starts_webapp
.
- db (
The bfly commands¶
-
bfly.__main__.
bfly
()[source]¶ Makes the
bfly.Butterfly
that does everything. Typebfly
in a shell afterbfly
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