[Paraview] PV client-server: browsing remote files

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Sat Jan 6 14:03:34 EST 2018


Robert,

Sorry I missed the email earlier. What you have as an alternative is
indeed a reasonable approach. Once can also use ParaView's
infrastructure used by the file dialog, but it's a little clunky
currently, since it needs to be pythonified for easier user.

Here's how you'd do this with 5.4.1.

from paraview import servermanager as sm

helper = sm.misc.FileInformationHelper()
helper.DirectoryListing = 1
helper.WorkingDirecotry = "'/path/to/data/on/remote"

pvinfo = servermanager.vtkPVFileInformation()
helper.GatherInformation(pvinfo)
for a_pvinfo in pvinfo.GetConents():
   if a_pvinfo.GetType() == a_pvinfo.FILE_GROUP:
     for b_pvinfo in a_pvinfo.GetContents():
        assert b_pvinfo.GetType() == b_pvinfo.SINGLE_FILE
        print (b_pvinfo.GetName(),  b_pvinfo.GetFullPath())
   elif a_pvinfo.GetType() ==  a_pvinfo.SINGLE_FILE
      print (a_pvinfo.GetName(),  a_pvinfo.GetFullPath())

This will print all files in the directory.

See vtkPVFileInformation docs
(https://www.paraview.org/ParaView3/Doc/Nightly/www/cxx-doc/classvtkPVFileInformation.html)
for more API details.

Hope that helps.

Utkarsh

On Fri, Jan 5, 2018 at 2:05 PM, Robert Sawko <robertsawko at gmail.com> wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> https://paraview.org/mailman/listinfo/paraview


More information about the ParaView mailing list