-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
55 lines (40 loc) · 1.55 KB
/
upload.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
#!/usr/bin/env python3
import os
import requests
import shutil
import subprocess
import sys
BASE_PATH = 'pros-docs/v5/_static/branchline'
DOCS_REPO_URL = 'https://github.com/purduesigbots/pros-docs.git'
def upload(name: str, version: str, new_template: int, token: str):
"""
Uploads a template and updated registry files to docs.
This will upload the contents to https://pros.cs.purdue.edu/
TODO: error handling
"""
# update registry files
shutil.copyfile('pros-branchline/pros-branchline.json', f'{BASE_PATH}/pros-branchline.json')
shutil.copyfile(f'pros-branchline/templates/{name}.json', f'{BASE_PATH}/templates/{name}.json')
# move zip
if new_template == 1:
os.mkdir(f'{BASE_PATH}/{name}')
shutil.copyfile(f'{name}@{version}.zip', f'{BASE_PATH}/{name}/{name}@{version}.zip')
print('Finished upload')
# push changes
# TODO: make a PR or push to main?
subprocess.run('git -C pros-docs add .', shell=True)
subprocess.run(f'git -C pros-docs commit -m \"[BRANCHLINE] Update {name}\"', shell=True)
subprocess.run(f'git -C pros-docs push https://{token}@github.com/purduesigbots/pros-docs', shell=True)
def main():
# Check if the correct number of arguments is provided
if len(sys.argv) <= 3:
print("error: msising arguments")
sys.exit(1)
# Retrieve command-line arguments
name = sys.argv[1]
version = sys.argv[2]
new_template = sys.argv[3]
token = sys.argv[4]
upload(name, version, int(new_template), token)
if __name__ == "__main__":
main()