-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix_app
More file actions
executable file
·86 lines (70 loc) · 2.48 KB
/
matrix_app
File metadata and controls
executable file
·86 lines (70 loc) · 2.48 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
The Matrix application runs all of the known parsers thru all the files
found in the input directory and displays performance statistics for
each one.
"""
import os
import sys
import argparse
from choice.router import Router
options = None
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt
Yellow = chr(27) + '[0;33m'
White = chr(27) + '[0;37m'
Green = chr(27) + '[0;32m'
IGreen = chr(27) + '[0;92m'
def setup():
global options
# declare command-line argument parser
command_line = argparse.ArgumentParser(
description='Runs all of the parsers thru all the input files.',
prog=sys.argv[0],
)
# define the command-line arguments
command_line.add_argument('-s', '--stats', action='store_true',
help='Show statistics')
command_line.add_argument('-c', '--color', action='store_true',
help='Use bash colored output')
# load the commandline options
options = command_line.parse_args(sys.argv[1:])
def color(q):
if not options.color: return q
string = str(q)
color = White
if 'o' in string:
color = IGreen
elif 's' in string:
color = Yellow
return '%s%s%s' % (color, string, White)
def main():
relpath = os.path.dirname(sys.argv[0])
abspath = os.path.abspath(relpath)
inppath = os.path.join(abspath, 'input')
matrix = []
for input_file in os.listdir(inppath):
r = Router()
r.load(['-i', os.path.join(inppath, input_file)])
matrix.append(r)
if options.stats:
sys.stderr.write(input_file + '\n')
sys.stderr.write(str(r) + '\n')
if options.color:
data_line_format = '%-50s %-25s %-25s %-25s %-25s %-25s'
else:
data_line_format = '%-50s %-11s %-11s %-11s %-11s %-11s'
print '%-50s %-11s %-11s %-11s %-11s %-11s' % ('input file name', 'Stems', 'Block', 'Index', 'Chunk', 'Quest')
for router in matrix:
if router.options:
print data_line_format % (
router.options.inputfile.name,
color(router.qhash.get('StemsParser',' '*11)),
color(router.qhash.get('BlockParser',' '*11)),
color(router.qhash.get('IndexParser',' '*11)),
color(router.qhash.get('ChunkParser',' '*11)),
color(router.qhash.get('QuestParser',' '*11)),
)
if __name__ == "__main__":
setup()
main()