def __download_file(self, download): self.prepare_location(download.save_location) download_max_attempts = 5 download_attempt = 0 result = False while download_attempt < download_max_attempts: try: start_point, download_mode = self.get_start_point_and_download_mode( download) result = self.download_operation(download, start_point, download_mode) break except ConnectionError as e: print(e) download_attempt += 1 # mark download as complete self.__mark_download_as_complete(download, result) # Successful downloads if result: if download.number == download.out_of_amount: finish_thread = threading.Thread(target=download.finish) finish_thread.start() if self.__queue.empty(): Config.unset("current_download") # Unsuccessful downloads and cancels else: self.__cancel = False download.cancel() self.__current_download = None os.remove(download.save_location)
def test_unset(self, mock_isfile): mock_isfile.return_value = True config = JSON_DEFAULT_CONFIGURATION with patch("builtins.open", mock_open(read_data=config)): from goodoldgalaxy.config import Config Config.unset("lang") lang = Config.get("lang") exp = None obs = lang self.assertEqual(exp, obs)
def logout(self, button): # Unset everything which is specific to this user Config.unset("username") Config.unset("user_id") Config.unset("refresh_token") self.hide() # Show the login screen self.__authenticate() self.user_photo.set_tooltip_text(self.api.get_user_info()) self.user_photo.set_from_icon_name("contact-new", 4) self.sync_library() self.show_all()
def __authenticate(self): url = None if Config.get("stay_logged_in"): token = Config.get("refresh_token") else: Config.unset("username") Config.unset("user_id") Config.unset("refresh_token") token = None # Make sure there is an internet connection if not self.api.can_connect(): return try: authenticated = self.api.authenticate(refresh_token=token, login_code=url) except Exception as ex: print("Could not authenticate with GOG. Cause: {}".format(ex)) return while not authenticated: login_url = self.api.get_login_url() redirect_url = self.api.get_redirect_url() login = Login(login_url=login_url, redirect_url=redirect_url, parent=self) response = login.run() login.hide() if response == Gtk.ResponseType.DELETE_EVENT: Gtk.main_quit() exit(0) if response == Gtk.ResponseType.NONE: result = login.get_result() authenticated = self.api.authenticate(refresh_token=token, login_code=result) Config.set("refresh_token", authenticated)
def prevent_resume_on_startup(self, game): download_id = Config.get("current_download") if download_id and download_id == game.id: Config.unset("current_download")