recv.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/python
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. #
  5. # Copyright (C) 2015 Alexandru Damian for Intel Corp.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. # Program to receive review requests by email and log tasks to backlog.txt
  20. # Designed to be run by the email system from a .forward file:
  21. #
  22. # cat .forward
  23. # |[full/path]/recv.py
  24. from __future__ import print_function
  25. import sys, config, shellutils
  26. from email.parser import Parser
  27. def recv_mail(datastring):
  28. headers = Parser().parsestr(datastring)
  29. return headers['subject']
  30. def main():
  31. lock_file = shellutils.lockfile(shellutils.mk_lock_filename(), retry=True)
  32. if lock_file is None:
  33. if config.DEBUG:
  34. print("Concurrent script in progress, exiting")
  35. sys.exit(1)
  36. subject = recv_mail(sys.stdin.read())
  37. subject_parts = subject.split()
  38. if "[review-request]" in subject_parts:
  39. task_name = subject_parts[subject_parts.index("[review-request]") + 1]
  40. with open(config.BACKLOGFILE, "a") as fout:
  41. line = "%s|%s\n" % (task_name, config.TASKS.PENDING)
  42. fout.write(line)
  43. shellutils.unlockfile(lock_file)
  44. if __name__ == "__main__":
  45. main()