-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
101 lines (79 loc) · 2.9 KB
/
script.py
File metadata and controls
101 lines (79 loc) · 2.9 KB
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
""" Main script to push to maven.mozilla.org"""
import argparse
import asyncio
import aiohttp
from context import Context
from utils import (
load_json_or_yaml, setup_mimetypes, _handle_asyncio_loop,
upload_to_s3, raise_future_exceptions
)
from zip import (
download_zip_archive,
check_extract_and_delete_zip_archive,
)
GLEAN_PACKAGES = [
'glean',
'glean-forUnitTests',
'glean-gradle-plugin'
]
async def move_beets(context):
"""TODO"""
uploads = []
for file, local_path in context.extracted_files.items():
for package_name in GLEAN_PACKAGES:
if file.startswith(f"{package_name}-{context.version}"):
destination = f"maven2/org/mozilla/telemetry/{package_name}/{context.version}/{file}"
break
else:
continue
uploads.append(
asyncio.ensure_future(
upload_to_s3(context=context, s3_key=destination, path=local_path)
)
)
await raise_future_exceptions(uploads)
async def async_main(context):
"""TODO"""
# download the release archive from Github
download_zip_archive(context.release_url, context.zip_path)
# explode zip archive
context.extracted_files = check_extract_and_delete_zip_archive(context.zip_path)
connector = aiohttp.TCPConnector(limit=10)
async with aiohttp.ClientSession(connector=connector) as session:
context.session = session
await move_beets(context)
def sync_main(async_main, release_url, zip_path, script_config,
bucket, version, dry_run):
"""TODO"""
context = Context()
context.release_url = release_url
context.zip_path = zip_path
context.bucket = bucket
context.version = version
context.dry_run = dry_run
context.config = {}
context.config.update(load_json_or_yaml(script_config, is_path=True))
setup_mimetypes()
loop = asyncio.get_event_loop()
loop.run_until_complete(_handle_asyncio_loop(async_main, context))
def main():
"""TODO"""
parser = argparse.ArgumentParser(description='Telemetry upload')
parser.add_argument('--release-url', dest='release_url',
action='store', required=True)
parser.add_argument('--script-config', dest='script_config',
action='store', required=True)
parser.add_argument('--bucket', dest='bucket',
action='store', required=True)
parser.add_argument('--version', dest='version',
action='store', required=True)
parser.add_argument('--dry-run', default=False,
action='store_true')
args = parser.parse_args()
if not args.release_url:
sys.exit(1)
zip_path = '/tmp/target.zip'
sync_main(async_main, args.release_url, zip_path,
args.script_config, args.bucket, args.version,
args.dry_run)
__name__ == '__main__' and main()