예제 #1
0
파일: manager.py 프로젝트: gray/Flexget
    def update_feeds(self):
        """Updates instances of all configured feeds from config"""
        from flexget.feed import Feed

        if not isinstance(self.config['feeds'], dict):
            log.critical('Feeds is in wrong datatype, please read configuration guides')
            return

        # construct feed list
        for name in self.config.get('feeds', {}):
            if not isinstance(self.config['feeds'][name], dict):
                continue
            if name in self.feeds:
                # This feed already has an instance, update it
                self.feeds[name].config = deepcopy(self.config['feeds'][name])
                if not name.startswith('_'):
                    self.feeds[name].enabled = True
            else:
                # Create feed
                feed = Feed(self, name, deepcopy(self.config['feeds'][name]))
                # If feed name is prefixed with _ it's disabled
                if name.startswith('_'):
                    feed.enabled = False
                self.feeds[name] = feed
        # Delete any feed instances that are no longer in the config
        for name in [n for n in self.feeds if n not in self.config['feeds']]:
            del self.feeds[name]
예제 #2
0
파일: manager.py 프로젝트: achuprin/Flexget
    def create_feeds(self):
        """Creates instances of all configured feeds"""
        from flexget.feed import Feed
        # Clear feeds dict
        self.feeds = {}

        if not 'feeds' in self.config:
            log.critical('There are no feeds in the configuration file!')
            return

        if not isinstance(self.config['feeds'], dict):
            log.critical('Feeds is in wrong datatype, please read configuration guides')
            return

        # construct feed list
        feeds = self.config.get('feeds', {}).keys()
        for name in feeds:
            # validate (TODO: make use of validator?)
            if not isinstance(self.config['feeds'][name], dict):
                if isinstance(self.config['feeds'][name], basestring):
                    from flexget.plugin import plugins
                    if name in plugins:
                        log.error('\'%s\' is known keyword, but in wrong indentation level. \
                        Please indent it correctly under a feed. Reminder: keyword should have 2 \
                        more spaces than feed name.' % name)
                        continue
                log.error('\'%s\' is not a properly configured feed, please check indentation levels.' % name)
                continue

            # create feed
            feed = Feed(self, name, self.config['feeds'][name])
            # if feed name is prefixed with _ it's disabled
            if name.startswith('_'):
                feed.enabled = False
            self.feeds[name] = feed
예제 #3
0
 def on_feed_filter(self, feed, config):
     entry_actions = {
         'accept': feed.accept,
         'reject': feed.reject,
         'fail': feed.fail}
     for entry in feed.entries:
         # Make entry fields and other utilities available in the eval namespace
         # We need our namespace to be an Entry instance for lazy loading to work
         eval_locals = copy(entry)
         eval_locals.update({'has_field': lambda f: f in entry,
                             'timedelta': datetime.timedelta,
                             'now': datetime.datetime.now()})
         for item in config:
             requirement, action = item.items()[0]
             try:
                 # Restrict eval namespace to have no globals and locals only from eval_locals
                 passed = safer_eval(requirement, eval_locals)
             except NameError, e:
                 # Extract the name that did not exist
                 missing_field = e.message.split('\'')[1]
                 log.debug('%s does not contain the field %s' % (entry['title'], missing_field))
             except Exception, e:
                 log.error('Error occurred in if statement: %r' % e)
             else:
                 if passed:
                     log.debug('%s matched requirement %s' % (entry['title'], requirement))
                     if isinstance(action, basestring):
                         # Simple entry action (accept, reject or fail) was specified as a string
                         entry_actions[action](entry, 'Matched requirement: %s' % requirement)
                     else:
                         # Other filters were specified to run on this entry
                         fake_feed = Feed(feed.manager, feed.name, feed.config)
                         fake_feed.session = feed.session
                         fake_feed.entries = [entry]
                         try:
                             for filter_name, filter_config in action.iteritems():
                                 filter = get_plugin_by_name(filter_name)
                                 method = filter.phase_handlers['filter']
                                 method(fake_feed, filter_config)
                         except Exception:
                             raise
                         else:
                             # Populate changes from the fake feed to the real one
                             for e in fake_feed.accepted:
                                 feed.accept(e, e.get('reason'))
                             for e in fake_feed.rejected:
                                 feed.reject(e, e.get('reason'))
                             for e in fake_feed.failed:
                                 feed.fail(e, e.get('reason'))
