def upload(self, local_file, srm_dir, check=False): """Upload local file to the SRM. @local_file: the file that needs to be copied. @param srm_dir: location on the SRM where the file needs to be copied to. @param check: whether to check if the local and remote files exist. Default: True @return: location of the file on the SRM. """ srm_file = path.join(srm_dir, path.basename(local_file)) srm_url = self.srm_host + srm_file if check: if not path.isfile(local_file): raise EnvironmentError(10, "File not found.", local_file) if self.remote_exists(srm_file): raise EnvironmentError(11, "File exists on srm.", srm_url) cmd = ['srmcp', '-2', '-server_mode=passive', 'file:///' + local_file, srm_url] print cmd (returncode, stdout, stderr) = execute(cmd) if returncode == 0: pass else: raise EnvironmentError("Upload failed.") return srm_url
def upload(self, local_file, srm_dir, check=False): """Upload local file to the SRM. @local_file: the file that needs to be copied. @param srm_dir: location on the SRM where the file needs to be copied to. @param check: whether to check if the local and remote files exist. Default: True @return: location of the file on the SRM. """ srm_file = path.join(srm_dir, path.basename(local_file)) srm_url = self.srm_host + srm_file if check: if not path.isfile(local_file): raise EnvironmentError(10, "File not found.", local_file) if self.remote_exists(srm_file): raise EnvironmentError(11, "File exists on srm.", srm_url) cmd = [ 'srmcp', '-2', '-server_mode=passive', 'file:///' + local_file, srm_url ] print cmd (returncode, stdout, stderr) = execute(cmd) if returncode == 0: pass else: raise EnvironmentError("Upload failed.") return srm_url
def remote_exists(self, loc): """Check if a file exists on the remote location. @param loc: complete path on the SRM to the file. @return: True when the """ sURL = self.srm_host + loc cmd = ['srmls', sURL] print " ".join(cmd) (returncode, stdout, stderr) = execute(cmd) if returncode == 0: bn = path.basename(loc) lines = stdout.split("\n") for line in lines: if bn in line: return True return False else: return False