Commit 7f695c24 authored by Alain Takoudjou's avatar Alain Takoudjou

Update Software inspection and Project Management

parent 7a935c83
#
# jQuery File Tree
# Python/Django connector script
# By Martin Skou
#
import os
import urllib
def dirlist(request):
r=['<ul class="jqueryFileTree" style="display: none;">']
try:
r=['<ul class="jqueryFileTree" style="display: none;">']
d=urllib.unquote(request.POST.get('dir','c:\\temp'))
for f in os.listdir(d):
ff=os.path.join(d,f)
if os.path.isdir(ff):
r.append('<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % (ff,f))
else:
e=os.path.splitext(f)[1][1:] # get .ext and remove dot
r.append('<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>' % (e,ff,f))
r.append('</ul>')
except Exception,e:
r.append('Could not load directory: %s' % str(e))
r.append('</ul>')
return HttpResponse(''.join(r))
\ No newline at end of file
......@@ -133,6 +133,20 @@ def runSoftwareWithLock(config):
slapgrid = Popen([config['slapgrid_sr'], '-vc', config['configuration_file_path']], stdout=logfile)
writePid(slapgrid_pid, slapgrid.pid)
slapgrid.wait()
#Saves the current compile software for re-use
data = loadSoftwareData(config['runner_workdir'])
md5 = ""
for path in os.listdir(config['software_root']):
exist = False
for val in data:
if val['md5'] == path:
exist = True
if not exist: #save this compile software folder
data.append({"title":getProjectTitle(config), "md5":path,
"path": open(os.path.join(config['runner_workdir'],
".project"), 'r').read()})
writeSoftwareData(config['runner_workdir'], data)
break
return True
return False
......@@ -222,7 +236,7 @@ def getSvcTailProcess(config, process):
"tail", process]).communicate()[0]
def svcStartStopProcess(config, process, action):
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop"}
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop", "EXITED":"start", "STOP":"stop"}
return Popen([config['supervisor'], config['configuration_file_path'],
cmd[action], process]).communicate()[0]
......@@ -315,5 +329,42 @@ def getProjectTitle(config):
project = open(conf, "r").read().replace(config['workspace'] + "/", "").split("/")
software = project[len(project) - 1]
del project[len(project) - 1]
return software + "(" + string.join(project, '/') + ")"
return ""
\ No newline at end of file
return software + "(in " + string.join(project, '/') + ")"
return "No Profile"
def loadSoftwareData(runner_dir):
import pickle
file_path = os.path.join(runner_dir, '.softdata')
if not os.path.exists(file_path):
return []
pkl_file = open(file_path, 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
return data
def writeSoftwareData(runner_dir, data):
import pickle
file_path = os.path.join(runner_dir, '.softdata')
pkl_file = open(file_path, 'wb')
# Pickle dictionary using protocol 0.
pickle.dump(data, pkl_file)
pkl_file.close()
def removeSoftwareByName(config, folderName):
if isSoftwareRunning(config) or isInstanceRunning(config):
return jsonify(code=0, result="Software installation or instantiation in progress, cannot remove")
path = os.path.join(config['software_root'], folderName)
if not os.path.exists(path):
return jsonify(code=0, result="Can not remove software: No such file or directory")
svcStopAll(config)
shutil.rmtree(path)
#update compiled software list
data = loadSoftwareData(config['runner_workdir'])
i = 0
for p in data:
if p['md5'] == folderName:
del data[i]
writeSoftwareData(config['runner_workdir'], data)
break
i = i+1
return jsonify(code=1, result=data)
\ No newline at end of file
......@@ -3,7 +3,8 @@ from flask import Flask, request, redirect, url_for, \
from utils import *
import os
import shutil
from gittools import cloneRepo, gitStatus
from gittools import cloneRepo, gitStatus, switchBranch, createBranch, getDiff, \
gitPush
app = Flask(__name__)
......@@ -40,10 +41,9 @@ def inspectSoftware():
if not os.path.exists(app.config['software_root']):
result = ""
else:
#process = Popen(['find'], cwd=app.config['software_root'])
result = app.config['software_root']
return render_template('runResult.html', type='Software',
result=result)
return render_template('runResult.html', softwareRoot=app.config['software_root'],
softwares=loadSoftwareData(app.config['runner_workdir']))
@app.route('/removeSoftware')
def removeSoftware():
......@@ -52,6 +52,7 @@ def removeSoftware():
elif os.path.exists(app.config['software_root']):
svcStopAll(app.config)
shutil.rmtree(app.config['software_root'])
os.remove(os.path.join(config['runner_workdir'], ".softdata"))
flash('Software removed')
return redirect(url_for('inspectSoftware'))
......@@ -244,6 +245,21 @@ def createFile():
except Exception, e:
return jsonify(code=0, result=str(e))
@app.route("/removeFile", methods=['POST'])
def removeFile():
try:
if request.form['type'] == "folder":
shutil.rmtree(request.form['path'])
else:
os.remove(request.form['path'])
return jsonify(code=1, result="")
except Exception, e:
return jsonify(code=0, result=str(e))
@app.route("/removeSoftwareDir", methods=['POST'])
def removeSoftwareDir():
return removeSoftwareByName(app.config, request.form['name'])
@app.route("/getFileContent", methods=['POST'])
def getFileContent():
if os.path.exists(request.form['file']):
......@@ -257,4 +273,22 @@ def saveFileContent():
open(request.form['file'], 'w').write(request.form['content'])
return jsonify(code=1, result="")
else:
return jsonify(code=0, result="Error: No such file!")
\ No newline at end of file
return jsonify(code=0, result="Error: No such file!")
@app.route("/changeBranch", methods=['POST'])
def changeBranch():
return switchBranch(request.form['project'], request.form['name'])
@app.route("/newBranch", methods=['POST'])
def newBranch():
return createBranch(request.form['project'], request.form['name'])
@app.route("/getProjectDiff/<project>", methods=['GET'])
def getProjectDiff(project):
path = os.path.join(app.config['workspace'], project)
return render_template('projectDiff.html', project=project,
diff=getDiff(path))
@app.route("/pushProjectFiles", methods=['POST'])
def pushProjectFiles():
return gitPush(request.form['project'], request.form['msg'], False)
\ No newline at end of file
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