Download sources
(self)
| 266 | return out.strip().decode("utf-8") |
| 267 | |
| 268 | def _download_src(self): |
| 269 | """Download sources""" |
| 270 | src_dir = os.path.dirname(self.src_file) |
| 271 | if not os.path.isdir(src_dir): |
| 272 | os.makedirs(src_dir) |
| 273 | data = None |
| 274 | for url_template in self.url_templates: |
| 275 | url = url_template.format(v=self.version, s=self.short_version) |
| 276 | log.info("Downloading from {}".format(url)) |
| 277 | try: |
| 278 | req = urlopen(url) |
| 279 | # KISS, read all, write all |
| 280 | data = req.read() |
| 281 | except HTTPError as e: |
| 282 | log.error( |
| 283 | "Download from {} has from failed: {}".format(url, e) |
| 284 | ) |
| 285 | else: |
| 286 | log.info("Successfully downloaded from {}".format(url)) |
| 287 | break |
| 288 | if data is None: |
| 289 | raise ValueError("All download URLs have failed") |
| 290 | log.info("Storing {}".format(self.src_file)) |
| 291 | with open(self.src_file, "wb") as f: |
| 292 | f.write(data) |
| 293 | |
| 294 | def _unpack_src(self): |
| 295 | """Unpack tar.gz bundle""" |