Example #1
0
 def test_get_settings_creates_new_settings_document_if_document_is_missing(self):
     old_settings_doc = adms.get_settings_document()
     old_settings_id = old_settings_doc['_id']
     current_app.db.delete(old_settings_doc)
     new_settings_doc = adms.get_settings_document()
     new_settings_id = new_settings_doc['_id']
     assert old_settings_id != new_settings_id
Example #2
0
def both_still():
    '''
    Api endpoint for taking one or a series of 'both' stills - that is, Picam and Lepton stills which are then post-processed
      and merged into a single image
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{'name': 'delay', 'default': 0, 'cast_function': int},
                                                     {'name': 'repeat', 'default': 0, 'cast_function': int},
                                                     {'name': 'clean_up_files', 'default': True, 'cast_function': bool}])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        both_still_dict = take_both_still(
            snap_id=snap_id,
            group_id=group_id,
            delay=args_dict['delay'],
            repeat=args_dict['repeat'],
            clean_up_files=args_dict['clean_up_files'])

        return Response(json.dumps(both_still_dict), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
Example #3
0
def update_settings():
    settings = get_settings_document()
    if request.headers['Content-Type'] == 'application/json':
        for k in request.json.keys():
            if doc_attribute_can_be_set(k):
                settings[k] = request.json[k]
        save_document(settings)
        return Response(json.dumps(settings), status=200, mimetype='application/json')
Example #4
0
def get_settings():
    '''
    Returns the settings document (it's a singleton)
    '''
    try:
        settings = get_settings_document()
        return Response(json.dumps(settings), status=200, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
Example #5
0
def update_settings():
    settings = get_settings_document()
    if request.headers['Content-Type'] == 'application/json':
        for k in request.json.keys():
            if doc_attribute_can_be_set(k):
                settings[k] = request.json[k]
        save_document(settings)
        return Response(json.dumps(settings),
                        status=200,
                        mimetype='application/json')
Example #6
0
def save_group():
    settings = get_settings_document()
    group_dict = default_group_dict()
    if request.headers['Content-Type'] == 'application/json':
        for k in request.json.keys():
            if doc_attribute_can_be_set(k):
                group_dict[k] = request.json[k]
        save_document(group_dict)
        settings['current_group_id'] = group_dict['_id']
        save_document(settings)
        return Response(json.dumps(group_dict), status=200, mimetype='application/json')
Example #7
0
    def test_get_group_document_current_gets_the_current_group_document(self):
        settings_doc = adms.get_settings_document()

        some_other_group_id = str(uuid.uuid4())
        some_other_group_doc = {'type': 'group'}
        current_app.db[some_other_group_id] = some_other_group_doc

        group_doc_from_current = adms.get_group_document('current')

        assert group_doc_from_current['_id'] != some_other_group_id
        assert group_doc_from_current['_id'] == settings_doc['current_group_id']
Example #8
0
def picam_still():
    '''
    Api endpoint for taking one or a series of Picam stills.  
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()
    ret_dict = take_picam_still(snap_id=snap_id, group_id=group_id, delay=delay, repeat=repeat)
    return Response(json.dumps(ret_dict), status=202, mimetype='application/json')
Example #9
0
def get_settings():
    '''
    Returns the settings document (it's a singleton)
    '''
    try:
        settings = get_settings_document()
        return Response(json.dumps(settings),
                        status=200,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
Example #10
0
def save_group():
    settings = get_settings_document()
    group_dict = default_group_dict()
    if request.headers['Content-Type'] == 'application/json':
        for k in request.json.keys():
            if doc_attribute_can_be_set(k):
                group_dict[k] = request.json[k]
        save_document(group_dict)
        settings['current_group_id'] = group_dict['_id']
        save_document(settings)
        return Response(json.dumps(group_dict),
                        status=200,
                        mimetype='application/json')
Example #11
0
def update_settings():
    '''
    Updates the settings document
    '''
    try:
        settings = get_settings_document()
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    settings[k] = request.json[k]
            update_generic(settings, 'settings')
            return Response(json.dumps(settings), status=200, mimetype='application/json')
        err_msg = 'no valid settings parameters supplied'
        return Response(json.dumps(err_msg), status=409, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
Example #12
0
def picam_still():
    '''
    Api endpoint for taking one or a series of Picam stills.  
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()
    ret_dict = take_picam_still(snap_id=snap_id,
                                group_id=group_id,
                                delay=delay,
                                repeat=repeat)
    return Response(json.dumps(ret_dict),
                    status=202,
                    mimetype='application/json')
Example #13
0
def both_still_test():
    '''
    for experimental both_still
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still_test(snap_id=snap_id,
                                           group_id=group_id,
                                           delay=delay,
                                           repeat=repeat)

    return Response(json.dumps(both_still_dict),
                    status=202,
                    mimetype='application/json')
Example #14
0
def both_still_test():
    '''
    for experimental both_still
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still_test(
        snap_id=snap_id,
        group_id=group_id,
        delay=delay,
        repeat=repeat
    )

    return Response(json.dumps(both_still_dict), status=202, mimetype='application/json')
Example #15
0
def save_group():
    '''
    Creates a new group record, saves it as the new current group in the settings document
    Won't let you specify _id, _rev or type
    Automatically sets settings.current_group_id to the groups id as well
    '''
    return_value = generic_save_view(args_dict=default_group_dict(), document_type='group')
    if return_value.status_code == 200:
        try:
            group_id = json.loads(return_value.data)['_id']
            settings = get_settings_document()
            settings['current_group_id'] = group_id
            save_generic(settings, 'settings')
            return return_value
        except Exception as e:
            return Response(json.dumps('error saving settings: '+e.message), status=e.status_code, mimetype='application/json')
    else:
        return return_value
Example #16
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{
            'name': 'delay',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'repeat',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'clean_up_files',
            'default': True,
            'cast_function': bool
        }, {
            'name': 'scale_image',
            'default': True,
            'cast_function': bool
        }])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        ret_dict = take_thermal_still(
            snap_id=snap_id,
            group_id=group_id,
            delay=args_dict['delay'],
            repeat=args_dict['repeat'],
            scale_image=args_dict['scale_image'],
            clean_up_files=args_dict['clean_up_files'])
        return Response(json.dumps(ret_dict),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
Example #17
0
def both_still():
    '''
    Api endpoint for taking one or a series of 'both' stills - that is, Picam and Lepton stills which are then post-processed
      and merged into a single image
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still(
        snap_id=snap_id,
        group_id=group_id,
        delay=delay,
        repeat=repeat
    )

    return Response(json.dumps(both_still_dict), status=202, mimetype='application/json')
Example #18
0
def both_still():
    '''
    Api endpoint for taking one or a series of 'both' stills - that is, Picam and Lepton stills which are then post-processed
      and merged into a single image
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()

    both_still_dict = take_both_still(snap_id=snap_id,
                                      group_id=group_id,
                                      delay=delay,
                                      repeat=repeat)

    return Response(json.dumps(both_still_dict),
                    status=202,
                    mimetype='application/json')
Example #19
0
def save_group():
    '''
    Creates a new group record, saves it as the new current group in the settings document
    Won't let you specify _id, _rev or type
    Automatically sets settings.current_group_id to the groups id as well
    '''
    return_value = generic_save_view(args_dict=default_group_dict(),
                                     document_type='group')
    if return_value.status_code == 200:
        try:
            group_id = json.loads(return_value.data)['_id']
            settings = get_settings_document()
            settings['current_group_id'] = group_id
            save_generic(settings, 'settings')
            return return_value
        except Exception as e:
            return Response(json.dumps('error saving settings: ' + e.message),
                            status=e.status_code,
                            mimetype='application/json')
    else:
        return return_value
Example #20
0
def update_settings():
    '''
    Updates the settings document
    '''
    try:
        settings = get_settings_document()
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    settings[k] = request.json[k]
            update_generic(settings, 'settings')
            return Response(json.dumps(settings),
                            status=200,
                            mimetype='application/json')
        err_msg = 'no valid settings parameters supplied'
        return Response(json.dumps(err_msg),
                        status=409,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
Example #21
0
 def test_get_settings_fetches_a_real_settings_document(self):
     settings_doc = adms.get_settings_document()
     assert '_id' in settings_doc.keys()
     assert '_rev' in settings_doc.keys()
     assert 'current_group_id' in settings_doc.keys()
     assert settings_doc['type'] == 'settings'
Example #22
0
def get_settings():
    settings = get_settings_document()
    return Response(json.dumps(settings), status=200, mimetype='application/json')
Example #23
0
def get_settings():
    settings = get_settings_document()
    return Response(json.dumps(settings),
                    status=200,
                    mimetype='application/json')
Example #24
0
 def test_settings_points_to_a_real_group_document(self):
     settings_doc = adms.get_settings_document()
     group_doc = current_app.db[settings_doc['current_group_id']]
     assert group_doc['type'] == 'group'