Skip to content

Commit

Permalink
Address flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ninamiolane committed Apr 28, 2022
1 parent 72048df commit 98e3536
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions ioSPI/datasets.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"""Module to house methods related to datasets (micrographs, meta-data, etc.)."""

import os

import typing
from pathlib import Path

import requests


class Project:
"""Class to list and download dataset from a project on OSF.io
"""Class to list, download and upload data from OSF.
Parameters
----------
username : str
Expand All @@ -22,55 +21,60 @@ class Project:
project_id : str, default = "7g42j"
Identifier of the project, found on the OSF project page.
E.g. 7g42j for project at https://osf.io/7g42j/
See Also
--------
OSF API documentation : https://developer.osf.io/
"""

def __init__(self, username: str, token: str, project_id: str = "7g42j") -> None:
self.project_id = project_id

config_path = os.path.join(".osfcli.config")
with open(config_path, 'w') as out_file:
with open(config_path, "w") as out_file:
out_file.write("[osf]\n")
out_file.write(f"username = {username}\n")
out_file.write(f"project = {project_id}\n")
out_file.write(f"token = {token}\n")
print("OSF config written to .osfcli.config!")

def ls(self):
"List all files for the project"
"""List all files in the project."""
print(f"Listing files from OSF project: {self.project_id}...")
os.system("osf ls")

def download(self, remote_path, local_path):
"""Download file from osf and save it locally.
Parameters
----------
remote_path : str
Remote path of the file on OSF.
E.g. osfstorage/randomrot1D_nodisorder/4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
E.g. osfstorage/
randomrot1D_nodisorder/
4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
local_path : str
Local path where the file will be saved.
E.g. 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
"""
print(f"Downloading {remote_path} to {local_path}...")
os.system(f"osf fetch {remote_path} {local_path}")
print("Done!")

def upload(self, remote_path, local_path):
"""Upload file to osf.
Notes
-----
You should have requested permission to upload to the project first.
Parameters
----------
remote_path : str
Remote path of the file on OSF.
E.g. osfstorage/randomrot1D_nodisorder/4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
E.g. osfstorage/
randomrot1D_nodisorder/
4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
local_path : str
Local path where the file will be saved.
E.g. 4v6x_randomrot_copy6_defocus3.0_yes_noise.txt
Expand Down

0 comments on commit 98e3536

Please sign in to comment.