def get_metadata_and_check_license(self, result): """Download files to download + license and check it""" logger.debug("Parse download metadata") error_msg = result[self.download_page].error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.download_page, error_msg)) UI.return_main_screen() url, md5sum = (None, None) with StringIO() as license_txt: in_license = False in_download = False for line in result[self.download_page].buffer: line_content = line.decode() if self.expect_license: in_license = self.parse_license(line_content, license_txt, in_license) (download, in_download) = self.parse_download_link(line_content, in_download) if download is not None: (newurl, newmd5sum) = download url = newurl if newurl is not None else url md5sum = newmd5sum if newmd5sum is not None else md5sum logger.debug("Found download link for {}, md5sum: {}".format(url, md5sum)) if url is None or (self.require_md5 and md5sum is None): logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen() self.download_requests.append((url, md5sum)) if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display(LicenseAgreement(strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) elif self.expect_license: logger.error("We were expecting to find a license on the download page, we didn't.") UI.return_main_screen() else: self.start_download_and_install() return
def test_strip_without_tags(self): """We return unmodified content if there is no tag""" self.assertEquals(tools.strip_tags("content content content contentcontent\n content" "\ncontent content"), "content content content contentcontent\n content\ncontent content")
def test_strip_invalid_tags(self): """We return trip tags even if invalid""" self.assertEquals(tools.strip_tags("content <a foo bar>content content content</a><b>content\n content</c>" "\n</b>content content"), "content content content contentcontent\n content\ncontent content")
def test_strip_tags(self): """We return strip tags from content""" self.assertEquals(tools.strip_tags("content <a foo bar>content content content</a><b><c>content\n content</c>" "\n</b>content content"), "content content content contentcontent\n content\ncontent content")