Пример #1
0
def stats():
    conf = data.get_conf()
    if 'user' not in conf or 'dir' not in conf:
        return ""

    info = {}

    info['exportees'] = requests.post(sync.root + '/export_breakdown/' +
                                      conf['user']).json()['export_capacities']

    info['exporters'] = [{
        "name": get_friend_name(id),
        "capacity": capacity_for_friend(id)
    } for id in conf['friends'] if len(id) > 0]

    progress = requests.get(sync.root + '/backup_progress/' +
                            conf['user']).json()

    info['backup_progress'] = progress['backup_progress']

    data_size = size_for_dir(conf['dir'])
    remaining_to_restore = progress['capacity_left_to_restore']
    info['restore_progress'] = 1 - remaining_to_restore * 1.0 / (
        data_size + remaining_to_restore) if (data_size +
                                              remaining_to_restore) else 0

    return templ8("stats.html", info)
Пример #2
0
def settings():
    conf = data.get_conf()
    if 'user' not in conf:
        info = requests.post(sync.root + "/sign_up", {
            "name": platform.node()
        }).json()
        conf['user'] = info['user']
        conf['secret'] = info['secret']
        conf['friends'] = conf.get('friends', [])
        conf['dir'] = data.default_dir
        if not os.path.exists(conf['dir']):
            os.mkdir(conf['dir'])
        conf['email'] = ""
        data.save_conf(conf)
    if flask.request.method == 'GET':
        args = copy.copy(conf)
        args['msg'] = flask.request.args.get('msg', None)
        return templ8("ui.html", args)
    elif flask.request.method == 'POST':
        conf['dir'] = flask.request.form.get('dir')
        conf['email'] = flask.request.form.get('email')
        sync.postjson('/set_email', {
            "user": conf['user'],
            "secret": conf['secret'],
            "email": conf['email']
        })
        data.save_conf(conf)
        return flask.redirect('/ui?msg=Saved')
        return "Saved!"
Пример #3
0
def settings():
    conf = data.get_conf()
    if 'user' not in conf:
        info = requests.post(sync.root+"/sign_up").json()
        conf['user'] = info['user']
        conf['secret'] = info['secret']
        data.save_conf(conf)
    if flask.request.method=='GET':
        return templ8("settings.html", conf)
    elif flask.request.method=='POST':
        friends = flask.request.form.get('friends').split('\n')
        friends = [f for f in friends if len(f)>0]
        conf['friends'] = friends
        dir = flask.request.form.get('dir')
        conf['dir'] = dir
        data.save_conf(conf)
        return "Saved!"
Пример #4
0
def stats():
    conf = data.get_conf()
    if "user" not in conf or "dir" not in conf:
        return ""

    info = {}

    info["exportees"] = requests.post(sync.root + "/export_breakdown/" + conf["user"]).json()["export_capacities"]

    info["exporters"] = [
        {"name": get_friend_name(id), "capacity": capacity_for_friend(id)} for id in conf["friends"] if len(id) > 0
    ]

    progress = requests.get(sync.root + "/backup_progress/" + conf["user"]).json()

    info["backup_progress"] = progress["backup_progress"]

    data_size = size_for_dir(conf["dir"])
    remaining_to_restore = progress["capacity_left_to_restore"]
    info["restore_progress"] = (
        1 - remaining_to_restore * 1.0 / (data_size + remaining_to_restore) if (data_size + remaining_to_restore) else 0
    )

    return templ8("stats.html", info)
Пример #5
0
def hello():
    return templ8("hello.html", {"name": "world"})
Пример #6
0
def hello():
    return templ8("hello.html", {"name": "world"})