def DownloadFile(self, url: Text, save_location: Text, max_retries: int = 5, show_progress: bool = False): """Downloads a file from one location to another. If URL references a local path, the file will be copied rather than downloaded. Args: url: The address of the file to be downloaded. save_location: The full path of where the file should be saved. max_retries: The number of times to attempt to download a file if the first attempt fails. show_progress: Print download progress to stdout (overrides default). Raises: DownloadError: failure writing file to the save_location """ self._save_location = save_location if IsRemote(url): if self._beyondcorp.CheckBeyondCorp(): url = self._SetUrl(url) max_retries = -1 file_stream = self._OpenStream(url, max_retries) self._StreamToDisk(file_stream, show_progress) else: try: file_util.Copy(url, save_location) except file_util.Error as e: raise DownloadError(str(e))
def Run(self): try: src = self._args[0] dst = self._args[1] except IndexError: raise ActionError('Unable to determine source and destination from %s.' % str(self._args)) try: file_util.Copy(src, dst) except (file_util.Error) as e: raise ActionError(str(e))