tracker_receive_news.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright 2013 The Distro Tracker Developers
  2. # See the COPYRIGHT file at the top-level directory of this distribution and
  3. # at http://deb.li/DTAuthors
  4. #
  5. # This file is part of Distro Tracker. It is subject to the license terms
  6. # in the LICENSE file found in the top-level directory of this
  7. # distribution and at http://deb.li/DTLicense. No part of Distro Tracker,
  8. # including this file, may be copied, modified, propagated, or distributed
  9. # except according to the terms contained in the LICENSE file.
  10. """
  11. A management command which is used to process an email message which could
  12. potentially be turned into a news item.
  13. """
  14. from django.core.management.base import BaseCommand
  15. from django.utils import six
  16. from distro_tracker.mail.mail_news import process
  17. import sys
  18. import logging
  19. logger = logging.getLogger(__name__)
  20. class Command(BaseCommand):
  21. input_file = sys.stdin
  22. def handle(self, *args, **kwargs):
  23. logger.info("Processing a received message")
  24. # Make sure to read binary data.
  25. if six.PY3:
  26. self.input_file = self.input_file.detach()
  27. input_data = self.input_file.read()
  28. process(input_data)
  29. logger.info('Completed processing a received message')