Ejemplo n.º 1
0
def main():
  uid = get_uid_from_cookie()
  storage_dir = os.path.join(app_dir, 'storage')
  uid_dir = os.path.join(storage_dir, 'users', uid['uid'])
  userconfig = read_user_config(uid)

  form = cgi.FieldStorage()  

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

  taskfile = ''


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

  if taskfile == '' or not os.path.exists(taskfile):
    raise RuntimeError('Task File does not exist')

  task = parse_xcsoar_task(taskfile)

  print "Content-Type: text/html"
  print
  print write_json_task(task)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def load(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config["USERS_FOLDER"], uid["uid"])
    userconfig = read_user_config(uid)

    taskfile = ""

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

    if taskfile == "" or not os.path.exists(taskfile):
        raise NotFound("Task File does not exist")

    task = parse_xcsoar_task(taskfile)

    return write_json_task(task)
Ejemplo n.º 4
0
def load(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])
    userconfig = read_user_config(uid)

    taskfile = ''

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

    if taskfile == '' or not os.path.exists(taskfile):
        raise NotFound('Task File does not exist')

    task = parse_xcsoar_task(taskfile)

    return write_json_task(task)
Ejemplo n.º 5
0
def load(taskname):
    uid = get_uid_from_cookie()
    uid_dir = os.path.join(current_app.config['USERS_FOLDER'], uid['uid'])
    userconfig = read_user_config(uid)

    taskfile = ''

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

    if taskfile == '' or not os.path.exists(taskfile):
        raise NotFound('Task File does not exist')

    task = parse_xcsoar_task(taskfile)

    return write_json_task(task)
Ejemplo n.º 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))
Ejemplo n.º 7
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.º 8
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))