-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (86 loc) · 2.96 KB
/
main.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
from typing import Optional
from bin.helper import get_logger
from bin.slack import SlackClass
from bin.archive import ArchiveClass
from bin.find import FindClass
from bin.environment import EnvironmentVariableClass
from bin.util import (
read_or_new_pickle,
dx_login,
parse_arguments,
get_members,
parse_datetime,
)
logger = get_logger(__name__)
def main():
args = parse_arguments()
datetime = parse_datetime(args)
logger.info(datetime)
dnanexus_id_to_slack_id = get_members("members.ini")
env = EnvironmentVariableClass()
env.load_configs()
# define Slack class
slack = SlackClass(env, datetime)
# define Archive class
archive = ArchiveClass(env)
# define Find class
find = FindClass(env, dnanexus_id_to_slack_id)
# dnanexus login
if not dx_login(env.DNANEXUS_TOKEN):
slack.post_simple_message_to_slack(
"#egg-alerts", "automated-archiving: dnanexus login failed."
)
raise Exception("dnanexus login failed.")
archive_pickle = read_or_new_pickle(env.AUTOMATED_ARCHIVE_PICKLE_PATH)
projects_marked_for_archiving: Optional[list] = archive_pickle.get(
"projects", []
)
staging52_directories: Optional[list] = archive_pickle.get(
"directories", []
)
precision_projects: Optional[list] = archive_pickle.get("precisions", [])
tars = find.get_tar()
slack.notify({"tars": tars})
if datetime.day in [1, 15]:
archived_project_ids = archive.archive_projects(
projects_marked_for_archiving
)
archived_directories_dict = archive.archive_staging52(
staging52_directories
)
archived_precisions = archive.archive_precisions(precision_projects)
slack.post_long_message_to_slack(
"#egg-alerts" "archived", list(archived_project_ids)
)
slack.post_long_message_to_slack(
"#egg-alerts" "archived",
[
f"{archived_count} files archived in {folder_path} in `staging52`."
for folder_path, archived_count in archived_directories_dict.items()
],
)
slack.post_long_message_to_slack(
"#egg-alerts" "archived",
[
f"{project_id}:{','.join(folder_path)} archived in `precision`."
for project_id, folder_path in archived_precisions.items()
],
)
find.find_projects()
find.find_directories()
find.find_precisions()
find.save_to_pickle()
slack.post_simple_message_to_slack(
"#egg-alerts",
f"automated-archiving guideline: {env.GUIDELINE_URL}",
)
slack.notify(
{
"projects2": find.archiving_projects_2_slack,
"projects3": find.archiving_projects_3_slack,
"directories": find.archiving_directories_slack,
"precisions": find.archiving_precision_directories_slack,
}
)
if __name__ == "__main__":
main()