File size: 2,836 Bytes
0b85c0f
 
 
 
 
 
7873ee1
0b85c0f
 
7873ee1
 
0b85c0f
7873ee1
0b85c0f
 
7873ee1
0b85c0f
7873ee1
 
 
 
0b85c0f
7873ee1
0b85c0f
7873ee1
0b85c0f
 
 
7873ee1
0b85c0f
 
 
7873ee1
0b85c0f
 
 
7873ee1
0b85c0f
 
7873ee1
0b85c0f
7873ee1
0b85c0f
 
7873ee1
0b85c0f
 
7873ee1
0b85c0f
 
 
 
 
7873ee1
0b85c0f
 
7873ee1
0b85c0f
 
 
 
 
 
 
 
7873ee1
0b85c0f
7873ee1
0b85c0f
 
7873ee1
0b85c0f
7873ee1
 
0b85c0f
 
 
 
 
7873ee1
0b85c0f
7873ee1
0b85c0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import subprocess
from pathlib import Path
from dotenv import load_dotenv
import requests

########## Configs ##########
load_dotenv(dotenv_path=Path(__file__).resolve().parent.parent / ".env")
DAGSHUB_TOKEN = os.getenv("DAGSHUB_TOKEN")
USERNAME = os.getenv("USERNAME")
REPO = os.getenv("REPO")
REPO_PATH = f"{USERNAME}/{REPO}"
##############################

if not DAGSHUB_TOKEN:
    raise ValueError("❌ DAGSHUB_TOKEN not found in .env")

def testar_conexao_dagshub(token):
    print("πŸ” Testing DagsHub authentication...")
    url = f"https://dagshub.com/api/v1/repos/{USERNAME}/{REPO}"
    response = requests.get(url, auth=(USERNAME, token))
    if response.status_code == 200:
        print("βœ… DagsHub connection OK")
        return True
    print(f"❌ Authentication failed ({response.status_code}): {response.text}")
    return False

def install_dagshub_client():
    print("πŸ”§ Checking DagsHub client...")
    try:
        subprocess.run(["dagshub", "--help"], capture_output=True, text=True, check=True)
    except (FileNotFoundError, subprocess.CalledProcessError):
        print("πŸ“¦ Installing DagsHub client...")
        subprocess.run(["pip", "install", "dagshub", "--upgrade"], check=True)

def login_dagshub():
    print("πŸ” Performing automatic login to DagsHub via token...")
    try:
        subprocess.run(["dagshub", "login", "--token", DAGSHUB_TOKEN], check=True)
        print("βœ… Login successful")
    except subprocess.CalledProcessError as e:
        print(f"⚠️  Warning during login: {e.stderr}")

def upload_datasets():
    print("πŸ“€ Uploading datasets to DagsHub bucket...")

    datasets_to_upload = [
        "datasets/FASDD"
    ]
    
    for dataset_path in datasets_to_upload:
        path_obj = Path(dataset_path)
        if not path_obj.exists():
            print(f"⚠️  Dataset not found: {dataset_path}, skipping...")
            continue

        print(f"πŸ“ Uploading: {dataset_path}")
        try:
            subprocess.run([
                "dagshub", "upload",
                REPO_PATH,
                dataset_path,
                f"data/{path_obj.name}/",
                "--bucket", "--update", "-v"
            ], check=True)
            print(f"βœ… Upload completed: {dataset_path}")
        except subprocess.CalledProcessError as e:
            print(f"❌ Upload error for {dataset_path}: {e.stderr}")

if __name__ == "__main__":
    print("πŸš€ Starting upload to DagsHub bucket...")

    if not testar_conexao_dagshub(DAGSHUB_TOKEN):
        raise SystemExit("β›” Invalid token or repository inaccessible.")

    try:
        install_dagshub_client()
        login_dagshub()
        upload_datasets()
        print("βœ… Upload completed successfully!")
    except Exception as e:
        print(f"❌ Error during process: {e}")
        raise