示例#1
0
文件: views.py 项目: Auto-DL/Auto-DL
def get_all_projects(request):
    try:
        username = request.data.get("username")
        user = User(username=username, password=None)
        user = user.find()
        store_obj = Store(user)

        delete_broken_symlinks(store_obj.path)
        project_ids = store_obj.enlist()

        projects = []
        for id in project_ids:
            path = store_obj.path + os.sep + id + os.sep + "meta.json"
            with open(path, "r") as f:
                metadata = json.load(f)
            list_item = {id: metadata}
            projects.append(list_item)
        status, success, message = 200, True, "Projects Fetched"
    except Exception as e:
        status, success, message, projects = (
            500,
            False,
            "Projects could not be fetched",
            [],
        )
    return JsonResponse(
        {"success": success, "message": message, "projects": projects}, status=status
    )
示例#2
0
def test_enlist():
    user = MockUser().mock_user()
    store = Store(user)
    store.rootpath = os.path.expanduser(tempdir + "/.autodl/")
    store.path = posixpath.join(store.rootpath, store.user.get("username"))

    project_path_1 = store.create(project="test_project_dir_0")
    project_path_2 = store.create(project="test_project_dir_1")
    project_path_3 = store.create(project="test_project_dir_2")

    test_projects = store.enlist()
    if (
        "test_project_dir_0" in test_projects
        and "test_project_dir_1" in test_projects
        and "test_project_dir_2" in test_projects
    ):
        assert True