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 () {
var method = $("input#method").val(),
workdir = $("input#workdir").val();
function checkFolder(path) {
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + '/checkFolder',
data: "path=" + path,
success: function (data) {
var path = data.result;
$("input#path").val(path);
if (path !== "") {
/*
* Check if path is a .cfg (buildout profile) file.
**/
function isBuildoutFile(path) {
var suffix = '.cfg',
isBuildoutFile = path.indexOf(suffix, path.length - suffix.length) !== -1;
$("#check").fadeIn('normal');
if (isBuildoutFile) {
$("input#path").val(path);
} else {
$("input#path").val('');
$("#check").hide();
}
}
});
return "";
}
......@@ -31,7 +29,7 @@ $(document).ready(function () {
$("input#subfolder").val(file);
if (method === "open") {
$("#info").append("Selection: " + file);
checkFolder(file);
isBuildoutFile(file);
} else {
if ($("input#software").val() !== "" && $("input#software").val().match(/^[\w\d._\-]+$/)) {
$("#info").append("New Software in: " + file + $("input#software").val());
......@@ -43,7 +41,7 @@ $(document).ready(function () {
}
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);
});
}
......
......@@ -93,10 +93,9 @@ def getCurrentSoftwareReleaseProfile(config):
Returns used Software Release profile as a string.
"""
try:
software_folder = open(
software_profile_path = open(
os.path.join(config['etc_dir'], ".project")).read()
return realpath(
config, os.path.join(software_folder, config['software_profile']))
return realpath(config, software_profile_path)
except:
return False
......@@ -315,7 +314,7 @@ def runInstanceWithLock(config):
return True
return False
def getProfilePath(projectDir, profile):
def getProfilePath(projectDir):
"""
Return the path of the current Software Release `profile`
......@@ -329,7 +328,7 @@ def getProfilePath(projectDir, profile):
if not os.path.exists(os.path.join(projectDir, ".project")):
return False
projectFolder = open(os.path.join(projectDir, ".project")).read()
return os.path.join(projectFolder, profile)
return projectFolder
def getSlapStatus(config):
"""Return all Slapos Partitions with associate informations"""
......@@ -440,40 +439,6 @@ def getFolderContent(config, folder):
r.append('</ul>')
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):
"""Return the list of projet (folder) into the workspace
......@@ -524,6 +489,9 @@ def newSoftware(folder, config, session):
folder: directory of the new software release
config: slraprunner configuration
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 = ""
code = 0
basedir = config['etc_dir']
......@@ -559,13 +527,6 @@ def newSoftware(folder, config, session):
shutil.rmtree(folderPath)
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):
"""Generate the name of the current software Release (for slaprunner UI)"""
conf = os.path.join(config['etc_dir'], ".project")
......
......@@ -12,7 +12,7 @@ from flask import (Flask, request, redirect, url_for, render_template,
g, flash, jsonify, session, abort, send_file)
from slapos.runner.process import killRunningProcess
from slapos.runner.utils import (checkSoftwareFolder, configNewSR, getFolder,
from slapos.runner.utils import (configNewSR,
getFolderContent, getProfilePath,
getProjectList, getProjectTitle, getSession,
getSlapStatus, getSvcStatus,
......@@ -111,7 +111,7 @@ def doLogin():
# software views
@login_required()
def editSoftwareProfile():
profile = getProfilePath(app.config['etc_dir'], app.config['software_profile'])
profile = getProfilePath(app.config['etc_dir'])
if profile == "":
flash('Error: can not open profile, please select your project first')
return render_template('updateSoftwareProfile.html', workDir='workspace',
......@@ -154,7 +154,8 @@ def viewSoftwareLog():
# instance views
@login_required()
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 == "":
flash('Error: can not open instance profile for this Software Release')
return render_template('updateInstanceProfile.html', workDir='workspace',
......@@ -260,18 +261,10 @@ def cloneRepository():
def readFolder():
return getFolderContent(app.config, request.form['dir'])
@login_required()
def openFolder():
return getFolder(app.config, request.form['dir'])
@login_required()
def createSoftware():
return newSoftware(request.form['folder'], app.config, session)
@login_required()
def checkFolder():
return checkSoftwareFolder(request.form['path'], app.config)
@login_required()
def setCurrentProject():
if configNewSR(app.config, request.form['path']):
......@@ -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("/setCurrentProject", 'setCurrentProject', setCurrentProject,
methods=['POST'])
app.add_url_rule("/checkFolder", 'checkFolder', checkFolder, methods=['POST'])
app.add_url_rule('/createSoftware', 'createSoftware', createSoftware,
methods=['POST'])
app.add_url_rule('/cloneRepository', 'cloneRepository', cloneRepository,
methods=['POST'])
app.add_url_rule('/openFolder', 'openFolder', openFolder, methods=['POST'])
app.add_url_rule('/readFolder', 'readFolder', readFolder, methods=['POST'])
app.add_url_rule('/configRepo', 'configRepo', configRepo)
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