diff --git a/beat/backend/python/database.py b/beat/backend/python/database.py index 20853102fbedb64a8cf27f4359ddd09674f50f9c..e6a170ab52f63beda9c9064bc5e009bc85a60ad2 100644 --- a/beat/backend/python/database.py +++ b/beat/backend/python/database.py @@ -26,7 +26,13 @@ ############################################################################### -"""Validation of databases""" +""" +======== +database +======== + +Validation of databases +""" import os import sys @@ -44,7 +50,7 @@ from .dataformat import DataFormat from .outputs import OutputList -#---------------------------------------------------------- +# ---------------------------------------------------------- class Storage(utils.CodeStorage): @@ -70,10 +76,11 @@ class Storage(utils.CodeStorage): path = os.path.join(self.prefix, 'databases', name + '.json') path = path[:-5] - super(Storage, self).__init__(path, 'python') #views are coded in Python + # views are coded in Python + super(Storage, self).__init__(path, 'python') -#---------------------------------------------------------- +# ---------------------------------------------------------- class Runner(object): @@ -109,7 +116,7 @@ class Runner(object): type, value, traceback = sys.exc_info() six.reraise(exc, exc(value), traceback) else: - raise # just re-raise the user exception + raise # just re-raise the user exception self.obj = loader.run(class_, '__new__', exc) self.ready = False @@ -183,7 +190,7 @@ class Runner(object): return self.obj.objs -#---------------------------------------------------------- +# ---------------------------------------------------------- class Database(object): @@ -217,7 +224,7 @@ class Database(object): self._name = None self.prefix = prefix - self.dataformats = {} # preloaded dataformats + self.dataformats = {} # preloaded dataformats self.storage = None self.errors = [] @@ -330,8 +337,9 @@ class Database(object): @property def valid(self): - return not bool(self.errors) + """A boolean that indicates if this database is valid or not""" + return not bool(self.errors) @property def protocols(self): @@ -380,13 +388,15 @@ class Database(object): Parameters: - protocol (str): The name of the protocol where to retrieve the view from + protocol (str): The name of the protocol where to retrieve the view + from name (str): The name of the set in the protocol where to retrieve the view from exc (:std:term:`class`): If passed, must be a valid exception class - that will be used to report errors in the read-out of this database's view. + that will be used to report errors in the read-out of this + database's view. Returns: @@ -407,7 +417,8 @@ class Database(object): raise RuntimeError(message) - # loads the module only once through the lifetime of the database object + # loads the module only once through the lifetime of the database + # object try: if not hasattr(self, '_module'): self._module = loader.load_module(self.name.replace(os.sep, '_'), @@ -417,7 +428,7 @@ class Database(object): type, value, traceback = sys.exc_info() six.reraise(exc, exc(value), traceback) else: - raise #just re-raise the user exception + raise # just re-raise the user exception if root_folder is None: root_folder = self.data['root_folder'] @@ -432,7 +443,8 @@ class Database(object): Parameters: - indent (int): The number of indentation spaces at every indentation level + indent (int): The number of indentation spaces at every indentation + level Returns: @@ -463,7 +475,7 @@ class Database(object): if storage is None: if not self._name: raise RuntimeError("database has no name") - storage = self.storage #overwrite + storage = self.storage # overwrite storage.save(str(self), self.code, self.description) @@ -506,7 +518,7 @@ class Database(object): self.write(Storage(prefix, self.name)) -#---------------------------------------------------------- +# ---------------------------------------------------------- class View(object): @@ -515,8 +527,8 @@ class View(object): """Returns a list of (named) tuples describing the data provided by the view. The ordering of values inside the tuples is free, but it is expected - that the list is ordered in a consistent manner (ie. all train images of - person A, then all train images of person B, ...). + that the list is ordered in a consistent manner (ie. all train images + of person A, then all train images of person B, ...). For instance, assuming a view providing that kind of data: @@ -558,7 +570,7 @@ class View(object): def setup(self, root_folder, parameters, objs, start_index=None, end_index=None): - # Initialisations + # Initialisation self.root_folder = root_folder self.parameters = parameters self.objs = objs @@ -571,14 +583,15 @@ class View(object): def get(self, output, index): - """Returns the data of the provided output at the provided index in the list - of (named) tuples describing the data provided by the view (accessible at - self.objs)""" + """Returns the data of the provided output at the provided index in the + list of (named) tuples describing the data provided by the view + (accessible at self.objs) + """ raise NotImplementedError -#---------------------------------------------------------- +# ---------------------------------------------------------- class DatabaseTester: @@ -807,7 +820,8 @@ class DatabaseTester: # Compute the next data index that should be produced next_index = 1 + min([ x.written_data[-1][1] for x in outputs if x.isConnected() ]) - # Compute the next data index that should be produced by each connected output + # Compute the next data index that should be produced by each + # connected output for name in connected_outputs.keys(): if name not in self.irregular_outputs: if next_index == next_expected_indices[name] + connected_outputs[name]: @@ -827,7 +841,8 @@ class DatabaseTester: assert(outputs[name].written_data[-1][1] == next_index - 1) - # Generate a text file with lots of details (only if all outputs are connected) + # Generate a text file with lots of details (only if all outputs are + # connected) if len(connected_outputs) == len(self.outputs_declaration): sorted_outputs = sorted(outputs, key=lambda x: len(x.written_data))