コード例 #1
0
ファイル: test_tools.py プロジェクト: abondis/simple-share
def test_create_random_folder(aaa):
    """Get a sharing UID that doesn't already exist"""
    prep_folder(True)
    aaa.current_user.username = "******"
    t.root_dir = "/tmp/test"
    t.random_generator = Mock(side_effect=["XYZ22", "ABC123"])
    x, y = t.create_random_folder()
    assert t.random_generator.call_count == 2
    assert x == "ABC123"
コード例 #2
0
ファイル: __init__.py プロジェクト: abondis/simple-share
def share(path="."):
    """Share a file or a folder"""
    reuse = post_get('reuse') or None
    # print(reuse)
    public = post_get('public')
    users = post_get('users')
    # .../user/config
    path_config = permitted_config_path()
    # .../user/shares
    uidshares_config = permitted_shares_path()
    # /.../user/files/....
    real_path = protect_path(path)
    try:
        # /.../user/files
        # get relative path, to use in configuration path
        rel_shared_path = relpath(real_path, permitted_files_path())
    except IOError:
        abort(403, PATH_ERROR)
    if reuse is not None:
        try:
            shared_path = get_config(reuse, 'path', 'shares')
        except IOError:
            abort(400, "This sharing ID is invalid")
        if shared_path != rel_shared_path:
            abort(400, "This sharing ID is invalid")
    else:
        uid, uid_path = create_random_folder()
    # create .../user/config/rel/path/UID
    print('uid {} Uid_path {}'.format(reuse or uid, uid_path))
    print('*' * 80)
    print((uidshares_config, rel_shared_path, reuse or uid, rel_shared_path))
    print('*' * 80)
    configure(
        path_config,
        rel_shared_path,
        reuse or uid,
        rel_shared_path)
    # configure .../user/shares/UID/
    configure(uidshares_config, uid_path, 'path', real_path)
    configure(uidshares_config, uid_path, 'public', public)
    configure(uidshares_config, uid_path, 'users', users)
    return relist_parent_folder(real_path)