-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleaner.py
46 lines (40 loc) · 1.17 KB
/
cleaner.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
import os
import misc
import shutil
class Cleaner:
tempdir = None
games = 0
args = []
def __init__(self, args, tempdir):
self.args = args
self.tempdir = tempdir
self.initDir()
def delDir(self):
if not os.path.exists(self.tempdir) : return
shutil.rmtree(self.tempdir)
def initDir(self):
if os.path.exists(self.tempdir) : self.delDir()
os.makedirs(self.tempdir)
def invalidline(self, line):
if line[0] == '#' : return True
temp = line.split(':')
if len(temp) != 3 : return True
try:
float(temp[2])
except:
return True
return False
def clean(self):
print("Cleaning...")
data = misc.loadFile(self.args.testfile)
file = open(self.tempdir + '/' + "test.txt", 'w')
err = 0
for line in data:
if not self.invalidline(line):
file.write(line)
else:
err += 1
file.close()
self.games = len(data) - err
print("'" + self.args.testfile + "' cleaned (" + str(self.games)
+ " games and " + str(err) + " invalid lines)")