-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-bin.py
executable file
·51 lines (40 loc) · 1.52 KB
/
upload-bin.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
#!/usr/bin/env python3
# upload file path specified via command line
# example: upload-bin.py --file /home/user/file.txt
# then, ask the user for the server password and send file to https://lamp.bobbycar.cloud/upload-firmware
import argparse
import requests
import sys
import os
from getpass import getpass
def upload_file(file_path, password):
"""
Uploads a file to the server.
:param file_path: path to the file to upload
:return:
"""
if not os.path.isfile(file_path):
file_path = os.path.join(os.getcwd(), '.pio/build/esp8266dev/firmware.bin')
print('Uploading file: {}'.format(file_path))
# get git commit hash
commit_hash = os.popen('git rev-parse HEAD').read().strip()
print(commit_hash)
# get the server password
if not password or password == "":
password = getpass('Server password: ')
url = "https://lamps.bobbycar.cloud/upload-firmware"
files = {'firmware': open(file_path, 'rb')}
r = requests.post(url, files=files, headers={'Authorization': password, 'X-Git-Commit-Hash': commit_hash})
print(r.text)
def main():
parser = argparse.ArgumentParser(description='Uploads a file to the server.')
parser.add_argument('--file', type=str, help='path to the file to upload')
parser.add_argument('--password', type=str, help='server password')
args = parser.parse_args()
upload_file(args.file or "", args.password or "")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print()
sys.exit(0)