-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add path filter for Transmission (#145)
- Loading branch information
Showing
7 changed files
with
278 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#-*- coding:utf-8 -*- | ||
|
||
from .filter import Filter | ||
|
||
class PathFilter(Filter): | ||
def __init__(self, all_paths, ac, re): | ||
''' | ||
filter torrents by path (download directory) | ||
Parameters: | ||
all_paths (boolean): whether accept all paths | ||
ac (list): accept paths | ||
re (list): reject paths | ||
''' | ||
Filter.__init__(self, all_paths, ac, re) | ||
|
||
def apply(self, torrents): | ||
# Pick accepted torrents | ||
accepts = set() | ||
if self._all: # Accept all torrents (all_paths) | ||
accepts = set(torrents) | ||
elif len(self._accept) > 0: # Accept specific path torrents (paths) | ||
for torrent in torrents: | ||
path = torrent.download_dir | ||
if any(map(path.startswith, self._accept)) or path == '': | ||
accepts.add(torrent) | ||
# Pick rejected torrents | ||
rejects = set() | ||
if len(self._reject) > 0: # Reject specific path torrents (excluded_paths) | ||
for torrent in accepts: | ||
path = torrent.download_dir | ||
if any(map(path.startswith, self._reject)): | ||
rejects.add(torrent) | ||
return accepts.difference(rejects) # Return their difference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ pytest-cov | |
codacy-coverage | ||
requests_mock | ||
pytest-mock | ||
setuptools | ||
setuptools | ||
sphinx | ||
sphinx_rtd_theme | ||
sphinx-intl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.