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