Skip to content

Commit 83cdd66

Browse files
committed
增加gas_query日志的查看功能
1 parent b124feb commit 83cdd66

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

log_console/command_helper.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,28 @@ def excute1(dev_id, app_id, event_filter, columns, lines='100', show_lines='100'
9898
return Result(cmd, out, err, titles, raws, time.time()-start_point)
9999

100100
@staticmethod
101-
def excute2(cmd_id, queryStr, reversed=False):
101+
def excute2(cmd_id, queryStr, show_lines='100', reversed=False):
102102
"""执行预定义的指令,显示执行结果
103103
"""
104104
config = ConfigParser.RawConfigParser(allow_no_value=True)
105105
config.read('console.ini')
106106
cmd = config.get('cmd', cmd_id)
107107

108108
if not os.access(cmd, os.F_OK):
109-
cmd = 'ls -l'
109+
cmd = 'ls -l 1>&2'
110110
elif len(queryStr) > 0:
111111
cmd = cmd + ' ' + queryStr
112112

113113
(cmd, cost, out, err) = CommandUtil.excute(cmd)
114114

115115
raws = out.split('\n')
116116

117+
if reversed:
118+
raws.reverse()
119+
print 'reversed@excute'
120+
121+
if len(raws) > int(show_lines): raws = raws[0:int(show_lines)]
122+
117123
return Result(cmd, out, err, None, raws, cost)
118124

119125
if __name__ == '__main__':

log_console/supervisor_console.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;bash -c 'source /home/liyan/console/env/bin/activate; python /home/liyan/console/web_console.py'
44
command=/srv/www/console/env/bin/python /srv/www/console/web_console.py
55
directory=/srv/www/console
6-
environment=PATH="/srv/www/console/env/bin:bin:/usr/bin:/usr/local/bin"
6+
environment=PATH="/srv/www/console/env/bin:/bin:/usr/bin:/usr/local/bin"
77
user=nobody
88
stdout_logfile=/var/log/supervisor/%(program_name)s.log
99
stdout_logfile_maxbytes=1MB

log_console/templates/gas.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}
2929
.yellow {background-color: #ffff00}
3030
.red {background-color: #DC143C}
31+
.blue {background-color: #40E0D0}
3132
</style>
3233
</head>
3334
<body>
@@ -57,7 +58,7 @@
5758
</tbody>
5859
</table>
5960
</div>
60-
<div class="clear"><div class="clear"><pre class="red">{{ result.err }}</pre></div></div>
61+
<div class="clear"><div class="clear"><pre class="blue">{{ result.err }}</pre></div></div>
6162
</div>
6263
</body>
6364
</html>

log_console/web_console.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,36 @@ class GameAd:
7676
def GET(self):
7777
form = web.form.Form(
7878
web.form.Textbox("queryStr", description=u'AppID、IDFA任意关键字'),
79+
80+
web.form.Textbox("ShowLines",
81+
web.form.notnull,
82+
web.form.regexp('\d+', 'Must be a digit'),
83+
web.form.Validator('Not more than 200', lambda x:int(x)<201),
84+
description=u'显示的条数',
85+
value="100",
86+
),
87+
88+
web.form.Checkbox('Reversed', description=u'是否倒序', value=True, checked=True),
7989
)
8090
return render_template('gas.html', form=form, result = None)
8191

8292
def POST(self):
8393
form = web.form.Form(
8494
web.form.Textbox("queryStr", description=u'AppID?IDFA?'),
95+
96+
web.form.Textbox("ShowLines",
97+
web.form.notnull,
98+
web.form.regexp('\d+', 'Must be a digit'),
99+
web.form.Validator('Not more than 200', lambda x:int(x)<201),
100+
description=u'显示的条数',
101+
value="100",
102+
),
103+
104+
web.form.Checkbox('Reversed', description=u'是否倒序', value=True, checked=True),
85105
)
86106
result = None
87107
if form.validates():
88-
result = CommandUtil.excute2(cmd_id='cmd_1', queryStr=form.d.queryStr)
108+
result = CommandUtil.excute2(cmd_id='cmd_1', queryStr=form.d.queryStr, show_lines=form.d.ShowLines, reversed=form.d.Reversed)
89109

90110
return render_template('gas.html',form=form, result=result)
91111

0 commit comments

Comments
 (0)