Beispiel #1
0
    def get_sha_and_start_download(self, download_result):
        res = download_result[self.checksum_url].buffer.getvalue().decode()
        line = re.search(
            r'.*linux{}.tar.xz'.format(self.arch_trans[get_current_arch()]),
            res).group(0)
        # you get and store url and checksum
        checksum = line.split()[0]
        url = os.path.join(
            self.checksum_url.rpartition('/')[0],
            line.split()[1])
        if url is None:
            logger.error(
                "Download page changed its syntax or is not parsable (missing url)"
            )
            UI.return_main_screen(status_code=1)
        if checksum is None:
            logger.error(
                "Download page changed its syntax or is not parsable (missing sha512)"
            )
            UI.return_main_screen(status_code=1)
        logger.debug("Found download link for {}, checksum: {}".format(
            url, checksum))
        self.download_requests.append(
            DownloadItem(url, Checksum(self.checksum_type, checksum)))

        # add the user to arduino group
        if not self.was_in_arduino_group:
            with futures.ProcessPoolExecutor(max_workers=1) as executor:
                f = executor.submit(_add_to_group, self._current_user,
                                    self.ARDUINO_GROUP)
                if not f.result():
                    UI.return_main_screen(status_code=1)

        self.start_download_and_install()
Beispiel #2
0
    def get_metadata(self, result):
        """Download files to download + and download license 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)

        arch = platform.machine()
        download_re = r'\'linux64\': \'([^\']+)\''
        if arch == 'i686':
            download_re = r'\'linux32\': \'([^\']+)\''
        url = None
        for line in result[self.download_page].buffer:
            line = line.decode()
            p = re.search(download_re, line)
            with suppress(AttributeError):
                url = p.group(1)
                logger.debug("Found download link for {}".format(url))

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

        if not self.auto_accept_license:
            logger.debug("Downloading License page")
            DownloadCenter([DownloadItem(self.license_url, headers=self.headers)], self.check_external_license,
                           download=False)
        else:
            self.start_download_and_install()
Beispiel #3
0
    def test_download_with_wrong_sha256(self):
        """we raise an error if we don't have the correct sha256"""
        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request, Checksum(ChecksumType.sha256, 'AAAAA'))], self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertIn("Corrupted download", result.error)
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.fd)
        self.expect_warn_error = True
Beispiel #4
0
 def get_sha_and_start_download(self, download_result):
     res = download_result[self.sha1_url]
     sha1 = res.buffer.getvalue().decode('utf-8').split()[0]
     url = re.sub('.sha1', '', self.sha1_url)
     if url is None:
         logger.error("Download page changed its syntax or is not parsable (missing url)")
         UI.return_main_screen(status_code=1)
     if sha1 is None:
         logger.error("Download page changed its syntax or is not parsable (missing sha512)")
         UI.return_main_screen(status_code=1)
     logger.debug("Found download link for {}, checksum: {}".format(url, sha1))
     self.download_requests.append(DownloadItem(url, Checksum(ChecksumType.sha1, sha1)))
     self.start_download_and_install()
Beispiel #5
0
 def get_url_and_start_download(self, download_result):
     res = download_result[self.download_url]
     text = res.buffer.getvalue().decode('utf-8')
     url = re.search(r'http.*?.sh', text).group(0)
     if url is None:
         logger.error("Download page changed its syntax or is not parsable (missing url)")
         UI.return_main_screen(status_code=1)
     if self.checksum is None:
         logger.error("Download page changed its syntax or is not parsable (missing checksum)")
         UI.return_main_screen(status_code=1)
     logger.debug("Found download link for {}, checksum: {}".format(url, self.checksum))
     self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, self.checksum)))
     self.start_download_and_install()
Beispiel #6
0
    def test_download_with_wrong_checksumtype(self):
        """we raise an error if we don't have a support checksum type"""
        class WrongChecksumType(Enum):
            didrocksha = "didrocksha"

        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request, Checksum(WrongChecksumType.didrocksha, 'AAAAA'))], self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertIn("Unsupported checksum type", result.error)
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.fd)
        self.expect_warn_error = True
