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)
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)
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)
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)
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)
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))
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))
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))