示例#1
0
 def sort_by(col, sort_desc=True):
     if len(self._cols) == 0:
         raise FilamentError('Expected at least 1 column but 0 found')
     if col not in self._cols:
         raise FilamentError('%s column does not exist' % col)
     self._sort_by = col
     self._sort_desc = sort_desc
示例#2
0
    def load_filament(self, name):
        Filament._assert_root_dir()
        [filament_path] = [
            os.path.join(FILAMENTS_DIR, filament)
            for filament in os.listdir(FILAMENTS_DIR)
            if filament.endswith('.py') and name == filament[:-3]
        ] or [None]
        if filament_path:
            loader = SourceFileLoader(name, filament_path)
            self._filament = loader.load_module()
            # check for required methods
            # on the filament module
            doc = inspect.getdoc(self._filament)
            if not doc:
                raise FilamentError(
                    "Please provide a short description for the filament")

            [on_next_kevent] = self._find_func('on_next_kevent')
            if on_next_kevent:
                args_spec = inspect.getargspec(on_next_kevent)
                if len(args_spec.args) != 1:
                    raise FilamentError(
                        'Missing one argument on_next_kevent method on filament'
                    )
            else:
                raise FilamentError(
                    'Missing required on_next_kevent method on filament')
        else:
            raise FilamentError('%s filament not found' % name)
示例#3
0
 def limit(limit):
     if len(self._cols) == 0:
         raise FilamentError(
             'Expected at least 1 column but 0 found')
     if not type(limit) is int:
         raise FilamentError('Limit must be an integer value')
     self._limit = limit
示例#4
0
 def columns(cols):
     if not isinstance(cols, list):
         raise FilamentError('Columns must be a list, '
                             '%s found' % type(cols))
     self._cols = cols
     self._tabular = Tabular(self._cols)
     self._tabular.padding_width = 10
     self._tabular.junction_char = '|'
示例#5
0
    def load_filament(self, name):
        """Loads the filament module.

        Finds and loads the python module which
        holds the filament logic. It also looks up for
        some essential filament methods and raises an error
        if they can't be found.

        Parameters
        ----------
        name: str
            name of the filament to load

        """
        self._name = name
        Filament._assert_root_dir()
        filament_path = self._find_filament_path(name)
        if filament_path:
            loader = SourceFileLoader(name, filament_path)
            self._filament_module = loader.load_module()
            sys.path.append(FILAMENTS_DIR)
            doc = inspect.getdoc(self._filament_module)
            if not doc:
                raise FilamentError('Please provide a short '
                                    'description for the filament')

            on_next_kevent = self._find_filament_func('on_next_kevent')
            if on_next_kevent:
                if self._num_args(on_next_kevent) != 1:
                    raise FilamentError('Missing one argument on_next_kevent '
                                        'method on filament')
                self._initialize_funcs()
            else:
                raise FilamentError('Missing required on_next_kevent '
                                    'method on filament')
        else:
            raise FilamentError('%s filament not found' % name)
示例#6
0
 def add_row(row):
     if not isinstance(row, list):
         raise FilamentError(
             'Expected list type for the row, found %s' % type(row))
     self._tabular.add_row(row)
示例#7
0
 def set_interval(interval):
     if not type(interval) is int:
         raise FilamentError('Interval must be an integer value')
     self._interval = interval