[Download Datasheet] Better message warnings

- Unified
This commit is contained in:
Salvador E. Tropea 2023-03-27 08:51:55 -03:00
parent f7d52f3d09
commit 762d96d0e8
2 changed files with 15 additions and 13 deletions

View File

@ -12,13 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `default_resistor_tolerance` which tolerance to use when none found.
- `cache_3d_resistors` to avoid generating them all the time.
- 3D: colored 3D models for THT resistors
- Datasheet download:
- Avoid interruptions when too many redirections is detected (#408)
- Datasheet download: now the warnings mention which reference failed.
### Fixed
- Makefile: don't skip all preflights on each run, just the ones we generate
as targets. (#405)
- KiKit present: problems when no board was specified. (#402)
- Datasheet download:
- Avoid interruptions when too many redirections is detected (#408)
## [1.6.1] - 2023-03-16

View File

@ -50,6 +50,10 @@ class Download_Datasheets_Options(VariantOptions):
raise KiPlotConfigurationError("Empty `output` ({})".format(str(self._tree)))
self.field = self.field.lower()
def do_warning(self, msg, ds, c):
logger.warning(W_FAILDL+'{} during download of `{}` [{}]'.format(msg, ds, c.ref))
return None
def download(self, c, ds, dir, name, known):
dest = os.path.join(dir, name)
logger.debug('To download: {} -> {}'.format(ds, dest))
@ -67,20 +71,17 @@ class Download_Datasheets_Options(VariantOptions):
try:
r = requests.get(ds, allow_redirects=True, headers={'User-Agent': USER_AGENT}, timeout=20)
except requests.exceptions.ReadTimeout:
logger.warning(W_FAILDL+'Timeout during download `{}`'.format(ds))
return None
except requests.exceptions.ConnectionError:
logger.warning(W_FAILDL+'Connection error during download `{}`'.format(ds))
return None
return self.do_warning('Timeout', ds, c)
except requests.exceptions.SSLError:
logger.warning(W_FAILDL+'SSL Error during download `{}`'.format(ds))
return None
return self.do_warning('SSL Error', ds, c)
except requests.exceptions.TooManyRedirects:
logger.warning(W_FAILDL+'More than 30 redirections downloading `{}`'.format(ds))
return None
return self.do_warning('More than 30 redirections', ds, c)
except requests.exceptions.ConnectionError:
return self.do_warning('Connection', ds, c)
except requests.exceptions.RequestException as e:
return self.do_warning(str(e), ds, c)
if r.status_code != 200:
logger.warning(W_FAILDL+'Failed to download `{}`'.format(ds))
return None
return self.do_warning('Failed with status '+str(r.status_code), ds, c)
with open(dest, 'wb') as f:
f.write(r.content)
self._downloaded.add(name)