bexchange.net package

Submodules

bexchange.net.connections module

class bexchange.net.connections.backup_connection(backend, arguments)[source]

Bases: publisher_connection

Backup connection, expects a list of senders in arguments. Where all senders are run.

publish(path, meta)[source]

Publishes a file in some way using the underlying implementation :param path: The path to the file :param meta: The metadata of the file

class bexchange.net.connections.combined_connection(backend, arguments)[source]

Bases: publisher_connection

Combined connection is a way to combine different connection types into one so that you for example can have different connections in one. For example, assume that you always wants a file to be sent to a specific target and then that you want a sequence of fail over connections after that.

publish(path, meta)[source]

Publishes the file to all connections for this connection :param path: the file path :param meta: the metadata

class bexchange.net.connections.connection_manager[source]

Bases: object

The connection manager is used for creating connection instances from the provided configuration

classmethod from_conf(backend, clz, arguments)[source]

Creates an instance of clz with specified arguments :param clz: class name specified as <module>.<classname> :param arguments: a list of arguments that should be used to initialize the class

class bexchange.net.connections.distributed_connection(backend, arguments)[source]

Bases: publisher_connection

Distributed connection, expects a list of senders in arguments. Where all senders are run. This is the same behavior as the backup connection but it’s here for readability.

publish(path, meta)[source]

Publishes a file in some way using the underlying implementation :param path: The path to the file :param meta: The metadata of the file

class bexchange.net.connections.failover_connection(backend, arguments)[source]

Bases: publisher_connection

Failover connection, expects a list of senders in arguments. Where they are tried in order until one works.

publish(path, meta)[source]

Publishes the file using the senders. When first successful publishing has successfully been transmitted, the method returns. If on the other hand no senders are successfully used an exception will be thrown. :param path: The path to the file :param meta: The metadata of the file

class bexchange.net.connections.publisher_connection(backend)[source]

Bases: object

publisher connections are used for publishing files in various ways without taking the protocol / sender into account. Each (or most) publisher_connection is associated with one or more senders.

backend()[source]

Returns the backend

publish(path, meta)[source]

Publishes a file in some way using the underlying implementation :param path: The path to the file :param meta: The metadata of the file

class bexchange.net.connections.simple_connection(backend, arguments)[source]

Bases: publisher_connection

Simple connection, only parsing arguments according to. sender class + arguments.

publish(path, meta)[source]

Publishes the file using the sender :param path: The path to the file :param meta: The metadata of the file

bexchange.net.fetchers module

class bexchange.net.fetchers.baseuri_fetcher(backend, aid, arguments)[source]

Bases: fetcher

Base class for fetching data using basic file transmission protocols like sftp, ftp, …

hostname()[source]

Returns the hostname extracted from the uri

password()[source]

:return the password

path()[source]

:return the path

port()[source]

Returns the port number extracted from the uri.

set_port(portno)[source]

Sets the portnumber :param portno: The portnumber to use

uri()[source]
username()[source]

:return the user name

class bexchange.net.fetchers.baseuri_patternmatching_fetcher(backend, aid, arguments)[source]

Bases: baseuri_fetcher

Base class for fetching data using basic file transmission protocols like sftp, ftp, …

fnpattern()[source]

Returns the fnpattern :return: the filename pattern, like *.h5

pattern()[source]

:return the regular expression matching pattern

pattern_matcher()[source]

:return the pattern matcher for the regular expression if there is one

class bexchange.net.fetchers.copy_fetcher(backend, aid, arguments)[source]

Bases: fetcher

Fetcher file(s) using copy

fetch(**kwargs)[source]

Fetches the file(s) using copy. :param file: path to file that should be published :param meta: the meta object for all metadata of file

pattern_matcher()[source]

:return the pattern matcher

class bexchange.net.fetchers.fetcher(backend, aid)[source]

Bases: object

Base fetcher. All classes implementing this should provide ability to fetch files in some way.

backend()[source]

Returns the server backend

abstract fetch(**kwargs)[source]

Fetches some files

id()[source]

Returns this fetcher id

class bexchange.net.fetchers.fetcher_manager[source]

Bases: object

Creates fetcher instances from a configuration entry

classmethod from_conf(backend, arguments)[source]

Creates an instance of clz with specified arguments :param arguments: a list of arguments that should be used to initialize the class

class bexchange.net.fetchers.ftp_fetcher(backend, aid, arguments)[source]

Bases: baseuri_patternmatching_fetcher

Fetcher file(s) using scp

connect()[source]
fetch(**kwargs)[source]

