def get_file_details(self, file_path): """ Retrieves the contents of a file and its permissions. @param file_path: Path to the file @type file_path: string @return: File details including permissions and content @rtype: FileDetails """ command = ('[ -f {file_path} ] && echo "File exists" || ' 'echo "File does not exist"'.format(file_path=file_path)) output = self.ssh_client.execute_command(command) if output is None: return None output = output.stdout if not output.rstrip('\n') == 'File exists': raise FileNotFoundException( "File {file_path} not found on instance.".format( file_path=file_path)) file_permissions = self.ssh_client.execute_command( 'stat -c %a {file_path}'.format( file_path=file_path)).stdout.rstrip("\n") file_contents = self.ssh_client.execute_command( 'cat {file_path}'.format(file_path=file_path)).stdout return FileDetails(file_permissions, file_contents, file_path)
def get_file_details(self, filepath): """ @summary: Get the file details @param filepath: Path to the file @type filepath: string @return: File details including permissions and content @rtype: FileDetails """ output = self.ssh_client.exec_command( '[ -f ' + filepath + ' ] && echo "File exists" || echo "File does not exist"') if not output.rstrip('\n') == 'File exists': raise FileNotFoundException("File:" + filepath + " not found on instance.") file_permissions = self.ssh_client.exec_command('stat -c %a ' + filepath).rstrip("\n") file_contents = self.ssh_client.exec_command('cat ' + filepath) return FileDetails(file_permissions, file_contents, filepath)