|
4 | 4 | import subprocess |
5 | 5 | from threading import Timer, Thread |
6 | 6 | import psutil |
7 | | -from app.models import Patch, Run |
| 7 | +from app.models import Patch, Run, File |
8 | 8 | import tempfile |
9 | 9 | import os |
10 | 10 | import datetime |
@@ -74,33 +74,37 @@ def killer(process): |
74 | 74 |
|
75 | 75 | def workflow(self, patch: Patch): |
76 | 76 | assert self.__current_patch is None, 'no auto-concurrency!' |
77 | | - self.__current_patch = patch |
78 | | - |
79 | | - # step 1: write patch to temp file |
80 | | - patchfile = tempfile.NamedTemporaryFile(delete=False, mode='w') |
81 | | - patchfile.write(patch.patch) |
82 | | - patchfile.close() |
83 | | - |
84 | | - # step 2: apply patch |
85 | | - self.__execute_command_timeout('patch -p1 --input={patchfile}'.format(patchfile=patchfile.name), cwd='/') |
86 | | - |
87 | | - # step 3: command pipeline |
88 | | - success = self.__apply_command(patch, 'build_command') and \ |
89 | | - self.__apply_command(patch, 'quickcheck_command') and \ |
90 | | - self.__apply_command(patch, 'test_command') |
91 | | - |
92 | | - if success: |
93 | | - patch.state = 'survived' |
94 | | - db.session.commit() |
95 | | - |
96 | | - # step 4: revert patch |
97 | | - self.__execute_command_timeout('patch -p1 --reverse --input={patchfile}'.format(patchfile=patchfile.name), |
| 77 | + |
| 78 | + file = File.query.get(patch.file_id) |
| 79 | + |
| 80 | + if file is not None: |
| 81 | + self.__current_patch = patch |
| 82 | + |
| 83 | + # step 1: write patch to temp file |
| 84 | + patchfile = tempfile.NamedTemporaryFile(delete=False, mode='w') |
| 85 | + patchfile.write(patch.patch) |
| 86 | + patchfile.close() |
| 87 | + |
| 88 | + # step 2: apply patch |
| 89 | + self.__execute_command_timeout('patch -p1 --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), cwd='/') |
| 90 | + |
| 91 | + # step 3: command pipeline |
| 92 | + success = self.__apply_command(patch, 'build_command') and \ |
| 93 | + self.__apply_command(patch, 'quickcheck_command') and \ |
| 94 | + self.__apply_command(patch, 'test_command') |
| 95 | + |
| 96 | + if success: |
| 97 | + patch.state = 'survived' |
| 98 | + db.session.commit() |
| 99 | + |
| 100 | + # step 4: revert patch |
| 101 | + self.__execute_command_timeout('patch -p1 --reverse --input={patchfile} {inputfile}'.format(patchfile=patchfile.name, inputfile=file.filename), |
98 | 102 | cwd='/') |
99 | 103 |
|
100 | | - # step 6: delete patch file |
101 | | - os.remove(patchfile.name) |
| 104 | + # step 6: delete patch file |
| 105 | + os.remove(patchfile.name) |
102 | 106 |
|
103 | | - self.__current_patch = None |
| 107 | + self.__current_patch = None |
104 | 108 |
|
105 | 109 | def __apply_command(self, patch: Patch, step: str): |
106 | 110 | print(patch, step) |
|
0 commit comments