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:
JobBaseAdd torrent(s) to a BitTorrent client
This job adds the following signals to
signal:addingEmitted when attempting to add a torrent. Registered callbacks get the path to the torrent file as a positional argument.
addedEmitted when the torrent was added successfully. Registered callbacks get the added torrent’s info hash as a positional argument.
- cache_id = None
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_config –
BtclientConfiginstancetorrent_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_pathandPathTranslations.
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 toadd_task().Any keyword arguments passed to
initialize()are available viakwargs.The job
is_finishedwhen alladded tasksare done or cancelled. (See alsofinalize()andfinalization().)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:
JobBaseCopy file(s)
This job adds the following signals to
signal:copyingEmitted when attempting to copy a file. Registered callbacks get the source file path as a positional argument.
copiedEmitted 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
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 toadd_task().Any keyword arguments passed to
initialize()are available viakwargs.The job
is_finishedwhen alladded tasksare done or cancelled. (See alsofinalize()andfinalization().)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:
JobBaseCreate torrent file
This job adds the following signals to
signal:announce_urlEmitted before and after successful announce URL retrieval. Registered callbacks get an
Ellipsisto indicate the retrieval attempt and the announce URL if the attempt was successful.file_treeEmitted when torrent creation begins. Registered callbacks get nested (file_name, file_size) tuples (see
create()) as a positional argument. (See alsofs.format_file_tree().)file_listEmitted when torrent creation begins. Registered callbacks get a
listof paths to existing files that are in the torrent as a positional argument.progress_updateEmitted at roughly equal intervals to provide information about the torrent creation progress. Registered callbacks get a
CreateTorrentProgressorFindTorrentProgressinstance 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) andre.Patternobjects (return value fromre.compile()) that are matched against the relative path within the generated torrentGlob 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 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