user_interface - file_transfer
The user_interface package provides functions for interacting with files to and from the client.
Functions
Function | Parameters | Return Value | Description |
|---|---|---|---|
choose_remote_file | save_file: | Path to the remote file or | Shows an open dialog on the Client to let the user select a file |
copy_local_file_remote | local_file: A file-like descriptor | Number of bytes written | Copy a file from the Server to the Client |
copy_remote_file_locally | remote_path: Path to a folder on the part of the Client | Number of bytes written | Copy a file from the Client to the Server |
get_file | title: Dialog title text | A | Shows an open dialog and reads the selected file |
open_remote_file | remote_path: Path to a folder on the part of the Client | A | Open a remote file to read or write it |
read_remote_file | remote_path: Path to a folder on the part of the Client | A file-like object to read from ( | Read a file located on the Client from the Server |
store_file | local_file: A file-like descriptor | Number of bytes written or | Open a save file dialog on the Client to store the content of the |
store_file_without_dialog | local_file: A file-like descriptor | Copies the content of a file located on the Server to the Client. The local file must be opened with |
Warning:
When you try to copy files the size of which amounts to several megabytes or more, the execution might be interrupted due to a service timeout
Examples
Select a logfile and send it to the Client
import os
from ppms.user_interface import ask_user_to_select_from_list, store_file
def get_all_logfiles():
return [logfile for logfile in os.listdir('log') if logfile.endswith('.log')]
def ending_stripper(logfile):
return logfile.rstrip('.log')
logfiles = get_all_logfiles()
selected_logfile = ask_user_to_select_from_list(possible_values=logfiles, heading='Please select a logfile:', transform_value_to_text=ending_stripper)
if selected_logfile is not None:
logfile_path = os.path.join('log', selected_logfile)
with open(logfile_path, 'rb') as logfile:
title = 'Where do you want to save this logfile?'
filter = 'Log files (*.log)|*.log|All files (*.*)|*.*'
store_file(local_file=logfile, title=title, filter=filter, suggested_filename=selected_logfile)