-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
78 lines (58 loc) · 2.16 KB
/
script.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
67
68
69
70
71
72
73
74
75
76
77
78
#!usr/bin python3
import os
class RepoAnalyser:
buildDependency = {
"C":"docker build -t whanos-c .",
"Java":"docker build -t whanos-java .",
"JavaScript":"docker build -t whanos-javascript .",
"Python":"docker build -t whanos-python .",
"Befunge":"docker build -t whanos-befunge ." }
dockerFilesCopy = {
"C":"cp images/c/Dockerfile.standalone .",
"Java":"cp images/java/Dockerfile.standalone .",
"JavaScript":"cp images/javascript/Dockerfile.standalone .",
"Python":"cp images/python/Dockerfile.standalone .",
"Befunge":"cp images/befunge/Dockerfile.standalone ."}
files = os.listdir(".")
def __init__(self):
pass
def checkLanguageUsed(self):
lang = []
try:
if 'Makefile' in self.files:
lang.append('C')
if 'package.json' in self.files:
lang.append('JavaScript')
if 'requirements.txt' in self.files:
lang.append('Python')
try:
if 'app' in self.files:
appFiles = os.listdir("./app")
if 'pom.xml' in appFiles:
lang.append('Java')
if 'main.bf' in appFiles:
lang.append('Befunge')
except:
raise Exception("No language found")
except:
raise Exception("No language found")
return lang
def runDockerFiles(self, language):
i = 0
if "Dockerfile" in self.files:
i = os.system(self.buildDependency[language])
else:
os.system(self.dockerFilesCopy[language])
os.system(self.buildDependency[language])
if i != 0:
raise Exception('Dockerfile build failed')
def main():
myrepoanalyser = RepoAnalyser()
language = myrepoanalyser.checkLanguageUsed()
if language.__len__() > 1:
raise Exception("Too many languages")
if language.__len__() == 0:
raise Exception('No language found')
myrepoanalyser.runDockerFiles(language[0])
if __name__ == "__main__":
main()