コード例 #1
0
ファイル: self_updater.py プロジェクト: Numerlor/Auto_Neutron
    def check_update(self) -> None:
        """
        Check for a new version, if one is found download it and restart with the new file.

        The current executable's file will be renamed to a temporary name, and deleted by this method on the next run.
        """
        if not __debug__:
            log.info("Requesting version info.")
            make_network_request(LATEST_RELEASE_URL,
                                 finished_callback=self._check_new_version)
            try:
                EXECUTABLE_PATH.with_stem(TEMP_NAME).unlink(
                    missing_ok=True)  # Try to delete old executable
            except OSError as e:
                log.warning("Unable to delete temp executable.", exc_info=e)

            temp_dir = EXECUTABLE_PATH.parent / TEMP_NAME

            if temp_dir.exists():
                try:
                    shutil.rmtree(temp_dir)
                except OSError as e:
                    log.warning("Unable to delete temp directory files.",
                                exc_info=e)

            # delete temp dir generated by previous versions
            temp_dir = EXECUTABLE_PATH.parent.with_name(TEMP_NAME)

            if temp_dir.exists():
                try:
                    shutil.rmtree(temp_dir)
                except OSError as e:
                    log.warning("Unable to delete temp directory files.",
                                exc_info=e)
コード例 #2
0
ファイル: self_updater.py プロジェクト: Numerlor/Auto_Neutron
    def _download_new_release(self, release_json: dict[str, t.Any]) -> None:
        """Start downloading the appropriate new release asset."""
        if IS_ONEFILE:
            asset_name = "Auto_Neutron.exe"
        else:
            asset_name = "Auto_Neutron.zip"

        asset_json = next(
            (asset for asset in release_json["assets"]
             if asset["name"] == asset_name),
            None,
        )

        if asset_json is None:
            self._show_error_window(
                _("Unable to find appropriate new release."))
        else:
            download_url = asset_json["browser_download_url"]
            hash_download_url = download_url + ".signature.txt"
            log.info(f"Downloading hash from {download_url}.")
            make_network_request(
                hash_download_url,
                finished_callback=partial(self._set_hash_and_download,
                                          asset_download_url=download_url),
            )
コード例 #3
0
 def _make_nearest_request(self) -> None:
     """Make a request to Spansh's nearest endpoint with the values from spinboxes."""
     self._abort_request()
     self._current_network_request = make_network_request(
         SPANSH_API_URL + "/nearest",
         params={
             "x": self.x_spinbox.value,
             "y": self.y_spinbox.value,
             "z": self.z_spinbox.value,
         },
         finished_callback=self._assign_from_reply,
     )
     self.cursor = QtGui.QCursor(QtCore.Qt.CursorShape.BusyCursor)
コード例 #4
0
ファイル: self_updater.py プロジェクト: Numerlor/Auto_Neutron
    def _set_hash_and_download(self, network_reply: QtNetwork.QNetworkReply,
                               asset_download_url: str) -> None:
        """Schedule the file to be downloaded and pass it the checksum hash from the reply."""
        try:
            if network_reply.error(
            ) is QtNetwork.QNetworkReply.NetworkError.NoError:
                hash_ = network_reply.read_all().data().decode().strip()
                log.info(f"Downloading release from {asset_download_url}.")
                self._download_started.emit(
                    make_network_request(
                        asset_download_url,
                        finished_callback=partial(self._create_new_and_restart,
                                                  hash_to_check=hash_),
                    ))
            elif (network_reply.error() is
                  QtNetwork.QNetworkReply.NetworkError.OperationCanceledError):
                return
            else:
                self._show_error_window(network_reply.error_string())
                return

        finally:
            network_reply.delete_later()
コード例 #5
0
ファイル: route_plots.py プロジェクト: Numerlor/Auto_Neutron
 def make_request(self, *args: t.Any, **kwargs: t.Any) -> None:
     """Make a network request and store the result reply."""
     self._current_reply = make_network_request(*args, **kwargs)