Example #1
0
    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, checksum = (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, new_checksum) = download
                    url = newurl if newurl is not None else url
                    checksum = new_checksum if new_checksum is not None else checksum
                    if url is not None:
                        if self.checksum_type and checksum:
                            logger.debug(
                                "Found download link for {}, checksum: {}".
                                format(url, checksum))
                            break
                        elif not self.checksum_type:
                            logger.debug(
                                "Found download link for {}".format(url))
                            break

            if url is None or (self.checksum_type and checksum is None):
                logger.error(
                    "Download page changed its syntax or is not parsable")
                UI.return_main_screen()
            self.download_requests.append(
                DownloadItem(url, Checksum(self.checksum_type, checksum)))

            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
Example #2
0
 def test_strip_without_tags(self):
     """We return unmodified content if there is no tag"""
     self.assertEqual(
         tools.strip_tags("content content content contentcontent\n content"
                          "\ncontent content"),
         "content content content contentcontent\n content\ncontent content"
     )
Example #3
0
    def check_data_and_start_download(self,
                                      url=None,
                                      checksum=None,
                                      license_txt=StringIO()):
        if url is None:
            logger.error(
                "Download page changed its syntax or is not parsable (url missing)"
            )
            UI.return_main_screen(status_code=1)
        if (self.checksum_type and checksum is None):
            logger.error(
                "Download page changed its syntax or is not parsable (checksum missing)"
            )
            logger.error("URL is: {}".format(url))
            UI.return_main_screen(status_code=1)
        self.download_requests.append(
            DownloadItem(url, Checksum(self.checksum_type, checksum)))

        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 and not self.auto_accept_license:
            logger.error(
                "We were expecting to find a license on the download page, we didn't."
            )
            UI.return_main_screen(status_code=1)
        else:
            self.start_download_and_install()
Example #4
0
    def check_external_license(self, result):
        """Check external license which is in a separate page (can be factorized in BaseInstaller)"""
        logger.debug("Parse license page")
        error_msg = result[self.license_url].error
        if error_msg:
            logger.error("An error occurred while downloading {}: {}".format(self.license_url, error_msg))
            UI.return_main_screen(status_code=1)

        with StringIO() as license_txt:
            in_license = False
            for line in result[self.license_url].buffer:
                line = line.decode()
                if ('SOFTWARE LICENSE TERMS' in line):
                    in_license = True
                if in_license and "<strong>*   *   *</strong>" in line:
                    in_license = False
                    continue
                if in_license:
                    license_txt.write(line.strip() + "\n")

            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))
            else:
                logger.error("We were expecting to find a license, we didn't.")
                UI.return_main_screen(status_code=1)
Example #5
0
    def check_external_license(self, result):
        """Check external license which is in a separate page (can be factorized in BaseInstaller)"""
        logger.debug("Parse license page")
        error_msg = result[self.license_url].error
        if error_msg:
            logger.error("An error occurred while downloading {}: {}".format(self.license_url, error_msg))
            UI.return_main_screen(status_code=1)

        with StringIO() as license_txt:
            in_license = False
            for line in result[self.license_url].buffer:
                line = line.decode()
                if ('SOFTWARE LICENSE TERMS' in line):
                    in_license = True
                if in_license and "<strong>*   *   *</strong>" in line:
                    in_license = False
                    continue
                if in_license:
                    license_txt.write(line.strip() + "\n")

            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))
            else:
                logger.error("We were expecting to find a license, we didn't.")
                UI.return_main_screen(status_code=1)
Example #6
0
 def test_strip_invalid_tags(self):
     """We return trip tags even if invalid"""
     self.assertEqual(
         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"
     )
Example #7
0
 def test_strip_tags(self):
     """We return strip tags from content"""
     self.assertEqual(
         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"
     )
Example #8
0
 def test_strip_invalid_tags(self):
     """We return trip tags even if invalid"""
     self.assertEqual(
         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",
     )
Example #9
0
 def test_strip_tags(self):
     """We return strip tags from content"""
     self.assertEqual(
         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",
     )
Example #10
0
    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(status_code=1)

        url, checksum = (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 and not self.auto_accept_license:
                    in_license = self.parse_license(line_content, license_txt, in_license)

                # always take the first valid (url, checksum) if not match_last_link is set to True:
                download = None
                if url is None or (self.checksum_type and not checksum) or self.match_last_link:
                    (download, in_download) = self.parse_download_link(line_content, in_download)
                if download is not None:
                    (newurl, new_checksum) = download
                    url = newurl if newurl is not None else url
                    checksum = new_checksum if new_checksum is not None else checksum
                    if url is not None:
                        if self.checksum_type and checksum:
                            logger.debug("Found download link for {}, checksum: {}".format(url, checksum))
                        elif not self.checksum_type:
                            logger.debug("Found download link for {}".format(url))

            if url is None:
                logger.error("Download page changed its syntax or is not parsable (url missing)")
                UI.return_main_screen(status_code=1)
            if (self.checksum_type and checksum is None):
                logger.error("Download page changed its syntax or is not parsable (checksum missing)")
                logger.error("URL is: {}".format(url))
                UI.return_main_screen(status_code=1)
            self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, checksum)))

            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 and not self.auto_accept_license:
                logger.error("We were expecting to find a license on the download page, we didn't.")
                UI.return_main_screen(status_code=1)
            else:
                self.start_download_and_install()
Example #11
0
    def check_data_and_start_download(self, url=None, checksum=None, license_txt=StringIO()):
        if url is None:
            logger.error("Download page changed its syntax or is not parsable (url missing)")
            UI.return_main_screen(status_code=1)
        if (self.checksum_type and checksum is None):
            logger.error("Download page changed its syntax or is not parsable (checksum missing)")
            logger.error("URL is: {}".format(url))
            UI.return_main_screen(status_code=1)
        self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, checksum)))

        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 and not self.auto_accept_license:
            logger.error("We were expecting to find a license on the download page, we didn't.")
            UI.return_main_screen(status_code=1)
        else:
            self.start_download_and_install()
Example #12
0
 def test_strip_without_tags(self):
     """We return unmodified content if there is no tag"""
     self.assertEqual(tools.strip_tags("content content content contentcontent\n content"
                                       "\ncontent content"),
                      "content content content contentcontent\n content\ncontent content")