upsies.jobs.torrent

Create torrent file

Classes

class upsies.jobs.torrent.AddTorrentJob(*, home_directory=None, cache_directory=None, cache_id='', ignore_cache=False, no_output_is_ok=False, hidden=False, autostart=True, guaranteed=False, precondition=None, prejobs=(), callbacks={}, **kwargs)[source]

Bases: JobBase

Add torrent(s) to a BitTorrent client

This job adds the following signals to signal:

adding

Emitted when attempting to add a torrent. Registered callbacks get the path to the torrent file as a positional argument.

added

Emitted when the torrent was added successfully. Registered callbacks get the added torrent’s info hash as a positional argument.

cache_id = None
property hidden

True while this job is not started (i.e. waiting for a torrent to add), then False

initialize(*, btclient_config, torrent_files=(), download_path=None)[source]

Set internal state

Parameters:
  • btclient_configBtclientConfig instance

  • torrent_files – Sequence of torrent file paths to add

  • download_path

    Download directory of each torrent’s files

    This path is translated from a path on the computer that runs this code to a path on the BitTorrent client computer. See translate_path and PathTranslations.

After all torrent_files are added, if a job named “torrent” exists, receive_all() torrents from that job and add them too.

async run()[source]

Do the work

This method is called by start(). Its coroutine is passed to add_task().

Any keyword arguments passed to initialize() are available via kwargs.

The job is_finished when all added tasks are done or cancelled. (See also finalize() and finalization().)

This method may call add_task() if more tasks are required.

class upsies.jobs.torrent.CopyTorrentJob(*, home_directory=None, cache_directory=None, cache_id='', ignore_cache=False, no_output_is_ok=False, hidden=False, autostart=True, guaranteed=False, precondition=None, prejobs=(), callbacks={}, **kwargs)[source]

Bases: JobBase

Copy file(s)

This job adds the following signals to signal:

copying

Emitted when attempting to copy a file. Registered callbacks get the source file path as a positional argument.

copied

Emitted when the copy attempt ended. Registered callbacks get the destination file path (success) or the source file path (failure) as a positional argument.

cache_id = None
property hidden

True while this job is not started (i.e. waiting for a torrent to add), then False

initialize(*, destination, torrent_files=())[source]

Set internal state

Parameters:
  • destination – Where to put the torrent(s)

  • torrent_files – Sequence of torrent file paths to copy to destination

After all torrent_files are copied, if a job named “torrent” exists, receive_all() torrents from that job and copy them too.

async run()[source]

Do the work

This method is called by start(). Its coroutine is passed to add_task().

Any keyword arguments passed to initialize() are available via kwargs.

The job is_finished when all added tasks are done or cancelled. (See also finalize() and finalization().)

This method may call add_task() if more tasks are required.

MAX_FILE_SIZE = 10485760

Upper limit of acceptable file size

class upsies.jobs.torrent.CreateTorrentJob(*, home_directory=None, cache_directory=None, cache_id='', ignore_cache=False, no_output_is_ok=False, hidden=False, autostart=True, guaranteed=False, precondition=None, prejobs=(), callbacks={}, **kwargs)[source]

Bases: JobBase

Create torrent file

This job adds the following signals to signal:

announce_url

Emitted before and after successful announce URL retrieval. Registered callbacks get an Ellipsis to indicate the retrieval attempt and the announce URL if the attempt was successful.

file_tree

Emitted when torrent creation begins. Registered callbacks get nested (file_name, file_size) tuples (see create()) as a positional argument. (See also fs.format_file_tree().)

file_list

Emitted when torrent creation begins. Registered callbacks get a list of paths to existing files that are in the torrent as a positional argument.

progress_update

Emitted at roughly equal intervals to provide information about the torrent creation progress. Registered callbacks get a CreateTorrentProgress or FindTorrentProgress instance as a positional argument.

cache_id = None
initialize(*, tracker, content_path, exclude_files=(), reuse_torrent_path=None)[source]

Set internal state

Parameters:
  • tracker (TrackerBase) – Return value of trackers.tracker()

  • content_path – Path to file or directory

  • reuse_torrent_path – Path to existing torrent file to reuse piece hashes from (see create())

  • exclude_files

    Sequence of glob patterns (str) and re.Pattern objects (return value from re.compile()) that are matched against the relative path within the generated torrent

    Glob patterns are matched case-insensitively.

    Note

    This sequence is combined with TrackerBase.options["exclude"].

property activity

What is currently being done

"announce_url"

If we are getting the announce URL.

"hashing"

If we are hashing files.

"searching"

If we are searching for a torrent we can copy hashes from.

"verifying"

If we are hash-checking a potentially matching torrent.

""

None of the above is happening (e.g. we are getting the file tree).

async run()[source]

Get announce URL from tracker, then execute torrent creation subprocess

async download_torrent(url)[source]

Download torrent file and replace our own torrent

Some trackers make unpredictable modifications to our torrent file, changing the info hash and forcing us to download their version. In that case, this method can be called to overwrite our torrent file with the altered version from the tracker.

Important

This method must only be called AFTER this job is finished.

Raises:

errors.RequestError – if downloading or writing file fails

terminate(reason=None)[source]

Terminate torrent creation subprocess and all tasks

Stop searching for a torrent we can copy hashes from

If we are not currently searching for a torrent, do nothing.