def download(self, srm_file, local_dir="./", check=False): """Download a file from the SRM. @param srm_file: complete path to the file on the SRM. @param local_dir: directory where the file needs to be copied to. @return: location of the downloaded file. """ local_file = path.join(local_dir, path.basename(srm_file)) srm_url = self.srm_host + srm_file if check: if not self.remote_exists(srm_file): raise EnvironmentError(10, "File not found.", srm_url) cmd = [ 'srmcp', '-2', '-server_mode=passive', srm_url, 'file:///' + local_file ] self.logger.info("Downloading: " + local_file) returncode = execute_old(" ".join(cmd)) self.logger.debug("Done downloading " + local_file) if returncode == 0: pass else: self.logger.error("Download failed of: " + srm_file) raise EnvironmentError("Download failed.") return local_file
def remove(self, srm_file): """Remove a file from the SRM. @param srm_file: Path to the file on the SRM. @return: True when the operation succeeded. Throws an environment error otherwise. """ srm_url = self.srm_host + srm_file cmd = ['srmrm', srm_url] returncode = execute_old(" ".join(cmd)) if returncode == 0: pass else: self.logger.error("Removal failed of: " + srm_file) raise EnvironmentError("Remove failed.") return True
def download(self, srm_file, local_dir="./", check=False): """Download a file from the SRM. @param srm_file: complete path to the file on the SRM. @param local_dir: directory where the file needs to be copied to. @return: location of the downloaded file. """ local_file = path.join(local_dir, path.basename(srm_file)) srm_url = self.srm_host + srm_file if check: if not self.remote_exists(srm_file): raise EnvironmentError(10, "File not found.", srm_url) cmd = ['srmcp', '-2', '-server_mode=passive', srm_url, 'file:///' + local_file] self.logger.info("Downloading: " + local_file) returncode = execute_old(" ".join(cmd)) self.logger.debug("Done downloading " + local_file) if returncode == 0: pass else: self.logger.error("Download failed of: " + srm_file) raise EnvironmentError("Download failed.") return local_file