-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathglobus.py
More file actions
54 lines (43 loc) · 1.89 KB
/
globus.py
File metadata and controls
54 lines (43 loc) · 1.89 KB
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
import globus_sdk
from globus_sdk.scopes import TransferScopes
import os
#PeaTMOSS Access Token
CLIENT_ID = "2e3fa2a3-c37c-46f8-a3a6-c59d145503bd"
auth_client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
# requested_scopes specifies a list of scopes to request
# instead of the defaults, only request access to the Transfer API
auth_client.oauth2_start_flow(requested_scopes=TransferScopes.all)
authorize_url = auth_client.oauth2_get_authorize_url()
print(f"Please go to this URL and login:\n\n{authorize_url}\n")
auth_code = input("Please enter the code here: ").strip()
tokens = auth_client.oauth2_exchange_code_for_tokens(auth_code)
transfer_tokens = tokens.by_resource_server["transfer.api.globus.org"]
# construct an AccessTokenAuthorizer and use it to construct the
# TransferClient
transfer_client = globus_sdk.TransferClient(
authorizer=globus_sdk.AccessTokenAuthorizer(transfer_tokens["access_token"])
)
PeaTMOSS_endpoint_id = "c4ec6812-3315-11ee-b543-e72de9e39f95"
local_endpoint = globus_sdk.LocalGlobusConnectPersonal()
### Instead of using local_endpoint.endpoint_id, you may need to copy paste your collection's UUID if local_endpoint.endpoint_id returns None
local_endpoint_id = local_endpoint.endpoint_id
print(local_endpoint_id)
source_endpoint_id = PeaTMOSS_endpoint_id
dest_endpoint_id = local_endpoint_id
# create a Transfer task consisting of one or more items
task_data = globus_sdk.TransferData(
source_endpoint=source_endpoint_id,
destination_endpoint=dest_endpoint_id
)
curr_path = os.getcwd()
print(curr_path)
### Including ./ at the beginning of the filepath indicates it is in the root
print("./PeaTMOSS_DB/")
task_data.add_item(
"/~/Database/PeaTMOSS.db", # source
f"./PeaTMOSS_DB/PeaTMOSS.db", # dest
)
# submit, getting back the task ID
task_doc = transfer_client.submit_transfer(task_data)
task_id = task_doc["task_id"]
print(f"submitted transfer, task_id={task_id}")