Commit 3e8bc280 authored by Alain Takoudjou's avatar Alain Takoudjou

Add tail -f n implementation for 'runSoftware' logs

parent ed69c295
{% extends "layout.html" %} {% extends "layout.html" %}
{% block title %}View {{ type }} log{% endblock %} {% block title %}View {{ type }} log{% endblock %}
{% block body %} {% block body %}
Currently running: <span class="message">{{ running }}</span><br>
<strong>Note:</strong> You can refresh this page from time to time to have updates.<br> <strong>Note:</strong> You can refresh this page from time to time to have updates.<br>
<h2>Currently running: <span class="message">{{ running }}</span></h2><br>
<h2>Result for {{ type }}</h2> <h2>Result for {{ type }}</h2>
<div class="log_content"><textarea class="log" readonly >{{ result }}</textarea></div> <div class="log_content"><textarea class="log" readonly >{{ result }}</textarea></div>
{% endblock %} {% endblock %}
...@@ -219,6 +219,10 @@ def runBuildoutAnnotate(config): ...@@ -219,6 +219,10 @@ def runBuildoutAnnotate(config):
return False return False
def svcStopAll(config): def svcStopAll(config):
#stop all process running in supervisord
request = Popen([config['supervisor'], config['configuration_file_path'],
'stop', 'all'])
request.wait()
return Popen([config['supervisor'], config['configuration_file_path'], return Popen([config['supervisor'], config['configuration_file_path'],
'shutdown']).communicate()[0] 'shutdown']).communicate()[0]
...@@ -257,7 +261,8 @@ def getFolderContent(folder): ...@@ -257,7 +261,8 @@ def getFolderContent(folder):
try: try:
r=['<ul class="jqueryFileTree" style="display: none;">'] r=['<ul class="jqueryFileTree" style="display: none;">']
d=urllib.unquote(folder) d=urllib.unquote(folder)
for f in os.listdir(d): ldir = sorted(os.listdir(d), key=unicode.lower)
for f in ldir:
if f.startswith('.'): #do not displays this file/folder if f.startswith('.'): #do not displays this file/folder
continue continue
ff=os.path.join(d,f) ff=os.path.join(d,f)
...@@ -275,9 +280,10 @@ def getFolderContent(folder): ...@@ -275,9 +280,10 @@ def getFolderContent(folder):
def getFolder(folder): def getFolder(folder):
r=['<ul class="jqueryFileTree" style="display: none;">'] r=['<ul class="jqueryFileTree" style="display: none;">']
try: try:
r=['<ul class="jqueryFileTree" style="display: none;">'] r=['<ul class="jqueryFileTree" style="display: none;">']
d=urllib.unquote(folder) d=urllib.unquote(folder)
for f in os.listdir(d): ldir = sorted(os.listdir(d), key=unicode.lower)
for f in ldir:
if f.startswith('.'): #do not display this file/folder if f.startswith('.'): #do not display this file/folder
continue continue
ff=os.path.join(d,f) ff=os.path.join(d,f)
...@@ -341,8 +347,7 @@ def checkSoftwareFolder(path, config): ...@@ -341,8 +347,7 @@ def checkSoftwareFolder(path, config):
tmp = path.split('/') tmp = path.split('/')
del tmp[len(tmp) - 1] del tmp[len(tmp) - 1]
path = string.join(tmp, '/') path = string.join(tmp, '/')
if os.path.exists(os.path.join(path, config['software_profile'])) and \ if os.path.exists(os.path.join(path, config['software_profile'])):
os.path.exists(os.path.join(path, config['instance_profile'])):
return jsonify(result=path) return jsonify(result=path)
return jsonify(result="") return jsonify(result="")
...@@ -390,4 +395,31 @@ def removeSoftwareByName(config, folderName): ...@@ -390,4 +395,31 @@ def removeSoftwareByName(config, folderName):
writeSoftwareData(config['runner_workdir'], data) writeSoftwareData(config['runner_workdir'], data)
break break
i = i+1 i = i+1
return jsonify(code=1, result=data) return jsonify(code=1, result=data)
\ No newline at end of file
def tail(f, lines=20):
"""
Returns the last `lines` lines of file `f`. It is an implementation of tail -f n.
"""
BUFSIZ = 1024
f.seek(0, 2)
bytes = f.tell()
size = lines + 1
block = -1
data = []
while size > 0 and bytes > 0:
if bytes - BUFSIZ > 0:
# Seek back one whole BUFSIZ
f.seek(block * BUFSIZ, 2)
# read BUFFER
data.insert(0, f.read(BUFSIZ))
else:
# file too small, start from begining
f.seek(0,0)
# only read what was not read
data.insert(0, f.read(bytes))
linesFound = data[0].count('\n')
size -= linesFound
bytes -= BUFSIZ
block -= 1
return string.join(''.join(data).splitlines()[-lines:], '\n')
\ No newline at end of file
...@@ -69,7 +69,7 @@ def runSoftwareProfile(): ...@@ -69,7 +69,7 @@ def runSoftwareProfile():
@app.route('/viewSoftwareLog', methods=['GET']) @app.route('/viewSoftwareLog', methods=['GET'])
def viewSoftwareLog(): def viewSoftwareLog():
if os.path.exists(app.config['software_log']): if os.path.exists(app.config['software_log']):
result = open(app.config['software_log'], 'r').read() result = tail(open(app.config['software_log'], 'r'), lines=1500)
else: else:
result = 'Not found yet' result = 'Not found yet'
return render_template('viewLog.html', type='Software', return render_template('viewLog.html', type='Software',
...@@ -87,7 +87,7 @@ def updateSoftwareProfile(): ...@@ -87,7 +87,7 @@ def updateSoftwareProfile():
def editInstanceProfile(): def editInstanceProfile():
profile = getProfile(app.config['runner_workdir'], app.config['instance_profile']) profile = getProfile(app.config['runner_workdir'], app.config['instance_profile'])
if profile == "": if profile == "":
flash('Error: can not open profile, please select your project first') flash('Error: can not open instance profile for this Software Release')
return render_template('updateInstanceProfile.html', return render_template('updateInstanceProfile.html',
profile=profile) profile=profile)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment