Skip to content

Commit 1335e0a

Browse files
authored
Merge pull request nlohmann#1 from igormironchik/master
A few changes that made mutate_cpp working on Ubuntu 16.04
2 parents 8207a88 + 466f16e commit 1335e0a

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
venv
33
*.pyc
4+
*.db

app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from flask_compress import Compress
55
from flask_sqlalchemy import SQLAlchemy
66
from flask_humanize import Humanize
7+
import os.path
8+
import sys
9+
10+
sys.path.append( os.path.dirname( os.path.abspath( __file__ ) ) )
711

812
app = Flask(__name__)
913
app.config.from_object('config')

app/utils/Executor.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
from threading import Timer, Thread
66
import psutil
7-
from app.models import Patch, Run
7+
from app.models import Patch, Run, File
88
import tempfile
99
import os
1010
import datetime
@@ -74,33 +74,37 @@ def killer(process):
7474

7575
def workflow(self, patch: Patch):
7676
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),
98102
cwd='/')
99103

100-
# step 6: delete patch file
101-
os.remove(patchfile.name)
104+
# step 6: delete patch file
105+
os.remove(patchfile.name)
102106

103-
self.__current_patch = None
107+
self.__current_patch = None
104108

105109
def __apply_command(self, patch: Patch, step: str):
106110
print(patch, step)

app/utils/SourceFile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def __create_patch(self, line_number: int, replacement: Replacement) -> str:
117117
))
118118

119119
# lines: context before
120-
patch_lines += [' ' + x + '\n' for x in context_before]
120+
patch_lines += [' ' + x + "\r\n" for x in context_before]
121121
# line: the old value
122-
patch_lines.append('-' + old_line + '\n')
122+
patch_lines.append('-' + old_line + "\r\n")
123123
# line: the new value
124124
if replacement.new_val is not None:
125-
patch_lines.append('+' + new_line + '\n')
125+
patch_lines.append('+' + new_line + "\r\n")
126126
# lines: context after
127-
patch_lines += [' ' + x + '\n' for x in context_after]
127+
patch_lines += [' ' + x + "\r\n" for x in context_after]
128128

129129
patch_text = ''.join(patch_lines)
130130
return patch_text

db_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# coding=utf-8
22

33
from migrate.versioning import api
4-
from config import SQLALCHEMY_DATABASE_URI
5-
from config import SQLALCHEMY_MIGRATE_REPO
4+
from app.config import SQLALCHEMY_DATABASE_URI
5+
from app.config import SQLALCHEMY_MIGRATE_REPO
66
from app import db
77
import os.path
88

db_migrate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import imp
44
from migrate.versioning import api
55
from app import db
6-
from config import SQLALCHEMY_DATABASE_URI
7-
from config import SQLALCHEMY_MIGRATE_REPO
6+
from app.config import SQLALCHEMY_DATABASE_URI
7+
from app.config import SQLALCHEMY_MIGRATE_REPO
88

99
if __name__ == '__main__':
1010
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)

db_upgrade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# coding=utf-8
22

33
from migrate.versioning import api
4-
from config import SQLALCHEMY_DATABASE_URI
5-
from config import SQLALCHEMY_MIGRATE_REPO
4+
from app.config import SQLALCHEMY_DATABASE_URI
5+
from app.config import SQLALCHEMY_MIGRATE_REPO
66

77
if __name__ == '__main__':
88
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)

0 commit comments

Comments
 (0)