コード例 #1
0
ファイル: feedjack_status.py プロジェクト: allo-/feedjack
		def display_feed_status(feed):
			status = list()
			if not feed.is_active: status.append('disabled')
			elif feed.subscriber_set.count()\
					and feed.subscriber_set.filter(site_id=site.id, is_active=False):
				status.append('subscriber disabled')

			self.p( '  {} [{}] {}', ' '.join(it.imap( '({0})'.format,
				status )) if int(opts.verbosity) <= 1 else '', feed.id, feed )

			if int(opts.verbosity) > 1:
				self.p(
					'    Status: {}. Last check: {} ({}).', ', '.join(status) or 'active',
					feed.last_checked, utils.naturaltime_diff(feed.last_checked, ext='ago') )
			if int(opts.verbosity) > 2:
				filters = list(feed.filters.all())
				if filters: self.dump(filters, header='Filters:', indent=' '*4)
コード例 #2
0
ファイル: feedjack_status.py プロジェクト: vinodyk/feedjack
        def display_feed_status(feed):
            status = list()
            if not feed.is_active: status.append('disabled')
            elif feed.subscriber_set.count()\
              and feed.subscriber_set.filter(site_id=site.id, is_active=False):
                status.append('subscriber disabled')

            self.p(
                '  {} [{}] {}', ' '.join(it.imap('({0})'.format, status))
                if int(opts.verbosity) <= 1 else '', feed.id, feed)

            if int(opts.verbosity) > 1:
                self.p('    Status: {}. Last check: {} ({}).',
                       ', '.join(status) or 'active', feed.last_checked,
                       utils.naturaltime_diff(feed.last_checked, ext='ago'))
            if int(opts.verbosity) > 2:
                filters = list(feed.filters.all())
                if filters:
                    self.dump(filters, header='Filters:', indent=' ' * 4)
コード例 #3
0
ファイル: feedjack_purge.py プロジェクト: vinodyk/feedjack
    def handle(self, **opts):
        opts = type(
            b'Opts', (object, ),
            dict((k.replace('-', '_'), v) for k, v in opts.viewitems()))
        log = logging.getLogger('feedjack.purge')
        command_logger_setup(log, opts, stream=self.stdout)

        if not opts.feed and not opts.site:
            feeds = set(models.Feed.all())
            log.info('All feeds will be affected (%s)', len(feeds))
        else:
            feeds = set()
            if opts.feed:
                try:
                    feeds.update(
                        models.Feed.objects.get_by_string(name)
                        for name in opts.feed)
                except (models.ObjectDoesNotExist,
                        models.MultipleObjectsReturned) as err:
                    raise CommandError(unicode(err))
            if opts.site:
                try:
                    sites = list(
                        models.Site.objects.get_by_string(name)
                        for name in opts.site)
                except (models.ObjectDoesNotExist,
                        models.MultipleObjectsReturned) as err:
                    raise CommandError(unicode(err))
                for site in sites:
                    feeds.update(site.feeds)
            if log.isEnabledFor(logging.INFO):
                if log.isEnabledFor(logging.DEBUG):
                    log.debug('List of affected feeds (%s):', len(feeds))
                    for feed in sorted(feeds, key=op.attrgetter('pk')):
                        log.debug(' - [%s] %s', feed.pk, feed)
                else:
                    log.info(
                        'Number of affected feeds: %s (listed with more verbose logging)',
                        len(feeds))

        if opts.type == 'by-age':
            ts0, ts = timezone.localtime(timezone.now()), parse_timestamp(
                opts.time_spec)
            log.info('Parsed time spec %r as %s (delta: %s)', opts.time_spec,
                     ts, naturaltime_diff(ts, ts0))

            ts_field = 'date_{}'.format(opts.timestamp_type)
            ts_field_check = {
                '{}__{}'.format(ts_field, 'gt' if opts.newer else 'lt'): ts
            }
            log.debug('Timestamp field check: %s', ts_field_check)

            posts = models.Post.objects.filter(feed__in=feeds,
                                               **ts_field_check)

            if log.isEnabledFor(logging.INFO):
                if log.isEnabledFor(logging.DEBUG):
                    log.debug('List of selected Posts (%s):', posts.count())
                    for post in posts.order_by('pk'):
                        log.debug(' - [%s] %s', post.pk, post)
                else:
                    log.info(
                        'Selected %s Post object(s) for'
                        ' cleanup (listed with more verbose logging)',
                        posts.count())

            if not opts.dry_run:
                show_count = log.isEnabledFor(logging.INFO) and posts.count()
                if show_count:
                    log.info('Removing %s entries', show_count)
                    ts0 = time.time()
                posts.delete()
                if show_count:
                    log.info('Finished removal of %s entries (time: %.2fs)',
                             show_count,
                             time.time() - ts0)

        else:
            raise ValueError(post.type)