diff options
Diffstat (limited to 'module/plugins/hooks/DownloadScheduler.py')
| -rw-r--r-- | module/plugins/hooks/DownloadScheduler.py | 51 | 
1 files changed, 24 insertions, 27 deletions
diff --git a/module/plugins/hooks/DownloadScheduler.py b/module/plugins/hooks/DownloadScheduler.py index 41a20e5d1..4996e212d 100644 --- a/module/plugins/hooks/DownloadScheduler.py +++ b/module/plugins/hooks/DownloadScheduler.py @@ -1,44 +1,40 @@  # -*- coding: utf-8 -*- -""" -    This program is free software; you can redistribute it and/or modify -    it under the terms of the GNU General Public License as published by -    the Free Software Foundation; either version 3 of the License, -    or (at your option) any later version. - -    This program is distributed in the hope that it will be useful, -    but WITHOUT ANY WARRANTY; without even the implied warranty of -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -    You should have received a copy of the GNU General Public License -    along with this program; if not, see <http://www.gnu.org/licenses/>. - -    @author: zoidberg -    Original idea by new.cze -""" -  import re +  from time import localtime  from module.plugins.Hook import Hook  class DownloadScheduler(Hook): -    __name__ = "DownloadScheduler" -    __version__ = "0.21" -    __description__ = """Download Scheduler""" -    __config__ = [("activated", "bool", "Activated", False), -                  ("timetable", "str", "List time periods as hh:mm full or number(kB/s)", +    __name__    = "DownloadScheduler" +    __type__    = "hook" +    __version__ = "0.22" + +    __config__ = [("timetable", "str", "List time periods as hh:mm full or number(kB/s)",                     "0:00 full, 7:00 250, 10:00 0, 17:00 150"),                    ("abort", "bool", "Abort active downloads when start period with speed 0", False)] -    __author_name__ = ("zoidberg", "stickell") -    __author_mail__ = ("zoidberg@mujmail.cz", "l.stickell@yahoo.it") + +    __description__ = """Download Scheduler""" +    __license__     = "GPLv3" +    __authors__     = [("zoidberg", "zoidberg@mujmail.cz"), +                       ("stickell", "l.stickell@yahoo.it")] + + +    #@TODO: Remove in 0.4.10 +    def initPeriodical(self): +        pass +      def setup(self):          self.cb = None  # callback to scheduler job; will be by removed hookmanager when hook unloaded +      def coreReady(self):          self.updateSchedule() +      def updateSchedule(self, schedule=None):          if schedule is None:              schedule = self.getConfig("timetable") @@ -46,7 +42,7 @@ class DownloadScheduler(Hook):          schedule = re.findall("(\d{1,2}):(\d{2})[\s]*(-?\d+)",                                schedule.lower().replace("full", "-1").replace("none", "0"))          if not schedule: -            self.logError("Invalid schedule") +            self.logError(_("Invalid schedule"))              return          t0 = localtime() @@ -66,10 +62,11 @@ class DownloadScheduler(Hook):                  self.core.scheduler.removeJob(self.cb)                  self.cb = self.core.scheduler.addJob(next_time, self.updateSchedule, threaded=False) +      def setDownloadSpeed(self, speed):          if speed == 0:              abort = self.getConfig("abort") -            self.logInfo("Stopping download server. (Running downloads will %sbe aborted.)" % ('' if abort else 'not ')) +            self.logInfo(_("Stopping download server. (Running downloads will %sbe aborted.)") % '' if abort else _('not '))              self.core.api.pauseServer()              if abort:                  self.core.api.stopAllDownloads() @@ -77,10 +74,10 @@ class DownloadScheduler(Hook):              self.core.api.unpauseServer()              if speed > 0: -                self.logInfo("Setting download speed to %d kB/s" % speed) +                self.logInfo(_("Setting download speed to %d kB/s") % speed)                  self.core.api.setConfigValue("download", "limit_speed", 1)                  self.core.api.setConfigValue("download", "max_speed", speed)              else: -                self.logInfo("Setting download speed to FULL") +                self.logInfo(_("Setting download speed to FULL"))                  self.core.api.setConfigValue("download", "limit_speed", 0)                  self.core.api.setConfigValue("download", "max_speed", -1)  | 
