コード例 #1
0
def data_config_filter():
    rst = []
    notch = bottle.request.query.get('notch')
    if notch is not None:
        try:
            freq = int(notch)
        except ValueError:
            try:
                pt.notch = get_boolean(notch)
            except ValueError:
                bottle.abort(400, 'Invalid notch value: %s' % notch)
        else:
            pt.notch = freq
        rst.append('Realtime notch filter state: {}'.format(pt.notch or 'OFF'))
    low = bottle.request.query.get('low')
    high = bottle.request.query.get('high')
    if None not in [low, high]:
        try:
            low, high = float(low), float(high)
        except ValueError:
            bottle.abort(400, 'Invalid bandpass argument! Only accept number.')
        if low == high == 0:
            pt.bandpass.clear()
            rst.append('Realtime bandpass filter state: OFF')
        elif high < low or low < 0:
            bottle.abort(400, 'Invalid bandpass argument! 0 < Low < High.')
        else:
            pt.bandpass.low = max(1, low)
            pt.bandpass.high = min(reader.sample_rate // 2 - 1, high)
            process_register(reader.data_frame, pt)
            rst.append(
                'Realtime bandpass filter param: {low}Hz -- {high}Hz'.format(
                    **pt.bandpass))
    if rst:
        return minimize(rst)
コード例 #2
0
def wifi_toggle(boolean):
    boolean = get_boolean(boolean)
    try:
        nm.Enable(boolean)
    except dbus.exceptions.DBusException as e:
        if e.get_dbus_name() != \
                'org.freedesktop.NetworkManager.AlreadyEnabledOrDisabled':
            return (False, str(e))
        return (True, 'already ' + ('enabled' if boolean else 'disabled'))
    return (wifi_status(boolean), 'success')
コード例 #3
0
def base_datafile_info(filename):
    path = os.path.join(DIR_DATA, filename)
    if not os.path.exists(path):
        bottle.abort(400, 'Data file not exists: `%s`' % filename)
    if get_boolean(bottle.request.query.get('download', 'False')):
        dirname, basename = os.path.split(path)
        return bottle.static_file(basename, dirname, download=True)
    stat = os.stat(path)
    return {
        name: getattr(stat, name)
        for name in [
            'st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid',
            'st_size', 'st_atime', 'st_mtime', 'st_ctime'
        ]
    }
コード例 #4
0
def test_get_boolean():
    assert (get_boolean('True') and get_boolean('yes')
            and not get_boolean('No') and not get_boolean('off')
            and get_boolean('1'))
コード例 #5
0
def config_impedance(impedance):
    try:
        reader.measure_impedance = get_boolean(impedance)
    except ValueError:
        return ('Invalid impedance: `{}`! '.format(impedance) +
                'Choose one from `True` | `False`')
コード例 #6
0
def config_bias(bias):
    try:
        reader.enable_bias = get_boolean(bias)
    except ValueError:
        return ('Invalid bias `{}`! ' +
                'Choose one from `True` | `False`').format(bias)
コード例 #7
0
def config_detrend(detrend):
    try:
        pt.detrend = get_boolean(detrend)
    except ValueError:
        return ('Invalid detrend `{}`! '.format(detrend) +
                'Choose one from `True` | `False`')
コード例 #8
0
 def event_merge(self, v):
     self._event_merge = get_boolean(v)