-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_projects.py
120 lines (100 loc) · 3.05 KB
/
create_projects.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import synapseclient
from synapseclient import Project
from synapseclient.core.exceptions import SynapseHTTPError
import yaml
# Login to Synapse
syn = synapseclient.Synapse()
syn.login()
# Define project names
project_names = [
"HTAN2",
"HTAN2_Ovarian",
"HTAN2_Glioma",
"HTAN2_Gastric",
"HTAN2_Skin",
"HTAN2_Pediatric",
"HTAN2_Myeloma",
"HTAN2_Pancreatic",
"HTAN2_Prostate",
"HTAN2_CRC",
"HTAN2_Lymphoma",
]
# Define team IDs
htan_dcc_admins_team_id = "3497313" # HTAN DCC Admins team
htan_dcc_team_id = "3391844" # HTAN DCC team
act_team_id = "464532" # ACT team
# Initialize a dictionary to store project names and Synapse IDs
project_info = {}
# Function to get a project by name
def get_project_by_name(project_name):
try:
project_id = syn.findEntityId(project_name)
if project_id:
return syn.get(project_id)
else:
return None
except SynapseHTTPError:
return None
# Function to create a new project
def create_project(project_name):
project = Project(name=project_name)
return syn.store(project)
# Function to set permissions for a project
def set_project_permissions(project):
# Add HTAN DCC Admins team with admin permissions
syn.setPermissions(
project,
principalId=htan_dcc_admins_team_id,
accessType=[
"READ",
"DOWNLOAD",
"CREATE",
"UPDATE",
"DELETE",
"MODERATE",
"CHANGE_PERMISSIONS",
"CHANGE_SETTINGS",
],
)
# Add HTAN DCC team with edit and delete permissions
syn.setPermissions(
project,
principalId=htan_dcc_team_id,
accessType=["READ", "DOWNLOAD", "CREATE", "UPDATE", "DELETE"],
)
# Add ACT team with administrator permissions
syn.setPermissions(
project,
principalId=act_team_id,
accessType=[
"READ",
"DOWNLOAD",
"CREATE",
"UPDATE",
"DELETE",
"MODERATE",
"CHANGE_PERMISSIONS",
"CHANGE_SETTINGS",
],
)
# Function to save project information to a YAML file
def save_projects_to_yaml(project_info, filename="projects.yml"):
with open(filename, "w") as file:
yaml.dump(project_info, file)
# Main loop to create projects or reset permissions if they already exist
for project_name in project_names:
project = get_project_by_name(project_name)
if project:
print(f"Project '{project_name}' already exists. Resetting permissions.")
else:
# Create the project
project = create_project(project_name)
print(f"Project '{project_name}' created.")
# Set or reset the permissions
set_project_permissions(project)
print(f"Permissions set for project '{project_name}'.")
# Store project name and Synapse ID in the dictionary
project_info[project_name] = project.id
# Save the project info to 'projects.yml'
save_projects_to_yaml(project_info)
print("Project information saved to 'projects.yml'.")