forked from CIFASIS/VDiscover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcreator
executable file
·97 lines (78 loc) · 2.92 KB
/
tcreator
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python2
"""
This file is part of VDISCOVER.
VDISCOVER is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VDISCOVER is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VDISCOVER. If not, see <http://www.gnu.org/licenses/>.
Copyright 2014 by G.Grieco
"""
import os
import argparse
import sys
import csv
from vdiscover.Detection import WriteTestcase
from functools import reduce
concatenate = lambda *lists: reduce((lambda a, b: a.extend(b) or a), lists, [])
if __name__ == "__main__":
# Arguments
parser = argparse.ArgumentParser(
description='A small utility to create new test cases using a name and a command line')
parser.add_argument("--name", help="The name of the ",
type=str, default=None)
parser.add_argument(
"--cmd", help="Command-line to execute", type=str, default=None)
parser.add_argument(
"--batch", help="A csv with the command lines", type=str, default=None)
parser.add_argument(
"--copy",
help="Force the copy of the files in command lines instead of symbolic linking",
action='store_true',
default=False)
parser.add_argument(
"outdir",
help="Output directory to write testcases",
type=str,
default=None)
options = parser.parse_args()
name = options.name
cmd = options.cmd
in_file = options.batch
copy = options.copy
out_dir = options.outdir
if (name is not None and cmd is not None) ^ (in_file is not None):
pass
else:
# or (name not is None and cmd is not None) and in_file is None:
print "Either name and command should be used or an input file"
exit(-1)
try:
os.makedirs(out_dir)
except:
pass
if in_file is not None:
infile = open(in_file, "r")
csvreader = csv.reader(infile, delimiter='\t')
os.chdir(out_dir)
for i, row in enumerate(csvreader):
args = filter(lambda x: x is not '', row[0].split(" "))
name = args[0].replace("/", "_") + ":" + str(i)
WriteTestcase(name, args[0], args[1:], copy)
else:
os.chdir(out_dir)
args = cmd.split("'")
args = map(lambda x: x.split(" "), args)
pargs = []
for arg in args:
if arg != '':
pargs = pargs + arg
#args = concatenate(args)
print "Procesing '" + " ".join(pargs) + "'"
#args = filter(lambda x: x is not '', cmd.split(" "))
WriteTestcase(name, pargs[0], pargs[1:], copy)