Skip to content

Commit 8268465

Browse files
Merge branch 'dev'
2 parents f641616 + 25958f2 commit 8268465

9 files changed

Lines changed: 87 additions & 17 deletions

File tree

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
language: python
22
python:
3-
- "3.3"
43
- "3.4"
54
- "3.5"
65
- "3.6"
7-
- "3.6-dev" # Python 3.6 development branch
6+
- "3.7"
7+
dist: xenial
8+
sudo: true
89
# Command to install dependencies
910
install:
1011
- pip install requests pyyaml enum34
11-
- pip install pytest pytest-cov codacy-coverage
12+
- pip install --upgrade pytest
13+
- pip install pytest-cov codacy-coverage
1214
- pip install setuptools
1315
# Command to run tests
1416
script:
15-
- py.test --cov-report=xml --cov=./
17+
- py.test -s --cov-report=xml --cov
1618
- python setup.py install
1719
- autoremove-torrents -c pytest/test_main/config.yml -v
1820
# Command after success

README.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ Screenshot
103103

104104
Changelog
105105
----------
106+
**Mon, 10 Jan 2019**: Version 1.2.5.
107+
108+
* Fixed bug: Incorrect number of torrents in multiple strategies (`Issue #10 <https://github.com/jerrymakesjelly/autoremove-torrents/issues/10>`_, thanks to @momokoo for the report and PR).
109+
* Fixed bug: Incorrect number of torrents in qBittorrent (`Issue #13 <https://github.com/jerrymakesjelly/autoremove-torrents/issues/13>`_).
110+
106111
**Thu, 31 May 2018**: Version 1.2.4.
107112

108113
* Fixed startup failure.
@@ -143,7 +148,7 @@ Depend on users' feedback.
143148

144149
* Add remove condition: Max/Min average UL/DL speed
145150

146-
If you have any problem, please submit `Issues`_.
151+
If you have any problem, please submit `issues`_.
147152

148-
.. _Issues: https://github.com/jerrymakesjelly/autoremove-torrents/issues
153+
.. _issues: https://github.com/jerrymakesjelly/autoremove-torrents/issues
149154

autoremovetorrents/filter/tracker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def apply(self, torrents):
1313
for tracker in torrent.tracker: # For each tracker
1414
tracker = urllib.parse.urlparse(tracker).netloc
1515
if self._all or tracker in self._accept:
16-
result.append(torrent)
16+
if torrent not in result:
17+
result.append(torrent)
1718
if tracker in self._reject:
1819
result.remove(torrent)
1920
break # Reject this seed

autoremovetorrents/strategy.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ def _apply_filters(self):
4242
{'all':self._all_trackers, 'ac':'trackers', 're':'excluded_trackers'}, # Tracker filter
4343
{'all':self._all_status, 'ac':'status', 're':'excluded_status'} # Status filter
4444
]
45+
filter_name = ['Category', 'Tracker', 'Status']
4546
filter_obj = [CategoryFilter, TrackerFilter, StatusFilter]
4647
for i in range(0, len(filter_conf)):
48+
# Logging
49+
self._logger.debug('Filter `%s` is working to process %d torrent(s): Accept All: %s, Accept: %s, Reject: %s.' \
50+
% (
51+
filter_name[i],
52+
len(self.remain_list),
53+
'Yes' if filter_conf[i]['all'] else 'No',
54+
str(len(self._conf[filter_conf[i]['ac']])) if filter_conf[i]['ac'] in self._conf else 'Not Specified',
55+
str(len(self._conf[filter_conf[i]['re']])) if filter_conf[i]['re'] in self._conf else 'Not Specified',
56+
))
4757
# Apply each filter
4858
self.remain_list = filter_obj[i](
4959
filter_conf[i]['all'],
@@ -65,15 +75,26 @@ def _apply_conditions(self):
6575
for i in range(0, len(condition_field)):
6676
# Apply each condition
6777
if condition_field[i] in self._conf:
78+
# Logging
79+
self._logger.debug('Remove condition `%s` was specified to process %d torrent(s).' \
80+
% (condition_field[i], len(self.remain_list)))
81+
# Applying condition processor
6882
cond = condition_obj[i](self._conf[condition_field[i]])
6983
cond.apply(self.remain_list)
84+
# Logging
85+
self._logger.debug('The following %d torrent(s) would be remained.' % len(cond.remain))
86+
for torrent in cond.remain:
87+
self._logger.debug(torrent)
88+
self._logger.debug('The follwing %d torrent(s) would be removed.' % len(cond.remove))
89+
for torrent in cond.remove:
90+
self._logger.debug(torrent)
91+
# Output
7092
self.remain_list = cond.remain
7193
self.remove_list.extend(cond.remove)
7294

7395
# Execute this strategy
7496
def execute(self, torrents):
7597
self._logger.info('Running strategy %s...' % self._name)
76-
7798
self.remain_list = torrents
7899
# Apply Filters
79100
self._apply_filters()
@@ -86,7 +107,7 @@ def execute(self, torrents):
86107
self._logger.info('To be deleted:')
87108
for torrent in self.remove_list:
88109
self._logger.info(torrent)
89-
#self._logger.info('To be remained:')
110+
#self._logger.debug('To be remained:')
90111
#for torrent in self.remain_list:
91-
# self._logger.info(torrent)
112+
# self._logger.debug(torrent)
92113
#return self.remove_list

autoremovetorrents/task.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ def _get_torrents(self):
9696
# Apply strategies
9797
def _apply_strategies(self):
9898
for strategy_name in self._strategies:
99+
self._logger.debug('Strategy `%s` was specified to process %d torrent(s).' \
100+
% (strategy_name, len(self._torrents)))
99101
strategy = Strategy(strategy_name, self._strategies[strategy_name])
100102
strategy.execute(self._torrents)
101-
self._torrents = strategy.remain_list
102103
self._remove.extend(strategy.remove_list)
103104

104105
# Remove torrents
@@ -119,3 +120,11 @@ def execute(self):
119120
self._apply_strategies()
120121
if self._enabled_remove:
121122
self._remove_torrents()
123+
124+
# Get remaining torrents (for tester)
125+
def get_remaining_torrents(self):
126+
return self._torrents
127+
128+
# Get removed torrents (for tester)
129+
def get_removed_torrents(self):
130+
return self._remove

pytest/test_tasks/cases/test_qbittorrent.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@ task:
55
password: $(QBITTORRENT_PASSWORD)
66
delete_data: true
77
strategies:
8-
test_strategies:
9-
nothing: true
8+
strategy_1:
9+
categories:
10+
- cata1
11+
ratio: 0.009
12+
strategy_2:
13+
categories:
14+
- cata2
15+
seeding_time: 86400
16+
view: true
17+
result:
18+
num-of-remaining: 0
19+
num-of-removed: QBITTORRENT_TORRENT_NUM

pytest/test_tasks/cases/test_transmission.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ task:
55
delete_data: true
66
strategies:
77
test_strategies:
8-
nothing: true
8+
create_time: 86400
9+
view: true
10+
result:
11+
num-of-remaining: 0
12+
num-of-removed: TRANSMISSION_TORRENT_NUM

pytest/test_tasks/cases/test_utorrent.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ task:
33
host: $(UTORRENT_HOST)
44
username: $(UTORRENT_USERNAME)
55
password: $(UTORRENT_PASSWORD)
6+
view: true
7+
result:
8+
num-of-remaining: UTORRENT_TORRENT_NUM
9+
num-of-removed: 0

pytest/test_tasks/test_tasks.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,28 @@ def test_task(env_dist):
3636
lg.info('Loading file: %s' % file)
3737
with open(file_path, encoding='utf-8') as f:
3838
conf = yaml.safe_load(f)
39+
# Replace system environment variables
40+
keys = ['num-of-remaining', 'num-of-removed']
41+
if 'result' in conf:
42+
for key in keys:
43+
if key in conf['result'] and isinstance(conf['result'][key], str) \
44+
and conf['result'][key] in env_dist:
45+
conf['result'][key] = env_dist[conf['result'][key]]
3946

4047
# Make take and run
4148
try:
42-
task = Task(file, conf['task'])
49+
if 'view' in conf:
50+
task = Task(file, conf['task'], not conf['view'])
51+
else:
52+
task = Task(file, conf['task'])
4353
task.execute()
4454
if 'exceptions' in conf and len(conf['exceptions']) > 0:
4555
raise AssertionError("It didn't raise exceptions as expected")
46-
except Exception:
56+
if 'result' in conf:
57+
if len(task.get_removed_torrents()) != int(conf['result']['num-of-removed']):
58+
raise AssertionError('The actual number of removed seeds does not match the assumption: %d != %d.' \
59+
% (len(task.get_remaining_torrents()), int(conf['result']['num-of-removed'])))
60+
except Exception as e:
4761
# Check if the excpetion is expected
4862
found = False
4963
for e in exception_map:
@@ -53,4 +67,4 @@ def test_task(env_dist):
5367
found = True
5468
break # An expected exception
5569
if not found:
56-
raise AssertionError() # Unexpected exception
70+
raise e # Unexpected exception

0 commit comments

Comments
 (0)