/
upload-index-json.py
executable file
·66 lines (50 loc) · 1.49 KB
/
upload-index-json.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
#!/usr/bin/env python
from __future__ import print_function
import json
import os
import sys
import urllib2
sys.path.append(
os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../.."))
from lib.util import store_artifact, scoped_cwd, safe_mkdir, get_out_dir, \
ELECTRON_DIR
OUT_DIR = get_out_dir()
BASE_URL = 'https://electron-metadumper.herokuapp.com/?version='
version = sys.argv[1]
authToken = os.getenv('META_DUMPER_AUTH_HEADER')
def is_json(myjson):
try:
json.loads(myjson)
except ValueError:
return False
return True
def get_content(retry_count = 5):
try:
request = urllib2.Request(
BASE_URL + version,
headers={"Authorization" : authToken}
)
proposed_content = urllib2.urlopen(
request
).read()
if is_json(proposed_content):
return proposed_content
print("bad attempt")
raise Exception("Failed to fetch valid JSON from the metadumper service")
except Exception as e:
if retry_count == 0:
raise e
return get_content(retry_count - 1)
def main():
if not authToken or authToken == "":
raise Exception("Please set META_DUMPER_AUTH_HEADER")
# Upload the index.json.
with scoped_cwd(ELECTRON_DIR):
safe_mkdir(OUT_DIR)
index_json = os.path.relpath(os.path.join(OUT_DIR, 'index.json'))
new_content = get_content()
with open(index_json, "wb") as f:
f.write(new_content)
store_artifact(OUT_DIR, 'headers/dist/', [index_json])
if __name__ == '__main__':
sys.exit(main())