diff options
author | wbond <will@wbond.net> | 2019-07-04 06:32:22 -0400 |
---|---|---|
committer | wbond <will@wbond.net> | 2019-07-04 06:32:22 -0400 |
commit | 93193b8df443f3a1a3c6693d537e5fecfc610e12 (patch) | |
tree | 435f446e50ebc0614a8627d4754b675834d785aa /dev | |
parent | ecda20176f55d37021cbca1f6da9083a8e491197 (diff) | |
download | asn1crypto-93193b8df443f3a1a3c6693d537e5fecfc610e12.tar.gz |
CI reliability improvements related to codecov.io
Diffstat (limited to 'dev')
-rw-r--r-- | dev/coverage.py | 17 | ||||
-rw-r--r-- | dev/deps.py | 17 |
2 files changed, 26 insertions, 8 deletions
diff --git a/dev/coverage.py b/dev/coverage.py index f5fd6b2..fe56540 100644 --- a/dev/coverage.py +++ b/dev/coverage.py @@ -500,7 +500,11 @@ def _do_request(method, url, headers, data=None, query_params=None, timeout=20): # To properly obtain bytes, we use BitConverter to get hex dash # encoding (e.g. AE-09-3F) and they decode in python code += " + [System.BitConverter]::ToString($out);" - stdout, stderr = _execute([powershell_exe, '-Command', code], os.getcwd()) + stdout, stderr = _execute( + [powershell_exe, '-Command', code], + os.getcwd(), + 'Unable to connect to' + ) if stdout[-2:] == b'\r\n' and b'\r\n\r\n' in stdout: # An extra trailing crlf is added at the end by powershell stdout = stdout[0:-2] @@ -526,7 +530,7 @@ def _do_request(method, url, headers, data=None, query_params=None, timeout=20): args.append('--data-binary') args.append('@%s' % tempf_path) args.append(url) - stdout, stderr = _execute(args, os.getcwd()) + stdout, stderr = _execute(args, os.getcwd(), 'Failed to connect to') finally: if tempf_path and os.path.exists(tempf_path): os.remove(tempf_path) @@ -566,7 +570,7 @@ def _do_request(method, url, headers, data=None, query_params=None, timeout=20): return (content_type, encoding, body) -def _execute(params, cwd): +def _execute(params, cwd, retry=None): """ Executes a subprocess @@ -576,6 +580,9 @@ def _execute(params, cwd): :param cwd: The working directory to execute the command in + :param retry: + If this string is present in stderr, retry the operation + :return: A 2-element tuple of (stdout, stderr) """ @@ -589,7 +596,9 @@ def _execute(params, cwd): stdout, stderr = proc.communicate() code = proc.wait() if code != 0: - e = OSError('subprocess exit code for %r was %d: %s' % (params, code, stderr)) + if retry and retry in stderr.decode('utf-8'): + return _execute(params, cwd) + e = OSError('subprocess exit code for "%s" was %d: %s' % (' '.join(params), code, stderr)) e.stdout = stdout e.stderr = stderr raise e diff --git a/dev/deps.py b/dev/deps.py index 33c712d..d995c55 100644 --- a/dev/deps.py +++ b/dev/deps.py @@ -75,10 +75,14 @@ def _download(url, dest): powershell_exe = os.path.join('system32\\WindowsPowerShell\\v1.0\\powershell.exe') code = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;" code += "(New-Object Net.WebClient).DownloadFile('%s', '%s');" % (url, dest_path) - _execute([powershell_exe, '-Command', code], dest) + _execute([powershell_exe, '-Command', code], dest, 'Unable to connect to') else: - _execute(['curl', '-L', '--silent', '--show-error', '-O', url], dest) + _execute( + ['curl', '-L', '--silent', '--show-error', '-O', url], + dest, + 'Failed to connect to' + ) return dest_path @@ -456,7 +460,7 @@ def _parse_requires(path): return packages -def _execute(params, cwd): +def _execute(params, cwd, retry=None): """ Executes a subprocess @@ -466,6 +470,9 @@ def _execute(params, cwd): :param cwd: The working directory to execute the command in + :param retry: + If this string is present in stderr, retry the operation + :return: A 2-element tuple of (stdout, stderr) """ @@ -479,7 +486,9 @@ def _execute(params, cwd): stdout, stderr = proc.communicate() code = proc.wait() if code != 0: - e = OSError('subprocess exit code for %r was %d: %s' % (params, code, stderr)) + if retry and retry in stderr.decode('utf-8'): + return _execute(params, cwd) + e = OSError('subprocess exit code for "%s" was %d: %s' % (' '.join(params), code, stderr)) e.stdout = stdout e.stderr = stderr raise e |