Contribute#

Overall guidance on contributing to a PyAnsys library appears in the Contributing topic in the PyAnsys developer’s guide. Ensure that you are thoroughly familiar with this guide before attempting to contribute to the FileTransfer Tool Server.

Setup#

  • For information on how to build the FileTransfer Tool Server from source, see Getting started.

  • To build the documentation, use this command:

    poetry run -C doc html
    
  • To run tests, use this command:

    cd build; ctest; cd ..
    
  • To run pre-commit style checks, run this command:

    poetry run pre-commit run --all-files
    

Internal API#

Documentation follows for the internal classes and functions of the FileTransfer Tool Server. This documentation is intended for developers who want to understand the inner workings of the server and possibly extend it.

namespace file_transfer#

Typedefs

using pb_progress_t = decltype(::ansys::api::tools::filetransfer::v1::ProgressResponse().state())#
using pb_filesize_t = decltype(::ansys::api::tools::filetransfer::v1::FileInfo().size())#

Enums

enum Progress#

Named constants for the progress of a file transfer operation.

Values:

enumerator INITIALIZED#
enumerator COMPLETED#
class FileTransferServiceImpl : public ansys::api::tools::filetransfer::v1::FileTransferService::Service#

This class implements the file transfer service.

Public Functions

virtual auto DownloadFile(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::ansys::api::tools::filetransfer::v1::DownloadFileResponse, ::ansys::api::tools::filetransfer::v1::DownloadFileRequest> *stream) -> ::grpc::Status override#

Implements the “DownloadFile” operation.

Parameters:
  • context – Server context to use.

  • stream – Stream of requests and responses to process.

Returns:

Result of the operation.

virtual auto UploadFile(::grpc::ServerContext *context, ::grpc::ServerReaderWriter<::ansys::api::tools::filetransfer::v1::UploadFileResponse, ::ansys::api::tools::filetransfer::v1::UploadFileRequest> *stream) -> ::grpc::Status override#

Implements the “UploadFile” operation.

Parameters:
  • context – Server context to use.

  • stream – Stream of requests and responses to process.

Returns:

Result of the operation.

namespace detail#

Functions

auto get_sha1_hex_digest(const boost::filesystem::path &path_, const std::streamsize chunk_size_ = 1024) -> std::string#

Get the SHA1 hex digest of a file.

Note

This function is not thread-safe.

Parameters:
  • path_ – Path to the file.

  • chunk_size_ – Size of the chunks to read from the file.

Returns:

SHA1 hex digest of the file.

namespace download_impl#

Typedefs

using stream_t = ::grpc::ServerReaderWriter<api::DownloadFileResponse, api::DownloadFileRequest>#

Functions

auto get_request_checked(google::protobuf::Arena &arena_, stream_t *stream_, const api::DownloadFileRequest::SubStepCase &expected_step_) -> api::DownloadFileRequest*#
auto initialize(google::protobuf::Arena &arena_, stream_t *stream_) -> std::tuple<const boost::filesystem::path, const std::size_t, const std::streamsize>#
auto transfer(const boost::filesystem::path &file_path_, const std::size_t file_size_, const std::streamsize chunk_size_, google::protobuf::Arena &arena_, stream_t *stream_) -> void#
auto finalize(google::protobuf::Arena &arena_, stream_t *stream_) -> void#
namespace exceptions#

Functions

auto convert_exceptions_to_status_codes(const std::function<void()>&) -> ::grpc::Status#

Convert exceptions to gRPC status codes.

Parameters:

fun – Function to execute.

Returns:

gRPC status code.

class not_found : public std::runtime_error#

Exception type raised when an object is not found.

class invalid_argument : public std::runtime_error#

Exception type raised when invalid parameters are provided.

class failed_precondition : public std::runtime_error#

Exception type raised when some precondition is not met. For example, a file is expected to exist, but it does not.

class data_loss : public std::runtime_error#

Exception type raised when the transmitted data is lost or corrupted.

class internal : public std::runtime_error#

Exception type raised when an internal error occurs.

namespace detail#

Functions

template<typename ExceptionT>
auto get_exception_message(const ExceptionT &exc) -> std::string#
namespace upload_impl#

Typedefs

using stream_t = ::grpc::ServerReaderWriter<api::UploadFileResponse, api::UploadFileRequest>#

Functions

auto get_request_checked(api::UploadFileRequest *request_, stream_t *stream_, const api::UploadFileRequest::SubStepCase &expected_step_) -> void#
auto get_request_checked(google::protobuf::Arena &arena_, stream_t *stream_, const api::UploadFileRequest::SubStepCase &expected_step_) -> api::UploadFileRequest*#
auto initialize(google::protobuf::Arena &arena_, stream_t *stream_) -> std::tuple<const boost::filesystem::path, const std::size_t, const std::string>#
auto transfer(const boost::filesystem::path &file_path_, const std::size_t file_size_, google::protobuf::Arena &arena_, stream_t *stream_) -> void#
auto finalize(const boost::filesystem::path &file_path_, const std::string &source_sha1_hex_, google::protobuf::Arena &arena_, stream_t *stream_) -> void#