Ejemplo n.º 1
0
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    d = datetime.now()
    taskname = d.strftime('%w') + str(d.hour * 3600 + d.minute * 60 + d.second)
    filename = 'tasktemp_' + taskname + '.tsk'

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    base_url = 'tasks/' + uid['uid'] + '/temp/' + taskname
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False),
        'download': {
            'xcsoar': {
                'name': 'XCSoar (*.tsk)',
                'url': base_url + '/xcsoar',
                'qrcode': base_url + '/xcsoar/qr',
            },
            'seeyou': {
                'name': 'SeeYou (*.cup)',
                'url': base_url + '/seeyou',
                'qrcode': base_url + '/seeyou/qr',
            },
        }
    })
Ejemplo n.º 2
0
def download(uid, taskname, filetype, temptask=False):
    uid = {'uid': uid}

    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])
    userconfig = read_user_config(uid)

    taskfile = ''

    if not temptask:
        for d in userconfig['task_files']:
            if d.get('name') == taskname:
                taskfile = os.path.join(uid_dir,
                                        'task_' + str(d.get('id')) + '.tsk')

    else:
        taskfile = os.path.join(uid_dir, 'tasktemp_' + str(taskname) + '.tsk')

    if taskfile == '' or not os.path.exists(taskfile):
        raise NotFound('Task file not found: ' + taskname)

    task = parse_xcsoar_task(taskfile)

    io = StringIO()
    if filetype == 'xcsoar':
        mimetype = 'application/xcsoar'
        file_extension = 'tsk'
        write_xcsoar_task(io, task)

    elif filetype == 'seeyou':
        mimetype = 'application/seeyou'
        file_extension = 'cup'
        write_seeyou_task(io, task, taskname)

    io.seek(0)

    return send_file(io,
                     mimetype=mimetype,
                     as_attachment=True,
                     attachment_filename=(taskname + '.' + file_extension))
Ejemplo n.º 3
0
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    d = datetime.now()
    taskname = d.strftime('%w') + str(d.hour * 3600 + d.minute * 60 + d.second)
    filename = 'tasktemp_' + taskname + '.tsk'

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    base_url = 'tasks/' + uid['uid'] + '/temp/' + taskname
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False),
        'download': {
            'xcsoar': {
                'name': 'XCSoar (*.tsk)',
                'url': base_url + '/xcsoar',
                'qrcode': base_url + '/xcsoar/qr',
            },
            'seeyou': {
                'name': 'SeeYou (*.cup)',
                'url': base_url + '/seeyou',
                'qrcode': base_url + '/seeyou/qr',
            },
        }
    })
Ejemplo n.º 4
0
def download(uid, taskname, filetype, temptask=False):
    uid = {'uid': uid}

    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])
    userconfig = read_user_config(uid)

    taskfile = ''

    if not temptask:
        for d in userconfig['task_files']:
            if d.get('name') == taskname:
                taskfile = os.path.join(
                    uid_dir, 'task_' + str(d.get('id')) + '.tsk')

    else:
        taskfile = os.path.join(uid_dir, 'tasktemp_' + str(taskname) + '.tsk')

    if taskfile == '' or not os.path.exists(taskfile):
        raise NotFound('Task file not found: ' + taskname)

    task = parse_xcsoar_task(taskfile)

    io = StringIO()
    if filetype == 'xcsoar':
        mimetype = 'application/xcsoar'
        file_extension = 'tsk'
        write_xcsoar_task(io, task)

    elif filetype == 'seeyou':
        mimetype = 'application/seeyou'
        file_extension = 'cup'
        write_seeyou_task(io, task, taskname)

    io.seek(0)

    return send_file(io, mimetype=mimetype, as_attachment=True,
                     attachment_filename=(taskname + '.' + file_extension))
Ejemplo n.º 5
0
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    m = re.compile('([^&+/;]*)').match(task_name)
    task_name = m.group(1)

    if task_name == '':
        return jsonify({'success': False, 'reason': 'Invalid task name.'})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    replace = False

    taskid = len(userconfig['task_files'])

    for key, value in enumerate(userconfig['task_files']):

        if value['name'] == task_name:
            replace = True
            taskid = key
            break

    if taskid >= 20:
        return jsonify({
            'success': False,
            'reason': 'Too much tasks saved already (maximum of 20 reached).'
        })

    filename = 'task_' + str(taskid + 1) + '.tsk'
    d = datetime.today()

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    taskinfo = {
        'id': taskid + 1,
        'name': task_name,
        'distance': task.distance,
        'type': task.type,
        'turnpoints': len(task),
        'date': d.isoformat()
    }

    if not replace:
        userconfig['task_files'].append(taskinfo)
    else:
        userconfig['task_files'][taskid] = taskinfo

    write_user_config(uid, userconfig)
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False)
    })
Ejemplo n.º 6
0
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

    if 'task' not in request.values:
        return jsonify({'success': False, 'reason': 'No task.'})

    taskstring = request.values['task']
    task = parse_json_task(taskstring)

    m = re.compile('([^&+/;]*)').match(task_name)
    task_name = m.group(1)

    if task_name == '':
        return jsonify({'success': False, 'reason': 'Invalid task name.'})

    userconfig = read_user_config(uid)

    if not os.path.exists(uid_dir):
        write_user_config(uid, userconfig)

    replace = False

    taskid = len(userconfig['task_files'])

    for key, value in enumerate(userconfig['task_files']):

        if value['name'] == task_name:
            replace = True
            taskid = key
            break

    if taskid >= 20:
        return jsonify({
            'success':
            False,
            'reason':
            'Too much tasks saved already (maximum of 20 reached).'
        })

    filename = 'task_' + str(taskid + 1) + '.tsk'
    d = datetime.today()

    with open(os.path.join(uid_dir, filename), 'w') as f:
        write_xcsoar_task(f, task)

    taskinfo = {
        'id': taskid + 1,
        'name': task_name,
        'distance': task.distance,
        'type': task.type,
        'turnpoints': len(task),
        'date': d.isoformat()
    }

    if not replace:
        userconfig['task_files'].append(taskinfo)
    else:
        userconfig['task_files'][taskid] = taskinfo

    write_user_config(uid, userconfig)
    return jsonify({
        'success': True,
        'settings': get_user_config_as_json(uid, encoded=False)
    })