Fetches the file(s) using ftp. :param file: path to file that should be published :param meta: the meta object for all metadata of file

class bexchange.net.fetchers.scp_fetcher(backend, aid, arguments)[source]

Bases: baseuri_patternmatching_fetcher

Fetcher file(s) using scp

fetch(**kwargs)[source]

Fetches the file(s) using scp. :param file: path to file that should be published :param meta: the meta object for all metadata of file

class bexchange.net.fetchers.sftp_fetcher(backend, aid, arguments)[source]

Bases: baseuri_patternmatching_fetcher

Fetcher files using sftp

fetch(**kwargs)[source]

Fetches the file using sftp. :param file: path to file that should be published :param meta: the meta object for all metadata of file

bexchange.net.publishers module

class bexchange.net.publishers.pubQueue(qs)[source]

Bases: object

Wrapper around queue.Queue to be able to shutdown. This will be supported in python 3.13 but for now this will be enough.

get(waittime=10)[source]

Returns an item from the queue. The wait time is the time in seconds the thread should wait in the condition until checking for any new item in the queue. This condition will be notified whenever put or shutdown is called. :param waittime: The time to wait in seconds inside the condition :return: Will always return an item :throws: pubQueueShutdown

put(item)[source]

Puts an item into the queue without blocking. If queue is shutdown, the item will not be added to the queue and this will be done silently :param item: the item to add to the queue

shutdown()[source]

Shuts down the queue.

task_done()[source]

Call this when task grabbed from queue is finished

exception bexchange.net.publishers.pubQueueShutdown[source]

Bases: Exception

thrown to indicate that an entry already exists

class bexchange.net.publishers.publisher(backend, name, active, origin, ifilter, connections, decorators)[source]

Bases: object

Base class used by all publishers

active()[source]

Returns if this publication is active or not :return: if this publication is active or not

backend()[source]

Returns the backend :return: the backend

connections()[source]

Returns the connection(s) :return: the connection(s)

decorators()[source]

Returns the decorator(s) :return: the decorator(s)

filter()[source]

Returns the filter :return: the filter

initialize()[source]

Initializes the publisher before it is started.

name()[source]

Returns the name :return: the name

origin()[source]

:return the list of origins that should trigger this publication

publish(file, meta)[source]

publishes a file

Parameters:
  • file – The temp file instance

  • meta – The metadata

Returns:

metadata extracted from the file

start()[source]

A publisher should most likely be managing threads and as such a start method is needed

stop()[source]

A publisher should most likely be managing threads and as such a stop method is needed joining the threads

class bexchange.net.publishers.publisher_manager[source]

Bases: object

The manager used for creating publishers from configuration

classmethod create_publisher(name, clz, backend, active, origin, filter, connections, decorators, extra_arguments)[source]

Creates an instance of clz with specified arguments :param clz: class name specified as <module>.<classname> :param arguments: a list of arguments that should be used to initialize the class

classmethod from_conf(config, backend)[source]

Creates the publisher instance from provided configuration. :param config: The json config in a dict :param backend: The backend the publisher shall have access to :return: the created publisher

class bexchange.net.publishers.standard_publisher(backend, name, active, origin, ifilter, connections, decorators, extra_arguments)[source]

Bases: publisher

Standard publisher used for most situations. Provides two arguments. One is threads. The other is queue_size.

consumer()[source]

The consumer called by the individual threads. Will grab one entry from the queue and pass it on to the connections.

do_publish(tmpfile, meta)[source]

Passes a file to all connections

handle_consumer_file(tmpfile, meta)[source]

Will handle the file that the consumer retrieved from the queue :param self: self :param tmpfile: the tmp file :param meta: the meta data

initialize()[source]

Initializes the publisher before it is started.

publish(file, meta)[source]

Passes on a file to the consumer queue that will be consumed and passed on to the connections. :param file: Actual file to be duplicated and sent. :param meta: The metadata to be verified by the connections

start()[source]

Starts all consumer threads as daemon threads

stop()[source]

Joins the threads

bexchange.net.senders module

class bexchange.net.senders.baseuri_sender(backend, aid, arguments)[source]

Bases: sender

Base class for basic file transmission protocols like sftp, ftp, …

create_missing_directories()[source]

Returns if missing directories should be created or not

hostname()[source]

Returns the hostname extracted from the uri

name(meta)[source]

Creates a unique name from the metadatanamer created from the uri :param meta: Metadata to use when creating the name

password()[source]
port()[source]

Returns the port number extracted from the uri.

username()[source]
class bexchange.net.senders.copy_sender(backend, aid, arguments)[source]

