Skip to content
Snippets Groups Projects
Commit 8676e52d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[dbexecution] Added missing doc and fixed doc related warning

Also fixed import warnings
parent 281b33f7
Branches
Tags
2 merge requests!17Merge development branch 1.5.x,!13Improve documentation
......@@ -26,18 +26,25 @@
###############################################################################
'''Execution utilities'''
"""
===========
dbexecution
===========
Execution utilities
"""
import os
import logging
logger = logging.getLogger(__name__)
import simplejson
# from . import schema
from .database import Database
from .message_handler import MessageHandler
logger = logging.getLogger(__name__)
class DBExecutor(object):
......@@ -48,10 +55,11 @@ class DBExecutor(object):
prefix (str): Establishes the prefix of your installation.
data (dict, str): The piece of data representing the block to be executed.
data (dict, str): The piece of data representing the block to be
executed.
It must validate against the schema defined for execution blocks. If a
string is passed, it is supposed to be a fully qualified absolute path to
a JSON file containing the block execution information.
string is passed, it is supposed to be a fully qualified absolute path
to a JSON file containing the block execution information.
dataformat_cache (:py:class:`dict`, Optional): A dictionary mapping
dataformat names to loaded dataformats. This parameter is optional and,
......@@ -70,8 +78,8 @@ class DBExecutor(object):
Attributes:
errors (list): A list containing errors found while loading this execution
block.
errors (list): A list containing errors found while loading this
execution block.
data (dict): The original data for this executor, as loaded by our JSON
decoder.
......@@ -89,15 +97,15 @@ class DBExecutor(object):
input_list (inputs.InputList): A list of inputs that will be served to
the algorithm.
data_sources (list): A list with all data-sources created by our execution
loader.
data_sources (list): A list with all data-sources created by our
execution loader.
"""
def __init__(self, message_handler, prefix, cache_root, data, dataformat_cache=None,
database_cache=None):
def __init__(self, message_handler, prefix, cache_root, data,
dataformat_cache=None, database_cache=None):
# Initialisations
# Initialisation
self.prefix = prefix
self.databases = {}
self.views = {}
......@@ -112,7 +120,7 @@ class DBExecutor(object):
self.dataformat_cache = dataformat_cache if dataformat_cache is not None else {}
# Load the data
if not isinstance(data, dict): # User has passed a file name
if not isinstance(data, dict): # User has passed a file name
if not os.path.exists(data):
self.errors.append('File not found: %s' % data)
return
......@@ -134,9 +142,9 @@ class DBExecutor(object):
# Load the database
if details['database'] not in self.databases:
if details['database'] in database_cache: #reuse
if details['database'] in database_cache: # reuse
db = database_cache[details['database']]
else: #load it
else: # load it
db = Database(self.prefix, details['database'],
self.dataformat_cache)
database_cache[db.name] = db
......@@ -156,7 +164,7 @@ class DBExecutor(object):
if key not in self.views:
view = db.view(details['protocol'], details['set'])
if details['channel'] == self.data['channel']: #synchronized
if details['channel'] == self.data['channel']: # synchronized
start_index, end_index = self.data.get('range', (None, None))
else:
start_index, end_index = (None, None)
......@@ -178,15 +186,16 @@ class DBExecutor(object):
self.message_handler.set_data_sources(self.data_sources)
def process(self):
self.message_handler.start()
""" Starts the message handler"""
self.message_handler.start()
@property
def address(self):
return self.message_handler.address
""" Address of the message handler"""
return self.message_handler.address
@property
def valid(self):
......@@ -195,6 +204,8 @@ class DBExecutor(object):
def wait(self):
"""Wait for the message handle to finish"""
self.message_handler.join()
self.message_handler = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment