Skip to content

Commit

Permalink
Address some performance concerns, clean up style
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Feb 21, 2014
1 parent aa74e6c commit 70afcd9
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions seedtime/deluge/plugins/seedtime/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"default_stop_time": 7,
"apply_stop_time": False,
"remove_torrent": False,
"torrent_stop_times":{} # torrent_id: stop_time (in hours)
"torrent_stop_times": {} # torrent_id: stop_time (in hours)
}

class Core(CorePluginBase):
Expand All @@ -71,8 +71,8 @@ def enable(self):
deferLater(reactor, 5, self.start_looping)

def start_looping(self):
log.warning('seedtime loop starting')
self.looping_call.start(5)
log.debug("seedtime loop starting")
self.looping_call.start(10)

def disable(self):
self.plugin.deregister_status_field("seed_stop_time")
Expand All @@ -85,13 +85,11 @@ def update(self):
def update_checker(self):
"""Check if any torrents have reached their stop seed time."""
for torrent in component.get("Core").torrentmanager.torrents.values():
if not torrent.torrent_id in self.torrent_stop_times:
if not (torrent.state == "Seeding" and torrent.torrent_id in self.torrent_stop_times):
continue
stop_time = self.torrent_stop_times[torrent.torrent_id]
log.debug('seedtime stop time %s' % stop_time)
log.debug('seedtime torrent seeding time %r' % torrent.get_status(['seeding_time']))
if torrent.get_status(['seeding_time'])['seeding_time'] > stop_time * 3600.0 * 24.0:
if self.config['remove_torrent']:
if torrent.get_status(["seeding_time"])["seeding_time"] > stop_time * 3600.0 * 24.0:
if self.config["remove_torrent"]:
self.torrent_manager.remove(torrent.torrent_id)
else:
torrent.pause()
Expand All @@ -100,22 +98,19 @@ def update_checker(self):
def post_torrent_add(self, torrent_id):
if not self.torrent_manager.session_started:
return
log.debug("seedtime post_torrent_add")
if self.config["apply_stop_time"]:
log.debug('applying stop.... time %r' % self.config['default_stop_time'])
log.debug("applying stop.... time %r" % self.config["default_stop_time"])
self.set_torrent(torrent_id, self.config["default_stop_time"])


def post_torrent_remove(self, torrent_id):
log.debug("seedtime post_torrent_remove")
if torrent_id in self.torrent_stop_times:
del self.torrent_stop_times[torrent_id]

@export
def set_config(self, config):
"""Sets the config dictionary"""
log.debug('seedtime %r' % config)
log.debug('component state %r, component timer %r' % (self._component_state, self._component_timer))
log.debug("seedtime %r" % config)
log.debug("component state %r, component timer %r" % (self._component_state, self._component_timer))
for key in config.keys():
self.config[key] = config[key]
self.config.save()
Expand All @@ -126,7 +121,7 @@ def get_config(self):
return self.config.config

@export
def set_torrent(self, torrent_id , stop_time):
def set_torrent(self, torrent_id, stop_time):
if stop_time is None:
del self.torrent_stop_times[torrent_id]
else:
Expand Down

0 comments on commit 70afcd9

Please sign in to comment.