-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathupdate.py
214 lines (185 loc) · 5.66 KB
/
update.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import os
import textwrap
import argparse
import warnings
from utils.convert import (
get_cas_from_csv,
get_cas_from_json,
get_cas_from_files,
save_cas_to_readme,
save_cas_to_csv,
save_cas_to_json,
save_cas_to_files,
)
from utils.misc import CSV_FLAG
from utils.collective_action import CollectiveActions
def save_cas_to_all(cas: CollectiveActions):
""" update cas to json, csv, readme, and actions folder. """
save_cas_to_csv(cas)
save_cas_to_json(cas)
save_cas_to_readme(cas)
cas.to_files()
def _get_parser():
parser = argparse.ArgumentParser(
description=textwrap.dedent(
"""
This script is used to:
- clean up files under /actions
- export the actions to a csv
- export the actions to a json
- export the actions to the readme
"""
),
epilog=textwrap.dedent(
"""
# Automatically detect if csv or files are most up-to-date and update
# accordingly
$ python update.py --auto
# Update files in action folder
$ python update.py --files-cleanup
# Update actions.csv based on files
$ python update.py --files-to-csv
# Update README.md based on files
$ python update.py --files-to-readme
# Update actions.json based on files
$ python update.py --files-to-json
...
"""
),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--auto",
action="store_true",
help="automatically detect if csv of files are most up-to-date and update accordingly.",
)
# files > Any
parser.add_argument(
"--files-cleanup",
action="store_true",
help="Update FOLDER by cleaning it up and sorting it.",
)
parser.add_argument(
"--files-to-csv",
action="store_true",
help="Update CSV from action FOLDER.",
)
parser.add_argument(
"--files-to-json",
action="store_true",
help="Update JSON from action FOLDER.",
)
parser.add_argument(
"--files-to-readme",
action="store_true",
help="Update README.md from action FOLDER.",
)
# csv > Any
parser.add_argument(
"--csv-cleanup",
action="store_true",
help="Update CSV by cleaning it up and sorting it.",
)
parser.add_argument(
"--csv-to-files",
action="store_true",
help="Update FOLDER from CSV file.",
)
parser.add_argument(
"--csv-to-readme",
action="store_true",
help="Update README.md from CSV file.",
)
parser.add_argument(
"--csv-to-json", action="store_true", help="Update JSON from CSV file."
)
# json > Any
parser.add_argument(
"--json-cleanup",
action="store_true",
help="Update JSON by cleaning it up and sorting it.",
)
parser.add_argument(
"--json-to-files",
action="store_true",
help="Update FOLDER from JSON file.",
)
parser.add_argument(
"--json-to-readme",
action="store_true",
help="Update README.md from JSON file.",
)
parser.add_argument(
"--json-to-csv", action="store_true", help="Update CSV from JSON file."
)
args = parser.parse_args()
return args
if __name__ == "__main__":
warnings.filterwarnings("ignore", category=UserWarning, module="bs4")
args = _get_parser()
# auto
if args.auto:
print("Update repo automatically.")
if CSV_FLAG.exists():
print(
"CSV_FLAG is present; updating files, json and readme accordingly."
)
cas = get_cas_from_csv()
os.remove(CSV_FLAG)
else:
print(
"CSV_FLAG is not present; updating csv, json and readme using the action folder."
)
cas = get_cas_from_files()
save_cas_to_all(cas)
# files > Any
if args.files_cleanup:
print("Cleaning up actions folder...")
cas = get_cas_from_files()
save_cas_to_files(cas)
if args.files_to_csv:
print("Using files to update the CSV...")
cas = get_cas_from_files()
save_cas_to_csv(cas)
if args.files_to_json:
print("Using files to update the JSON...")
cas = get_cas_from_files()
save_cas_to_json(cas)
if args.files_to_readme:
print("Using files to update the README...")
cas = get_cas_from_files()
save_cas_to_readme(cas)
# csv > Any
if args.csv_cleanup:
print("Cleaning up the CSV file...")
cas = get_cas_from_csv()
save_cas_to_csv(cas)
if args.csv_to_files:
print("Using CSV to update the action folder...")
cas = get_cas_from_csv()
save_cas_to_files(cas)
if args.csv_to_readme:
print("Using CSV to update the README...")
cas = get_cas_from_csv()
save_cas_to_readme(cas)
if args.csv_to_json:
print("Using CSV to update JSON...")
cas = get_cas_from_csv()
save_cas_to_json(cas)
# json > Any
if args.json_cleanup:
print("Cleaning up the JSON file...")
cas = get_cas_from_json()
save_cas_to_json(cas)
if args.json_to_files:
print("Using JSON to update the action folder...")
cas = get_cas_from_json()
save_cas_to_files(cas)
if args.json_to_readme:
print("Using JSON to update README...")
cas = get_cas_from_json()
save_cas_to_readme(cas)
if args.json_to_csv:
print("Using JSON to update CSV...")
cas = get_cas_from_json()
save_cas_to_csv(cas)