-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtrain_all.py
executable file
·38 lines (28 loc) · 1.1 KB
/
train_all.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
#!/usr/bin/env python
import os
import sys
import regex
pattern = None
if len(sys.argv) > 1:
classnames = [sys.argv[1]]
if len(sys.argv) >= 3:
pattern = '.*' + sys.argv[2] + '.*'
else:
classnames = os.popen('ls tdata/train | perl -pe \'s/^(.*?)_00.*/$1/g\' | uniq', 'r').readlines()
classnames = map(lambda x: x.strip(), classnames)
for cn in classnames:
if pattern == None:
posfiles = os.popen('ls tdata/train/%s*.pcap' % (cn,), 'r').readlines()
posfiles = map(lambda x: '-T ' + x.strip(), posfiles)
negfiles = os.popen('ls tdata/train/*.pcap | grep -Pv \'^%s\'' % (cn,), 'r').readlines()
negfiles = map(lambda x: '-N ' + x.strip(), negfiles)
else:
pattern = regex.compile(pattern)
files = os.popen('ls tdata/train/*.pcap', 'r').readlines()
files = [x.strip() for x in files]
posfiles = ['-T ' + x for x in files if pattern.match(x) != None]
negfiles = ['-N ' + x for x in files if pattern.match(x) == None]
outfile = 'classifiers/%s' % (cn,)
cmd = './pacumen_train.py -M 2 ' + ' '.join(posfiles + negfiles) + ' ' + outfile
print cmd
os.system(cmd)