コード例 #1
0
    def test_ttl_value_updated(self):
        config = get_test_config()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.common.get_resource(
            common.testdata_rssfeed_filename, path="tests")

        yarss_config = common.get_empty_test_config()
        yarss_config.set_config(config)

        timer = RSSFeedTimer(yarss_config, log)
        timer.enable_timers()

        def add_torrents_pass(*arg):
            pass

        timer.add_torrent_func = add_torrents_pass

        # Run the rssfeed with key 0
        timer.rssfeed_update_handler("0")

        # Verify that update_interval of rssfeed in config was updated
        self.assertEquals(
            yarss_config.get_config()["rssfeeds"]["0"]["update_interval"], 60)

        # Verify that update_interval of the timer was updated
        self.assertEquals(timer.rssfeed_timers["0"]["update_interval"], 60)
        timer.disable_timers()
コード例 #2
0
    def test_ttl_value_updated(self):
        config = get_test_config()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.common.get_resource(common.testdata_rssfeed_filename, path="tests")

        yarss_config = common.get_empty_test_config()
        yarss_config.set_config(config)

        timer = RSSFeedTimer(yarss_config, log)
        timer.enable_timers()

        def add_torrents_pass(*arg):
            pass
        timer.add_torrent_func = add_torrents_pass

        # Run the rssfeed with key 0
        timer.rssfeed_update_handler("0")

        # Verify that update_interval of rssfeed in config was updated
        self.assertEquals(yarss_config.get_config()["rssfeeds"]["0"]["update_interval"], 60)

        # Verify that update_interval of the timer was updated
        self.assertEquals(timer.rssfeed_timers["0"]["update_interval"], 60)
        timer.disable_timers()