Bases: sender

Sends files by copying them

create_missing_directories()[source]
Returns:

if missing directories should be created or not

name(meta)[source]

Creates the name to use when copying the file from the metadata :param meta: The metadata :return: the name to use for destination

send(path, meta)[source]

Sends the file using copy. :param file: path to file that should be sent :param meta: the meta object for all metadata of file

class bexchange.net.senders.dex_sender(backend, aid, arguments)[source]

Bases: sender

Legacy DEX communication sending files to old nodes.

send(path, meta)[source]

Sends the file to the dex server :param file: path to file that should be sent :param meta: the meta object for all metadata of file

class bexchange.net.senders.ftp_sender(backend, aid, arguments)[source]

Bases: baseuri_sender

Publishes files over ftp

change_and_create_dir(ftp, path)[source]

Changes directory and creates specified directory. :param ftp: The ftp connection :param path: The path to create

connect()[source]

Connects to the host specified by host / port. :return: the ftp connection

does_dir_exist(ftp, path)[source]

Tests if the specified directory exist using the provided ftp-connection :param ftp: the ftp connection :param path: the path to test :return: True or False

send(path, meta)[source]

Sends the file using ftp. :param file: path to file that should be published :param meta: the meta object for all metadata of file

class bexchange.net.senders.rest_sender(backend, aid, arguments)[source]

Bases: sender

Sends a file to another node that is running bexchange. The rest sender uses the internal crypto library for signing messages which currently supports DSA & RSA keys. DSA uses DSS, RSA uses pkcs1_15.

send(path, meta)[source]

Sends the file to the bexchange server :param file: path to file that should be sent :param meta: the meta object for all metadata of file

class bexchange.net.senders.scp_sender(backend, aid, arguments)[source]

Bases: baseuri_sender

Publishes files over scp

send(path, meta)[source]

Sends the file using scp. :param file: path to file that should be sent :param meta: the meta object for all metadata of file

class bexchange.net.senders.sender(backend, aid)[source]

Bases: object

Base sender. All classes implementing this should send the specified file path to a recipient over a specific protocol.

backend()[source]

Returns the server backend

id()[source]

Returns this uploader id

abstract send(path, meta)[source]

Sends path with the metadata meta :param path: Path to file to be uploaded :param meta: Metadata of the uploaded file

class bexchange.net.senders.sender_manager[source]

Bases: object

classmethod from_conf(backend, arguments)[source]

Creates an instance of clz with specified arguments :param arguments: a list of arguments that should be used to initialize the class

class bexchange.net.senders.sftp_sender(backend, aid, arguments)[source]

Bases: baseuri_sender

Sends files over sftp

send(path, meta)[source]

Sends the file using sftp. :param file: path to file that should be sent :param meta: the meta object for all metadata of file

class bexchange.net.senders.storage_sender(backend, aid, arguments)[source]

Bases: sender

Sends files using a number of storages.

send(file, meta)[source]

Sends the file on all storages associated with self :param file: path to file that should be sent :param meta: the meta object for all metadata of file

bexchange.net.sftpclient module

class bexchange.net.sftpclient.sftpclient(host, port, username, password, timeout=30.0, banner_timeout=30)[source]

Bases: object

Implementation of a sftpclient using paramiko

chdir(dirname)[source]

Changes current directory on server :param dirname: The directory to change to

connect()[source]

(Re)connects to the sftp server

disconnect()[source]

Disconnects from the sftp server

get(filename, targetname)[source]

Fetches the file (filename) from the server and saves it as targetname. :param filename: Source filename to download :param targetname: The destination name to save as

getfo(remotepath, fl)[source]

Copies the file (remotepath) from the server and writes to an open file. Typically used like: with NamedTemporaryFile() as fp: c.getfo(”….”, fp)

Parameters:
  • remotepath – Source filename to download

  • fl – The destination file object

hostname()[source]

:return the hostname

isdir(path)[source]

Checks if the provided path is a directory or not

Parameters:

path – Path name to check

Returns:

if specified path is a dir or not

isfile(path)[source]
Parameters:

path – Path name to check

Returns:

if specified path is a file or not

listdir(dirname)[source]

Lists files and directories in the directory :param dirname: The directory to list :return a list of names

makedirs(targetdir)[source]

Creates the directories if they don’t exist :param targetdir: The structure to create from current wd

password()[source]

:return the password

port()[source]

:return the port number

put(filename, targetname, confirm=True)[source]

Uploads the file (filename) to the server named targetname. :param filename: Source filename to upload :param targetname: The destination name

username()[source]

:return the username

Module contents