def __download(self, download_info, finish_func, cancel_to_state): download_success = True GLib.idle_add(self.update_to_state, self.state.QUEUED) Config.set("current_download", self.game.id) # Start the download for all files self.download_list = [] number_of_files = len(download_info['files']) total_file_size = 0 executable_path = None download_files = [] for key, file_info in enumerate(download_info['files']): try: download_url = self.api.get_real_download_link( file_info["downlink"]) except ValueError as e: print(e) GLib.idle_add(self.parent.parent.show_error, _("Download error"), _(str(e))) download_success = False break total_file_size += self.api.get_file_size(file_info["downlink"]) try: # Extract the filename from the download url (filename is between %2F and &token) filename = urllib.parse.unquote( re.search('%2F(((?!%2F).)*)&t', download_url).group(1)) except AttributeError: filename = "{}-{}.bin".format(self.game.get_stripped_name(), key) download_path = os.path.join(self.download_dir, filename) if key == 0: # If key = 0, denote the file as the executable's path executable_path = download_path md5sum = self.api.get_download_file_md5(file_info["downlink"]) if md5sum: self.game.md5sum[os.path.basename(download_path)] = md5sum download = Download( url=download_url, save_location=download_path, finish_func=finish_func if download_path == executable_path else None, progress_func=self.set_progress, cancel_func=lambda: self.__cancel(to_state=cancel_to_state), number=number_of_files - key, out_of_amount=number_of_files, game=self.game) download_files.insert(0, download) self.download_list.extend(download_files) if check_diskspace(total_file_size, Config.get("install_dir")): DownloadManager.download(download_files) ds_msg_title = "" ds_msg_text = "" else: ds_msg_title = "Download error" ds_msg_text = "Not enough disk space to install game." download_success = False if ds_msg_title: GLib.idle_add(self.parent.parent.show_error, _(ds_msg_title), _(ds_msg_text)) return download_success
def test2_check_diskspace(self, mock_os_statvfs): frsize = 4096 bavail = 29699 mock_os_statvfs().f_frsize = frsize mock_os_statvfs().f_bavail = bavail exp = False obs = installer.check_diskspace(524288000, "/") self.assertEqual(exp, obs)