コード例 #3
0
    def test_rssfeed_update_handler(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        subscription = yarss2.yarss_config.get_fresh_subscription_config(
            rssfeed_key="0", key="0")
        self.config.set_config({"subscriptions": {"0": subscription}})

        # Check that last_update changes
        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the rssfeed with key 0
        timer.rssfeed_update_handler("0")
        self.assertNotEquals(old_last_update,
                             self.rssfeeds["0"]["last_update"])

        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the subscription with key 0 like when the user runs it manually
        timer.rssfeed_update_handler(None, "0")

        # last_update should not have changed
        self.assertEquals(old_last_update, self.rssfeeds["0"]["last_update"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #4
0
    def test_interval_unchanged(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Set timer 0 with same interval
        self.assertFalse(timer.set_timer("0", 1))

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #5
0
    def test_interval_unchanged(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Set timer 0 with same interval
        self.assertFalse(timer.set_timer("0", 1))

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #6
0
    def test_disable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        timer.disable_timers()

        # Now verify that the timers have been stopped
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertFalse(timer.rssfeed_timers[key]["timer"].running)
コード例 #7
0
    def test_disable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        timer.disable_timers()

        # Now verify that the timers have been stopped
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertFalse(timer.rssfeed_timers[key]["timer"].running)
コード例 #8
0
    def test_delete_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Delete timer
        self.assertTrue(timer.delete_timer("0"))
        self.assertFalse(timer.delete_timer("-1"))

        self.assertEquals(len(timer.rssfeed_timers.keys()), 4)
        self.assertFalse(timer.rssfeed_timers.has_key("0"))
        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #9
0
    def test_delete_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Delete timer
        self.assertTrue(timer.delete_timer("0"))
        self.assertFalse(timer.delete_timer("-1"))

        self.assertEquals(len(timer.rssfeed_timers.keys()), 4)
        self.assertFalse(timer.rssfeed_timers.has_key("0"))
        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #10
0
    def test_reschedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Change interval to 60 minutes
        self.assertTrue(timer.set_timer("0", 60))

        interval = timer.rssfeed_timers["0"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["0"]["update_interval"], 60)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #11
0
    def test_reschedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Change interval to 60 minutes
        self.assertTrue(timer.set_timer("0", 60))

        interval = timer.rssfeed_timers["0"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["0"]["update_interval"], 60)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #12
0
    def test_enable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Now verify the timers
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertTrue(timer.rssfeed_timers[key]["timer"].running)

            # Does the timer have the correct interval?
            interval = timer.rssfeed_timers[key]["timer"].interval
            self.assertEquals(self.rssfeeds[key]["update_interval"] * 60, interval)
            self.assertEquals(self.rssfeeds[key]["update_interval"], timer.rssfeed_timers[key]["update_interval"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #13
0
    def test_schedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Add new timer (with key "5") with interval 60 minutes
        self.assertTrue(timer.set_timer("5", 60))

        # Verify timer values
        interval = timer.rssfeed_timers["5"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["5"]["update_interval"], 60)

        # Should now be 6 timers
        self.assertEquals(len(timer.rssfeed_timers.keys()), 6)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #14
0
    def test_schedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Add new timer (with key "5") with interval 60 minutes
        self.assertTrue(timer.set_timer("5", 60))

        # Verify timer values
        interval = timer.rssfeed_timers["5"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["5"]["update_interval"], 60)

        # Should now be 6 timers
        self.assertEquals(len(timer.rssfeed_timers.keys()), 6)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #15
0
    def test_enable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Now verify the timers
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertTrue(timer.rssfeed_timers[key]["timer"].running)

            # Does the timer have the correct interval?
            interval = timer.rssfeed_timers[key]["timer"].interval
            self.assertEquals(self.rssfeeds[key]["update_interval"] * 60,
                              interval)
            self.assertEquals(self.rssfeeds[key]["update_interval"],
                              timer.rssfeed_timers[key]["update_interval"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #16
0
    def test_rssfeed_update_handler(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        subscription = yarss2.yarss_config.get_fresh_subscription_config(rssfeed_key="0", key="0")
        self.config.set_config({"subscriptions": {"0": subscription} })

        # Check that last_update changes
        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the rssfeed with key 0
        timer.rssfeed_update_handler("0")
        self.assertNotEquals(old_last_update, self.rssfeeds["0"]["last_update"])

        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the subscription with key 0 like when the user runs it manually
        timer.rssfeed_update_handler(None, "0")

        # last_update should not have changed
        self.assertEquals(old_last_update, self.rssfeeds["0"]["last_update"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
コード例 #17
0
class Core(CorePluginBase):
    def enable(self, config=None):
        self.log = yarss2.logger.Logger()
        self.torrent_handler = TorrentHandler(self.log)
        if config is None:
            self.yarss_config = YARSSConfig(self.log)
        else:
            self.yarss_config = config
        self.rssfeed_timer = RSSFeedTimer(self.yarss_config, self.log)
        self.rssfeed_timer.enable_timers()
        self.log.info("Enabled YaRSS2 %s" % yarss2.common.get_version())

    def disable(self):
        self.yarss_config.save()
        self.rssfeed_timer.disable_timers()

    def update(self):
        pass

    @export
    def initiate_rssfeed_update(self, rssfeed_key, subscription_key=None):
        self.rssfeed_timer.rssfeed_update_handler(
            rssfeed_key, subscription_key=subscription_key)

    @export
    def set_config(self, config):
        self.yarss_config.set_config(config)

    @export
    def get_config(self):
        "Returns the config dictionary"
        return self.yarss_config.get_config()

    @export
    def save_email_configurations(self, email_configurations):
        conf = {"email_configurations": email_configurations}
        try:
            self.yarss_config.set_config(conf)
        except ValueError as (v):
            self.log.error("Failed to save email configurations:" + str(v))

    @export
    def save_subscription(self,
                          dict_key=None,
                          subscription_data=None,
                          delete=False):
        """Saves the subscription in subscription_data.
        If subscription_data is None and delete=True, delete subscription with key==dict_key
        """
        if delete:
            if subscription_data is not None:
                self.log.warn(
                    "save_subscription called with delete=True, but rssfeed_data is not None!"
                )
            else:
                self.log.info("Deleting Subscription '%s'" %
                              self.yarss_config.get_config()["subscriptions"]
                              [dict_key]["name"])
        try:
            return self.yarss_config.generic_save_config(
                "subscriptions",
                dict_key=dict_key,
                data_dict=subscription_data,
                delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save subscription:" + str(v))

    @export
    def save_rssfeed(self, dict_key=None, rssfeed_data=None, delete=False):
        """Saves the rssfeed in rssfeed_data.
        If rssfeed_data is None and delete=True, delete rssfeed with key==dict_key
        """
        try:
            if delete:
                if rssfeed_data is not None:
                    self.log.warn(
                        "save_rssfeed called with delete=True, but rssfeed_data is not None!"
                    )
                else:
                    self.log.info("Stopping and deleting RSS Feed '%s'" %
                                  self.yarss_config.get_config()["rssfeeds"]
                                  [dict_key]["name"])

            config = self.yarss_config.generic_save_config(
                "rssfeeds",
                dict_key=dict_key,
                data_dict=rssfeed_data,
                delete=delete)
            if delete is True:
                self.rssfeed_timer.delete_timer(dict_key)
            # Successfully saved rssfeed, check if timer was changed
            elif config:
                if self.rssfeed_timer.set_timer(
                        rssfeed_data["key"], rssfeed_data["update_interval"]):
                    self.log.info("Scheduled RSS Feed '%s' with interval %s" %
                                  (rssfeed_data["name"],
                                   rssfeed_data["update_interval"]))
            return config
        except ValueError as (v):
            self.log.error("Failed to save rssfeed:" + str(v))

    @export
    def save_cookie(self, dict_key=None, cookie_data=None, delete=False):
        """Save cookie to config.
        If cookie_data is None and delete=True, delete cookie with key==dict_key"""
        try:
            return self.yarss_config.generic_save_config("cookies",
                                                         dict_key=dict_key,
                                                         data_dict=cookie_data,
                                                         delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save cookie:" + str(v))

    @export
    def save_email_message(self,
                           dict_key=None,
                           message_data=None,
                           delete=False):
        """Save email message to config.
        If message_data is None, delete message with key==dict_key"""
        try:
            return self.yarss_config.generic_save_config(
                "email_messages",
                dict_key=dict_key,
                data_dict=message_data,
                delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save email message:" + str(v))

    @export
    def add_torrent(self, torrent_url):
        cookie_header = get_cookie_header(
            self.yarss_config.get_config()["cookies"], torrent_url)
        id = self.torrent_handler.add_torrent(torrent_url,
                                              cookie_header=cookie_header)
コード例 #18
0
ファイル: core.py プロジェクト: thewetzel/deluge-yarss-plugin
class Core(CorePluginBase):

    def enable(self, config=None):
        self.log = yarss2.logger.Logger()
        self.torrent_handler = TorrentHandler(self.log)
        if config is None:
            self.yarss_config = YARSSConfig(self.log)
        else:
            self.yarss_config = config
        self.rssfeed_timer = RSSFeedTimer(self.yarss_config, self.log)
        self.rssfeed_timer.enable_timers()
        self.log.info("Enabled YaRSS2 %s" % yarss2.common.get_version())

    def disable(self):
        self.yarss_config.save()
        self.rssfeed_timer.disable_timers()

    def update(self):
        pass

    @export
    def initiate_rssfeed_update(self, rssfeed_key, subscription_key=None):
        self.rssfeed_timer.rssfeed_update_handler(rssfeed_key, subscription_key=subscription_key)

    @export
    def set_config(self, config):
        self.yarss_config.set_config(config)

    @export
    def get_config(self):
        "Returns the config dictionary"
        return self.yarss_config.get_config()

    @export
    def save_email_configurations(self, email_configurations):
        conf = {"email_configurations": email_configurations}
        try:
            self.yarss_config.set_config(conf)
        except ValueError as (v):
            self.log.error("Failed to save email configurations:" + str(v))

    @export
    def save_subscription(self, dict_key=None, subscription_data=None, delete=False):
        """Saves the subscription in subscription_data.
        If subscription_data is None and delete=True, delete subscription with key==dict_key
        """
        if delete:
            if subscription_data is not None:
                self.log.warn("save_subscription called with delete=True, but rssfeed_data is not None!")
            else:
                self.log.info("Deleting Subscription '%s'" %
                         self.yarss_config.get_config()["subscriptions"][dict_key]["name"])
        try:
            return self.yarss_config.generic_save_config("subscriptions", dict_key=dict_key,
                                                         data_dict=subscription_data, delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save subscription:" + str(v))

    @export
    def save_rssfeed(self, dict_key=None, rssfeed_data=None, delete=False):
        """Saves the rssfeed in rssfeed_data.
        If rssfeed_data is None and delete=True, delete rssfeed with key==dict_key
        """
        try:
            if delete:
                if rssfeed_data is not None:
                    self.log.warn("save_rssfeed called with delete=True, but rssfeed_data is not None!")
                else:
                    self.log.info("Stopping and deleting RSS Feed '%s'" %
                             self.yarss_config.get_config()["rssfeeds"][dict_key]["name"])

            config = self.yarss_config.generic_save_config("rssfeeds", dict_key=dict_key,
                                                         data_dict=rssfeed_data, delete=delete)
            if delete is True:
                self.rssfeed_timer.delete_timer(dict_key)
            # Successfully saved rssfeed, check if timer was changed
            elif config:
                if self.rssfeed_timer.set_timer(rssfeed_data["key"], rssfeed_data["update_interval"]):
                    self.log.info("Scheduled RSS Feed '%s' with interval %s" %
                             (rssfeed_data["name"], rssfeed_data["update_interval"]))
            return config
        except ValueError as (v):
            self.log.error("Failed to save rssfeed:" + str(v))

    @export
    def save_cookie(self, dict_key=None, cookie_data=None, delete=False):
        """Save cookie to config.
        If cookie_data is None and delete=True, delete cookie with key==dict_key"""
        try:
            return self.yarss_config.generic_save_config("cookies", dict_key=dict_key,
                                                         data_dict=cookie_data, delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save cookie:" + str(v))

    @export
    def save_email_message(self, dict_key=None, message_data=None, delete=False):
        """Save email message to config.
        If message_data is None, delete message with key==dict_key"""
        try:
            return self.yarss_config.generic_save_config("email_messages", dict_key=dict_key,
                                                         data_dict=message_data, delete=delete)
        except ValueError as (v):
            self.log.error("Failed to save email message:" + str(v))

    @export
    def add_torrent(self, torrent_url):
        cookie_header = get_cookie_header(self.yarss_config.get_config()["cookies"], torrent_url)
        id = self.torrent_handler.add_torrent(torrent_url, cookie_header=cookie_header)