예제 #4
0
    def create_feeds(self):
        """Creates instances of all configured feeds"""
        from flexget.feed import Feed
        # Clear feeds dict
        self.feeds = {}

        # construct feed list
        feeds = self.config.get('feeds', {}).keys()
        for name in feeds:
            # create feed
            feed = Feed(self, name, self.config['feeds'][name])
            # if feed name is prefixed with _ it's disabled
            if name.startswith('_'):
                feed.enabled = False
            self.feeds[name] = feed
예제 #5
0
 def handle_phase(feed, config):
     if feed.name not in self.feed_phases:
         log.debug('No config dict was generated for this feed.')
         return
     entry_actions = {
         'accept': feed.accept,
         'reject': feed.reject,
         'fail': feed.fail}
     for item in self.feed_phases[feed.name][phase]:
         requirement, action = item.items()[0]
         passed_entries = [e for e in feed.entries if self.check_condition(requirement, e)]
         if passed_entries:
             if isinstance(action, basestring):
                 # Simple entry action (accept, reject or fail) was specified as a string
                 for entry in passed_entries:
                     entry_actions[action](entry, 'Matched requirement: %s' % requirement)
             else:
                 # Other plugins were specified to run on this entry
                 fake_feed = Feed(feed.manager, feed.name, feed.config)
                 fake_feed.session = feed.session
                 fake_feed.entries = passed_entries
                 fake_feed.accepted = [e for e in feed.accepted if self.check_condition(requirement, e)]
                 fake_feed.rejected = [e for e in feed.rejected if self.check_condition(requirement, e)]
                 try:
                     for plugin_name, plugin_config in action.iteritems():
                         plugin = get_plugin_by_name(plugin_name)
                         method = plugin.phase_handlers[phase]
                         method(fake_feed, plugin_config)
                 except Exception:
                     raise
                 else:
                     # Populate changes from the fake feed to the real one
                     for e in fake_feed.accepted:
                         feed.accept(e, e.get('reason'))
                     for e in fake_feed.rejected:
                         feed.reject(e, e.get('reason'))
                     for e in fake_feed.failed:
                         feed.fail(e, e.get('reason'))
         feed.purge()
예제 #6
0
def edit_text(root, name):
    config_type = root.rstrip('s')
    context = {
        'name': name,
        'root': root,
        'config_type': config_type}

    if request.method == 'POST':
        context['config'] = request.form['config']
        try:
            config = yaml.load(request.form['config'])
        except yaml.scanner.ScannerError, e:
            flash('Invalid YAML document: %s' % e, 'error')
            log.exception(e)
        else:
            # valid yaml, now run validator
            errors = Feed.validate_config(config)
            if errors:
                for error in errors:
                    flash(error, 'error')
                context['config'] = request.form['config']
            else:
                manager.config[root][name] = config
                manager.save_config()
                context['config'] = yaml.dump(config, default_flow_style=False)
                if request.form.get('name') != name:
                    # Renaming
                    new_name = request.form.get('name')
                    if new_name in manager.config[root]:
                        flash('%s with name %s already exists' % (config_type.capitalize(), new_name), 'error')
                    else:
                        # Do the rename
                        manager.config[root][new_name] = manager.config[root][name]
                        del manager.config[root][name]
                        manager.save_config()
                        flash('%s %s renamed to %s.' % (config_type.capitalize(), name, new_name), 'success')
                        return redirect(url_for('edit_text', root=root, name=new_name))
                else:
                    flash('Configuration saved', 'success')