|
6 | 6 | import datetime
|
7 | 7 | import glob
|
8 | 8 | import imp
|
| 9 | +import json |
9 | 10 | import os
|
10 | 11 | import re
|
11 | 12 | import shlex
|
|
15 | 16 | import subprocess
|
16 | 17 | import sys
|
17 | 18 | import time
|
| 19 | +import urllib |
| 20 | +import urllib.request |
18 | 21 |
|
19 | 22 | this = sys.modules[__name__]
|
20 |
| - |
21 |
| -# Default paths. |
22 | 23 | root_dir = os.path.dirname(os.path.abspath(__file__))
|
23 | 24 | data_dir = os.path.join(root_dir, 'data')
|
24 | 25 | p9_dir = os.path.join(data_dir, '9p')
|
|
34 | 35 | qemu_src_dir = os.path.join(submodules_dir, 'qemu')
|
35 | 36 | parsec_benchmark_src_dir = os.path.join(submodules_dir, 'parsec-benchmark')
|
36 | 37 | ccache_dir = os.path.join('/usr', 'lib', 'ccache')
|
37 |
| - |
38 |
| -# Other default variables. |
| 38 | +github_token_file = os.path.join(data_dir, 'github-token') |
39 | 39 | arch_map = {
|
40 | 40 | 'a': 'arm',
|
41 | 41 | 'A': 'aarch64',
|
|
44 | 44 | arches = [arch_map[k] for k in arch_map]
|
45 | 45 | gem5_cpt_prefix = '^cpt\.'
|
46 | 46 | sha = subprocess.check_output(['git', '-C', root_dir, 'log', '-1', '--format=%H']).decode().rstrip()
|
| 47 | +release_dir = os.path.join(this.out_dir, 'release') |
| 48 | +release_zip_file = os.path.join(this.release_dir, 'lkmc-{}.zip'.format(this.sha)) |
| 49 | +github_repo_id = 'cirosantilli/linux-kernel-module-cheat' |
47 | 50 | config_file = os.path.join(data_dir, 'config')
|
48 | 51 | if os.path.exists(config_file):
|
49 | 52 | config = imp.load_source('config', config_file)
|
@@ -189,6 +192,39 @@ def get_toolchain_tool(tool):
|
189 | 192 | global this
|
190 | 193 | return glob.glob(os.path.join(this.host_bin_dir, '*-buildroot-*-{}'.format(tool)))[0]
|
191 | 194 |
|
| 195 | +def github_make_request( |
| 196 | + authenticate=False, |
| 197 | + data=None, |
| 198 | + extra_headers=None, |
| 199 | + path='', |
| 200 | + subdomain='api', |
| 201 | + url_params=None, |
| 202 | + **extra_request_args |
| 203 | + ): |
| 204 | + global this |
| 205 | + if extra_headers is None: |
| 206 | + extra_headers = {} |
| 207 | + headers = {'Accept': 'application/vnd.github.v3+json'} |
| 208 | + headers.update(extra_headers) |
| 209 | + if authenticate: |
| 210 | + with open(this.github_token_file, 'r') as f: |
| 211 | + token = f.read().rstrip() |
| 212 | + headers['Authorization'] = 'token ' + token |
| 213 | + if url_params is not None: |
| 214 | + path += '?' + urllib.parse.urlencode(url_params) |
| 215 | + request = urllib.request.Request( |
| 216 | + 'https://' + subdomain + '.github.com/repos/' + github_repo_id + path, |
| 217 | + headers=headers, |
| 218 | + data=data, |
| 219 | + **extra_request_args |
| 220 | + ) |
| 221 | + response_body = urllib.request.urlopen(request).read().decode() |
| 222 | + if response_body: |
| 223 | + _json = json.loads(response_body) |
| 224 | + else: |
| 225 | + _json = {} |
| 226 | + return _json |
| 227 | + |
192 | 228 | def log_error(msg):
|
193 | 229 | print('error: {}'.format(msg), file=sys.stderr)
|
194 | 230 |
|
@@ -340,7 +376,7 @@ def run_cmd(
|
340 | 376 | #signal.signal(signal.SIGPIPE, sigpipe_old)
|
341 | 377 | return proc.returncode
|
342 | 378 |
|
343 |
| -def setup(parser, **extra_args): |
| 379 | +def setup(parser): |
344 | 380 | '''
|
345 | 381 | Parse the command line arguments, and setup several variables based on them.
|
346 | 382 | Typically done after getting inputs from the command line arguments.
|
|
0 commit comments