예제 #1
0
파일: upload.py 프로젝트: ezhou7/repm
def upload_dataset(dataset_name: str):
    active_session = get_active_session()
    if not is_active_session_valid(active_session):
        print("You must login before uploading any data.")
        return

    session_cookies: dict = active_session.cookies.get_dict()
    upload_url: str = get_api_url("/dataset")

    project_root_path: str = get_repm_project_root_directory()
    if project_root_path:
        upload_path: str = "{}/data/{}/".format(project_root_path,
                                                dataset_name)
    else:
        raise Exception("Not within a repm project")

    upload_details = {"bucketName": dataset_name}

    for filename in os.listdir(upload_path):
        file_path = os.path.join(upload_path, filename)
        session_files = {
            "file": (filename, open(file_path,
                                    "rb"), "application/octet-stream")
        }
        res = active_session.post(upload_url,
                                  data=upload_details,
                                  files=session_files,
                                  cookies=session_cookies)
        print(res.content.decode("utf-8"))

        if res.status_code != 200:
            break
예제 #2
0
def is_active_session_valid(active_session: Optional[Session]) -> bool:
    if not active_session:
        return False

    session_cookies: dict = active_session.cookies.get_dict()

    is_session_valid_url: str = get_api_url("/auth/isSessionValid")
    is_session_valid_res: Response = active_session.post(is_session_valid_url, cookies=session_cookies)

    return is_session_valid_res.status_code == 200
예제 #3
0
파일: dataset.py 프로젝트: ezhou7/repm
def list_datasets():
    list_datasets_url: str = get_api_url("/datasets/list")
    list_datasets_res = requests.get(list_datasets_url)

    if list_datasets_res.status_code == 200:
        dataset_names = list_datasets_res.json()

        for name in dataset_names:
            print(name)
    else:
        print(list_datasets_res.content.decode("utf-8"))
예제 #4
0
def download_dataset(dataset_name: str):
    download_url: str = get_api_url("/dataset")

    project_root_path: str = get_repm_project_root_directory()
    if project_root_path:
        download_path = "{}/data/{}/".format(project_root_path, dataset_name)
    else:
        raise Exception("Not within a repm project")

    print("Downloading...")
    download_path: str = __download_zip(dataset_name, download_url, download_path)
    print("Finished download: {}".format(download_path))
예제 #5
0
파일: auth.py 프로젝트: ezhou7/repm
def logout():
    active_session = get_active_session()
    if not is_active_session_valid(active_session):
        print("Not logged in.")
        return

    session_cookies: dict = active_session.cookies.get_dict()

    logout_url: str = get_api_url("/auth/logout")
    logout_res: Response = active_session.get(logout_url, cookies=session_cookies)

    if logout_res.status_code == 200:
        set_active_session(None)

    print(logout_res.content.decode("utf-8"))
예제 #6
0
파일: auth.py 프로젝트: ezhou7/repm
def signup():
    active_session = get_active_session()
    if is_active_session_valid(active_session):
        print("Please log out before signing up for a new account.")
        return

    email: str = input("Email: ")
    password: str = getpass.getpass("Password: "******"/auth/signup")
    signup_details = {
        "email": email,
        "password": password
    }
    signup_res: Response = active_session.post(signup_url, data=signup_details)
    print(signup_res.content.decode("utf-8"))
예제 #7
0
파일: auth.py 프로젝트: ezhou7/repm
def login():
    active_session = get_active_session()
    if is_active_session_valid(active_session):
        print("Already logged in.")
        return

    email: str = input("Email: ")
    password: str = getpass.getpass("Password: "******"/auth/login")
    login_details = {
        "email": email,
        "password": password
    }
    login_res: Response = session.post(login_url, data=login_details)

    if login_res.status_code == 200:
        set_active_session(session)

    print(login_res.content.decode("utf-8"))