Allow to open any file as a software release, not only software.cfg.

This commit may break half of webrunner, especially creation of new SR, and SR result.
parent 3902b5aa
...@@ -8,21 +8,19 @@ $(document).ready(function () { ...@@ -8,21 +8,19 @@ $(document).ready(function () {
var method = $("input#method").val(), var method = $("input#method").val(),
workdir = $("input#workdir").val(); workdir = $("input#workdir").val();
function checkFolder(path) { /*
$.ajax({ * Check if path is a .cfg (buildout profile) file.
type: "POST", **/
url: $SCRIPT_ROOT + '/checkFolder', function isBuildoutFile(path) {
data: "path=" + path, var suffix = '.cfg',
success: function (data) { isBuildoutFile = path.indexOf(suffix, path.length - suffix.length) !== -1;
var path = data.result;
$("input#path").val(path);
if (path !== "") {
$("#check").fadeIn('normal'); $("#check").fadeIn('normal');
if (isBuildoutFile) {
$("input#path").val(path);
} else { } else {
$("input#path").val('');
$("#check").hide(); $("#check").hide();
} }
}
});
return ""; return "";
} }
...@@ -31,7 +29,7 @@ $(document).ready(function () { ...@@ -31,7 +29,7 @@ $(document).ready(function () {
$("input#subfolder").val(file); $("input#subfolder").val(file);
if (method === "open") { if (method === "open") {
$("#info").append("Selection: " + file); $("#info").append("Selection: " + file);
checkFolder(file); isBuildoutFile(file);
} else { } else {
if ($("input#software").val() !== "" && $("input#software").val().match(/^[\w\d._\-]+$/)) { if ($("input#software").val() !== "" && $("input#software").val().match(/^[\w\d._\-]+$/)) {
$("#info").append("New Software in: " + file + $("input#software").val()); $("#info").append("New Software in: " + file + $("input#software").val());
...@@ -43,7 +41,7 @@ $(document).ready(function () { ...@@ -43,7 +41,7 @@ $(document).ready(function () {
} }
if (method !== "file") { if (method !== "file") {
$('#fileTree').fileTree({root: workdir, script: $SCRIPT_ROOT + '/openFolder', folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, multiFolder: false, selectFolder: true }, function (file) { $('#fileTree').fileTree({root: workdir, script: $SCRIPT_ROOT + '/readFolder', folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, multiFolder: false, selectFolder: true }, function (file) {
selectFile(file); selectFile(file);
}); });
} }
......
...@@ -93,10 +93,9 @@ def getCurrentSoftwareReleaseProfile(config): ...@@ -93,10 +93,9 @@ def getCurrentSoftwareReleaseProfile(config):
Returns used Software Release profile as a string. Returns used Software Release profile as a string.
""" """
try: try:
software_folder = open( software_profile_path = open(
os.path.join(config['etc_dir'], ".project")).read() os.path.join(config['etc_dir'], ".project")).read()
return realpath( return realpath(config, software_profile_path)
config, os.path.join(software_folder, config['software_profile']))
except: except:
return False return False
...@@ -315,7 +314,7 @@ def runInstanceWithLock(config): ...@@ -315,7 +314,7 @@ def runInstanceWithLock(config):
return True return True
return False return False
def getProfilePath(projectDir, profile): def getProfilePath(projectDir):
""" """
Return the path of the current Software Release `profile` Return the path of the current Software Release `profile`
...@@ -329,7 +328,7 @@ def getProfilePath(projectDir, profile): ...@@ -329,7 +328,7 @@ def getProfilePath(projectDir, profile):
if not os.path.exists(os.path.join(projectDir, ".project")): if not os.path.exists(os.path.join(projectDir, ".project")):
return False return False
projectFolder = open(os.path.join(projectDir, ".project")).read() projectFolder = open(os.path.join(projectDir, ".project")).read()
return os.path.join(projectFolder, profile) return projectFolder
def getSlapStatus(config): def getSlapStatus(config):
"""Return all Slapos Partitions with associate informations""" """Return all Slapos Partitions with associate informations"""
...@@ -440,40 +439,6 @@ def getFolderContent(config, folder): ...@@ -440,40 +439,6 @@ def getFolderContent(config, folder):
r.append('</ul>') r.append('</ul>')
return jsonify(result=''.join(r)) return jsonify(result=''.join(r))
def getFolder(config, folder):
"""
Read list of folder for the specified directory
Args:
config: Slaprunner configuration.
folder: the directory to read.
Returns:
Html formated string or error message when fail.
"""
r = ['<ul class="jqueryFileTree" style="display: none;">']
try:
folder = str(folder)
r = ['<ul class="jqueryFileTree" style="display: none;">']
d = urllib.unquote(folder)
realdir = realpath(config, d)
if not realdir:
r.append('Could not load directory: Permission denied')
ldir = []
else:
ldir = sorted(os.listdir(realdir), key=str.lower)
for f in ldir:
if f.startswith('.'): #do not display this file/folder
continue
ff = os.path.join(d, f)
if os.path.isdir(os.path.join(realdir, f)):
r.append('<li class="directory collapsed"><a href="#%s" rel="%s/">%s</a></li>' % (ff, ff, f))
r.append('</ul>')
except Exception as e:
r.append('Could not load directory: %s' % str(e))
r.append('</ul>')
return jsonify(result=''.join(r))
def getProjectList(folder): def getProjectList(folder):
"""Return the list of projet (folder) into the workspace """Return the list of projet (folder) into the workspace
...@@ -524,6 +489,9 @@ def newSoftware(folder, config, session): ...@@ -524,6 +489,9 @@ def newSoftware(folder, config, session):
folder: directory of the new software release folder: directory of the new software release
config: slraprunner configuration config: slraprunner configuration
session: Flask session directory""" session: Flask session directory"""
# XXX-Cedric completely broken. refactor to "profile_path" and refactor to work with new behavior.
return jsonify(code=0, result="Not implemented.")
json = "" json = ""
code = 0 code = 0
basedir = config['etc_dir'] basedir = config['etc_dir']
...@@ -559,13 +527,6 @@ def newSoftware(folder, config, session): ...@@ -559,13 +527,6 @@ def newSoftware(folder, config, session):
shutil.rmtree(folderPath) shutil.rmtree(folderPath)
return jsonify(code=code, result=json) return jsonify(code=code, result=json)
def checkSoftwareFolder(path, config):
"""Check id `path` is a valid Software Release folder"""
realdir = realpath(config, path)
if realdir and os.path.exists(os.path.join(realdir, config['software_profile'])):
return jsonify(result=path)
return jsonify(result="")
def getProjectTitle(config): def getProjectTitle(config):
"""Generate the name of the current software Release (for slaprunner UI)""" """Generate the name of the current software Release (for slaprunner UI)"""
conf = os.path.join(config['etc_dir'], ".project") conf = os.path.join(config['etc_dir'], ".project")
......
...@@ -12,7 +12,7 @@ from flask import (Flask, request, redirect, url_for, render_template, ...@@ -12,7 +12,7 @@ from flask import (Flask, request, redirect, url_for, render_template,
g, flash, jsonify, session, abort, send_file) g, flash, jsonify, session, abort, send_file)
from slapos.runner.process import killRunningProcess from slapos.runner.process import killRunningProcess
from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder, from slapos.runner.utils import (configNewSR,
getFolderContent, getProfilePath, getFolderContent, getProfilePath,
getProjectList, getProjectTitle, getSession, getProjectList, getProjectTitle, getSession,
getSlapStatus, getSvcStatus, getSlapStatus, getSvcStatus,
...@@ -111,7 +111,7 @@ def doLogin(): ...@@ -111,7 +111,7 @@ def doLogin():
# software views # software views
@login_required() @login_required()
def editSoftwareProfile(): def editSoftwareProfile():
profile = getProfilePath(app.config['etc_dir'], app.config['software_profile']) profile = getProfilePath(app.config['etc_dir'])
if profile == "": if profile == "":
flash('Error: can not open profile, please select your project first') flash('Error: can not open profile, please select your project first')
return render_template('updateSoftwareProfile.html', workDir='workspace', return render_template('updateSoftwareProfile.html', workDir='workspace',
...@@ -154,7 +154,8 @@ def viewSoftwareLog(): ...@@ -154,7 +154,8 @@ def viewSoftwareLog():
# instance views # instance views
@login_required() @login_required()
def editInstanceProfile(): def editInstanceProfile():
profile = getProfilePath(app.config['etc_dir'], app.config['instance_profile']) # XXX-Cedric: adapt to new SlapOS Behavior
profile = getProfilePath(app.config['etc_dir'])
if profile == "": if profile == "":
flash('Error: can not open instance profile for this Software Release') flash('Error: can not open instance profile for this Software Release')
return render_template('updateInstanceProfile.html', workDir='workspace', return render_template('updateInstanceProfile.html', workDir='workspace',
...@@ -260,18 +261,10 @@ def cloneRepository(): ...@@ -260,18 +261,10 @@ def cloneRepository():
def readFolder(): def readFolder():
return getFolderContent(app.config, request.form['dir']) return getFolderContent(app.config, request.form['dir'])
@login_required()
def openFolder():
return getFolder(app.config, request.form['dir'])
@login_required() @login_required()
def createSoftware(): def createSoftware():
return newSoftware(request.form['folder'], app.config, session) return newSoftware(request.form['folder'], app.config, session)
@login_required()
def checkFolder():
return checkSoftwareFolder(request.form['path'], app.config)
@login_required() @login_required()
def setCurrentProject(): def setCurrentProject():
if configNewSR(app.config, request.form['path']): if configNewSR(app.config, request.form['path']):
...@@ -695,12 +688,10 @@ app.add_url_rule('/openProject/<method>', 'openProject', openProject, ...@@ -695,12 +688,10 @@ app.add_url_rule('/openProject/<method>', 'openProject', openProject,
app.add_url_rule("/manageProject", 'manageProject', manageProject, methods=['GET']) app.add_url_rule("/manageProject", 'manageProject', manageProject, methods=['GET'])
app.add_url_rule("/setCurrentProject", 'setCurrentProject', setCurrentProject, app.add_url_rule("/setCurrentProject", 'setCurrentProject', setCurrentProject,
methods=['POST']) methods=['POST'])
app.add_url_rule("/checkFolder", 'checkFolder', checkFolder, methods=['POST'])
app.add_url_rule('/createSoftware', 'createSoftware', createSoftware, app.add_url_rule('/createSoftware', 'createSoftware', createSoftware,
methods=['POST']) methods=['POST'])
app.add_url_rule('/cloneRepository', 'cloneRepository', cloneRepository, app.add_url_rule('/cloneRepository', 'cloneRepository', cloneRepository,
methods=['POST']) methods=['POST'])
app.add_url_rule('/openFolder', 'openFolder', openFolder, methods=['POST'])
app.add_url_rule('/readFolder', 'readFolder', readFolder, methods=['POST']) app.add_url_rule('/readFolder', 'readFolder', readFolder, methods=['POST'])
app.add_url_rule('/configRepo', 'configRepo', configRepo) app.add_url_rule('/configRepo', 'configRepo', configRepo)
app.add_url_rule("/saveParameterXml", 'saveParameterXml', saveParameterXml, app.add_url_rule("/saveParameterXml", 'saveParameterXml', saveParameterXml,
......
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