Beispiel #7
0
    def test_download_with_sha1sum(self):
        """we deliver once successful download, matching sha1sum"""
        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request, Checksum(ChecksumType.sha1, '0562f08aef399135936d6fb4eb0cc7bc1890d5b4'))],
                       self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertTrue(self.callback.called)
        self.assertEqual(self.callback.call_count, 1)
        with open(join(self.server_dir, filename), 'rb') as file_on_disk:
            self.assertEqual(file_on_disk.read(),
                             result.fd.read())
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.error)
Beispiel #8
0
    def test_download_with_md5(self):
        """we deliver once successful download, matching md5sum"""
        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request, Checksum(ChecksumType.md5, '268a5059001855fef30b4f95f82044ed'))],
                       self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertTrue(self.callback.called)
        self.assertEqual(self.callback.call_count, 1)
        with open(join(self.server_dir, filename), 'rb') as file_on_disk:
            self.assertEqual(file_on_disk.read(),
                             result.fd.read())
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.error)
Beispiel #9
0
    def test_download_with_sha256sum(self):
        """we deliver once successful download, matching sha256sum"""
        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request,
                                     Checksum(ChecksumType.sha256,
                                              'b1b113c6ed8ab3a14779f7c54179eac2b87d39fcebbf65a50556b8d68caaa2fb'))],
                       self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertTrue(self.callback.called)
        self.assertEqual(self.callback.call_count, 1)
        with open(join(self.server_dir, filename), 'rb') as file_on_disk:
            self.assertEqual(file_on_disk.read(),
                             result.fd.read())
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.error)
Beispiel #10
0
        def done(download_result):
            res = download_result[md5_url]

            if res.error:
                logger.error(res.error)
                UI.return_main_screen()

            # Should be ASCII anyway.
            md5 = res.buffer.getvalue().decode('utf-8').split()[0]
            logger.debug("Downloaded MD5 is {}".format(md5))

            logger.debug("Preparing to download the main archive.")
            if arch == 'i686':
                download_url = self.DOWNLOAD_URL_PAT.format(arch='', suf='')
            elif arch == 'x86_64':
                download_url = self.DOWNLOAD_URL_PAT.format(arch='-x86_64',
                                                            suf='')
            self.download_requests.append(DownloadItem(download_url, Checksum(ChecksumType.md5, md5)))
            self.start_download_and_install()
Beispiel #11
0
    def test_download_with_sha512sum(self):
        """we deliver once successful download, matching sha512sum"""
        filename = "simplefile"
        request = self.build_server_address(filename)
        DownloadCenter([DownloadItem(request,
                                     Checksum(ChecksumType.sha512,
                                              '74e20d520ba4ecfdb59d98ac213deccecf591c9c6bfc5996ac158ab6facd6611cce7dd2'
                                              '2120b63ebe9217f159506f352ce0ee6c0c2a1d200841ae21635dc5f9a'))],
                       self.callback)
        self.wait_for_callback(self.callback)

        result = self.callback.call_args[0][0][request]
        self.assertTrue(self.callback.called)
        self.assertEqual(self.callback.call_count, 1)
        with open(join(self.server_dir, filename), 'rb') as file_on_disk:
            self.assertEqual(file_on_disk.read(),
                             result.fd.read())
        self.assertIsNone(result.buffer)
        self.assertIsNone(result.error)
Beispiel #12
0
 def get_sha_and_start_download(self, download_result):
     res = download_result[self.checksum_url]
     checksum = res.buffer.getvalue().decode('utf-8').split()[0]
     # you get and store self.download_url
     url = re.sub('.' + self.checksum_type.name, '', self.checksum_url)
     if url is None:
         logger.error(
             "Download page changed its syntax or is not parsable (missing url)"
         )
         UI.return_main_screen(status_code=1)
     if checksum is None:
         logger.error(
             "Download page changed its syntax or is not parsable (missing checksum)"
         )
         UI.return_main_screen(status_code=1)
     logger.debug("Found download link for {}, checksum: {}".format(
         url, checksum))
     self.download_requests.append(
         DownloadItem(url, Checksum(self.checksum_type, checksum)))
     self.start_download_and_install()