[Paraview] PV client-server: browsing remote files
Robert Sawko
robertsawko at gmail.com
Fri Jan 5 14:05:08 EST 2018
Hi,
I will bump my own post from a month back (see below) and just will answer the
question in case anyone else was looking for something similar. I haven't found
a way to remotely navigate the file system through ParaView Python API objects,
but of course there are other Python packages which can achieve that. I used
paramiko. Below is my minimal example.
from paraview.simple import LegacyVTKReader, RenameSource, Connect
from paramiko import SSHClient, AutoAddPolicy
'''
This script extracts the output of a remote ls command with to feed into
a LegacyVTKReader. The main use is it to make a collection of VTK files
into a time sequence inside PV.
'''
# Inputs:
host = 'remote.host.com'
port = 22
username = 'me'
key_filename = '/path/to/private/key'
pvhost = 'localhost' # I typically run pvserver through an ssh tunnel so
pvport = 22227 # these are the parameters for local port forward
data_dir = '/path/to/data/on/remote'
# SSH part
# to get a list of files to open
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(
host, port=port,
username=username,
key_filename=key_filename)
stdin, stdout, stderr = client.exec_command(
'ls -1 {0}'.format(data_dir))
lslines = stdout.readlines()
client.close()
# ParaView part
Connect('localhost', 22227)
reader = LegacyVTKReader(FileNames=[
'data/{0}'.format(l.strip()) for l in lslines])
RenameSource('source', reader)
Hope this helps someone!
Robert
On 12/01/17 at 07:18pm, Robert Sawko wrote:
> Dear ParaViewers,
>
>
> I am trying to use Python shell in Client-Server mode, but I am running into
> some difficulties. How can I actually browse the remote directories. I tried
> to use the `os` module, but that obviously ends up being all local. Here's a
> minimal example of what I am trying to achieve.
>
>
> from paraview.simple import Connect, LegacyVTKReader
> from os import listdir
>
> Connect('my_server', port)
> location = '/my/remote/location/'
>
> file_names = listdir(location).sort()
> reader = LegacyVTKReader(FileNames=file_names)
>
>
> Please let me know if it's at all possible to query the directory on the remote
> side through an established connection.
>
> Many thanks,
> Robert
> --
> Seems like the famous poem of turbulence comes from Jonathan Swift
> http://en.wikipedia.org/wiki/The_Siphonaptera
--
Playing possum, opposable digit, climbing, swimming, omnivores...
Is there nothing they can't do?
http://en.wikipedia.org/wiki/Opossum
More information about the ParaView
mailing list