-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAllScalaFiles.py
57 lines (48 loc) · 1.48 KB
/
getAllScalaFiles.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
import os
from itertools import chain
import shutil
import subprocess
from subprocess import DEVNULL
import re
scalac = "/Users/arunkumar/scala/bin/scalac"
def find_all(basedir, pred):
for root, dirs, files in os.walk(basedir):
for fn in files:
path = os.path.join(root, fn)
if pred(path):
yield path
files = chain(
find_all("/Users/arunkumar/test1/", lambda p: p.endswith('.scala')))
# for i in files:
# os.system(f'cp {re.escape(i)} /Users/arunkumar/test1/')
added_files = chain(
find_all("/Users/arunkumar/test/", lambda p: p.endswith('.scala')))
addedfiles = map(lambda x: os.path.basename(x), added_files)
count1 = 0
count2 = 0
count = 0
for file in files:
# if (os.path.basename(file) in addedfiles):
# continue
a = subprocess.Popen([scalac, file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
b = a.stdout.read()
x = a.stderr.read()
c = b.decode("utf-8")
y = x.decode("utf-8")
print(f'FILE: {file}')
print(f'OUTPUT: {c}')
# print(f'ERROR: {y}')
q = re.search('errors', c)
if q is not None:
os.remove(file)
print(f'REMOVED {file} !!!!!\n')
# count += 1
# if c=='':
# os.system(f'cp {file} /Users/arunkumar/scalaExampleFinal/scalaPos')
# count1 += 1
# else:
# os.system(f'cp {file} /Users/arunkumar/scalaExampleFinal/scalaNeg')
# count2 += 1
print(f'all: {count}')
print(f'compiled: {count1}')
print(f'uncompiled: {count2}')