Пример #1
0
def main():
  uid = get_uid_from_cookie()
  uid_dir = os.path.join(app_dir, 'storage', 'users', uid['uid'])

  form = cgi.FieldStorage()
  if form.has_key('task'):
    taskstring = form.getvalue('task')
    task = parse_json_task(form.getvalue('task'))

  else:
    reply_failure("No task.")
    sys.exit()

  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:
    f.write(create_xcsoar_task(task))
    reply_success(uid, taskname)
    sys.exit()

  reply_failure("Unknown failure.")
Пример #2
0
def main():
  form = cgi.FieldStorage()  
#  uid = get_uid_from_cookie()

  m = re.compile('([0-9a-z]*)').match(form.getvalue('uid'))
  uid = {'uid': m.group(1)}

  storage_dir = os.path.join(app_dir, 'storage')
  uid_dir = os.path.join(storage_dir, 'users', uid['uid'])
  userconfig = read_user_config(uid)

  m = re.compile('([^&+/;]*)').match(form.getvalue('task'))
  taskname = m.group(1)

  temptask = form.getvalue('temp', 0)
  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):
    print "Status: 404 Not Found"
    print "Content-type: text/html"
    print
    print "Task file not found: " + taskname
    sys.exit() 
#    raise RuntimeError('Task File does not exist')

  task = parse_xcsoar_task(taskfile)

  if (form.getvalue('filetype') == 'xcsoar'):
    print "Content-Type: application/xcsoar"
    print "Content-disposition: attachment; filename=" + taskname + ".tsk"
    print
    print create_xcsoar_task(task)

  elif (form.getvalue('filetype') == 'seeyou'):
    print "Content-Type: application/seeyou"
    print "Content-disposition: attachment; filename=" + taskname + ".cup"
    print
    print create_seeyou_task(task, taskname)
Пример #3
0
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])

    if "task" in request.values:
        taskstring = request.values["task"]
        task = parse_json_task(taskstring)

    else:
        return jsonify({"success": False, "reason": "No task."})

    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:
        f.write(create_xcsoar_task(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",
                    },
                },
            }
        )

    return jsonify({"success": False, "reason": "Unknown failure."})
Пример #4
0
def save_temp():
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

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

    else:
        return jsonify({'success': False, 'reason': 'No task.'})

    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:
        f.write(create_xcsoar_task(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',
                },
            }
        })

    return jsonify({'success': False, 'reason': 'Unknown failure.'})
Пример #5
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)

    if filetype == 'xcsoar':
        mimetype = 'application/xcsoar'
        file_extension = 'tsk'
        task = create_xcsoar_task(task)

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

    io = StringIO()
    io.write(task.encode('utf-8'))
    io.seek(0)

    return send_file(io,
                     mimetype=mimetype,
                     as_attachment=True,
                     attachment_filename=(taskname + '.' + file_extension))
Пример #6
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)

    if filetype == "xcsoar":
        mimetype = "application/xcsoar"
        file_extension = "tsk"
        task = create_xcsoar_task(task)

    elif filetype == "seeyou":
        mimetype = "application/seeyou"
        file_extension = "cup"
        task = create_seeyou_task(task, taskname)

    io = StringIO()
    io.write(task.encode("utf-8"))
    io.seek(0)

    return send_file(io, mimetype=mimetype, as_attachment=True, attachment_filename=(taskname + "." + file_extension))
Пример #7
0
def main():
  uid = get_uid_from_cookie()
  uid_dir = os.path.join(app_dir, 'storage', 'users', uid['uid'])

  form = cgi.FieldStorage()
  if form.has_key('task'):
    taskstring = form.getvalue('task')
    task = parse_json_task(form.getvalue('task'))

  else:
    reply_failure("No task.")
    sys.exit()

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

  if task_name == '':
    reply_failure("Invalid task name.")
    sys.exit()

  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:
    reply_failure("Too much tasks saved already (maximum of 20 reached).")
    sys.exit()
#    raise RuntimeError('Too much tasks saved')
 
  filename = 'task_'+str(taskid+1)+'.tsk'
  d = datetime.today()

  with open(os.path.join(uid_dir, filename), 'w') as f:
    f.write(create_xcsoar_task(task))
    
    if not replace:
      userconfig['task_files'].append({'id': taskid+1,
                                       'name': task_name,
                                       'distance': task.distance,
                                       'type': task.type,
                                       'turnpoints': len(task),
                                       'date': d.isoformat() })
    else:
      userconfig['task_files'][taskid] = {'id': taskid+1,
                                       'name': task_name,
                                       'distance': task.distance,
                                       'type': task.type,
                                       'turnpoints': len(task),
                                       'date': d.isoformat() }

    write_user_config(uid, userconfig)
    reply_success(uid)
    exit()

  reply_failure("Unknown failure.")
Пример #8
0
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])

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

    else:
        return jsonify({'success': False, 'reason': 'No task.'})

    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:
        f.write(create_xcsoar_task(task))

        if not replace:
            userconfig['task_files'].append({
                'id': taskid + 1,
                'name': task_name,
                'distance': task.distance,
                'type': task.type,
                'turnpoints': len(task),
                'date': d.isoformat()
            })
        else:
            userconfig['task_files'][taskid] = {
                'id': taskid + 1,
                'name': task_name,
                'distance': task.distance,
                'type': task.type,
                'turnpoints': len(task),
                'date': d.isoformat()
            }

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

    return jsonify({'success': False, 'reason': 'Unknown failure.'})
Пример #9
0
def save(task_name):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])

    if "task" in request.values:
        taskstring = request.values["task"]
        task = parse_json_task(taskstring)

    else:
        return jsonify({"success": False, "reason": "No task."})

    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:
        f.write(create_xcsoar_task(task))

        if not replace:
            userconfig["task_files"].append(
                {
                    "id": taskid + 1,
                    "name": task_name,
                    "distance": task.distance,
                    "type": task.type,
                    "turnpoints": len(task),
                    "date": d.isoformat(),
                }
            )
        else:
            userconfig["task_files"][taskid] = {
                "id": taskid + 1,
                "name": task_name,
                "distance": task.distance,
                "type": task.type,
                "turnpoints": len(task),
                "date": d.isoformat(),
            }

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

    return jsonify({"success": False, "reason": "Unknown failure."})