forked from ashley/EntropyLocalization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiffSourceCode.py
66 lines (59 loc) · 2.28 KB
/
DiffSourceCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import subprocess
import os, sys
# File where results are stored
fi = open("Results.txt", "wb")
"""
Preparation before executing diff command.
"""
def prepareDirectory():
diffPath = raw_input("Enter absolute path to aggregated source code directory: ")
versions = [version for version in os.listdir(diffPath) if version != ".DS_Store"] #filter out default mac files
for versionDirectory in versions:
getDiffData(diffPath + "/" + versionDirectory, versionDirectory)
"""
Calls diff command but does checks to make sure files exist
@param {String} versionPath: Absolute path to the version directory
@param {String} versionID: number that is associated with project
"""
def getDiffData(versionPath, versionID):
before_files = [i for i in os.listdir(versionPath + "/b") if i != ".DS_store"]
after_files = [i for i in os.listdir(versionPath + "/f") if i != ".DS_Store"]
version_information = {
"VersionID" : versionID,
"path" : versionPath,
"working" : str(len(before_files) == len(after_files)),
"results" : ""
}
bug_information = {}
count = 0
if before_files == after_files: #checks if files' b/f versions exist
for fileName in before_files:
appendWorkbook(version_information) #helper function, for easy implementation of Excel sheets
diffCommand = ''.join([
"diff ",
versionPath, "/b/", fileName, " ",
versionPath, "/f/", fileName
])
process = subprocess.Popen(diffCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
bug_information[fileName] = output
appendWorkbook(bug_information)
count += 1
"""
Currently writes in a file. Can be modified to be used with OpenPyxl
@param {Dictionary} inputMap: any map with <String,String> for appending to a file
"""
def appendWorkbook(inputMap):
for key, value in inputMap.items():
fi.write(key + " : " + value + "\n")
"""
To parse output results from diff command. Future implementation
@param {String} result: output string to parse
"""
def parseOutput(result):
result = result.split("\n")
result[0]
def main():
prepareDirectory()
if __name__ == "__main__":
main()