<commit_before>import os
import logging
from flexget.plugin import register_plugin, priority, PluginWarning

log = logging.getLogger('exists')


class FilterExists(object):

    """
        Reject entries that already exist in given path.

        Example:

        exists: /storage/movies/
    """

    def validator(self):
        from flexget import validator
        root = validator.factory()
        root.accept('path')
        bundle = root.accept('list')
        bundle.accept('path')
        return root

    def get_config(self, feed):
        config = feed.config.get('exists', None)
        # If only a single path is passed turn it into a 1 element list
        if isinstance(config, basestring):
            config = [config]
        return config

    @priority(-1)
    def on_feed_filter(self, feed):
        config = self.get_config(feed)
        for path in config:
            # unicode path causes crashes on some paths
            path = str(os.path.expanduser(path))
            if not os.path.exists(path):
                raise PluginWarning('Path %s does not exist' % path, log)
            # scan through
            for root, dirs, files in os.walk(path):
                # convert filelists into utf-8 to avoid unicode problems
                dirs = [x.decode('utf-8', 'ignore') for x in dirs]
                files = [x.decode('utf-8', 'ignore') for x in files]
                for entry in feed.entries:
                    name = entry['title']
                    if name in dirs or name in files:
                        log.debug('Found %s in %s' % (name, root))
                        feed.reject(entry, '%s/%s' % (name, root))

register_plugin(FilterExists, 'exists')<commit_msg>Tweak exists plugin rejection message. Prevent exists plugin scanning when there are no accepted entries. Add verbose log message to exists that indicates it is scanning. refs #1647<commit_after>import os
import logging
from flexget.plugin import register_plugin, priority, PluginWarning

log = logging.getLogger('exists')


class FilterExists(object):

    """
        Reject entries that already exist in given path.

        Example:

        exists: /storage/movies/
    """

    def validator(self):
        from flexget import validator
        root = validator.factory()
        root.accept('path')
        bundle = root.accept('list')
        bundle.accept('path')
        return root

    def get_config(self, feed):
        config = feed.config.get('exists', None)
        # If only a single path is passed turn it into a 1 element list
        if isinstance(config, basestring):
            config = [config]
        return config

    @priority(-1)
    def on_feed_filter(self, feed):
        if not feed.accepted:
            log.debug('No accepted entries, not scanning for existing.')
            return
        log.verbose('Scanning path(s) for existing files.')
        config = self.get_config(feed)
        for path in config:
            # unicode path causes crashes on some paths
            path = str(os.path.expanduser(path))
            if not os.path.exists(path):
                raise PluginWarning('Path %s does not exist' % path, log)
            # scan through
            for root, dirs, files in os.walk(path):
                # convert filelists into utf-8 to avoid unicode problems
                dirs = [x.decode('utf-8', 'ignore') for x in dirs]
                files = [x.decode('utf-8', 'ignore') for x in files]
                for entry in feed.accepted:
                    name = entry['title']
                    if name in dirs or name in files:
                        log.debug('Found %s in %s' % (name, root))
                        feed.reject(entry, os.path.join(root, name))

register_plugin(FilterExists, 'exists')
{'fraction_non_alphanumeric': 0.09585423818325851, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 1.9709803921568627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129711', 'n_tokens_mistral': 1032, 'n_tokens_neox': 979, 'n_words': 345}