Commit b0c0d799 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: first commit for the mini-shell integration

parent af15ba13
......@@ -28,6 +28,7 @@
.swith_btn{background: url(../images/gnome-session-switch.png) center right no-repeat;width: 105px;}
.flist_btn{background: url(../images/list2_down.png) center right no-repeat;width: 26px;}
.fmenu_btn{background: url(../images/ui_menu_blue.png) center right no-repeat;width: 58px;}
.shell_btn{background: url(../images/terminal.png) center right no-repeat;width: 62px;}
#tabControl{overflow: hidden;}
#tabControl .item{float:left; min-width: 60px; background: #D5D5D5; height: 22px; padding-top: 8px; font-size:1em;
......@@ -43,4 +44,29 @@ border-left:1px #E4E4E4 solid; cursor:pointer; color: #5C7077; text-shadow: 0px
#tabContent pre.active {display: block;}
.item-hide{display:none;}
#shell-window {
width: 978px;
height: 350px;
z-index: 10;
border: 2px solid #6A93A0;
border-top: none;
border-left: none;
background: #7FAED3;
position: absolute;
display: none;
}
#shell-result {
width: 98%;
height: 300px;
margin-left: 1%;
margin-right: 1%;
box-sizing: border-box;
padding: 3px;
}
#shell-input {
width: 97%;
margin-left: 1%;
margin-right: 1%;
position: absolute;
bottom: 10px;
}
/*jslint undef: true */
/*global $, document, $SCRIPT_ROOT, window */
/*global path: true */
/* vim: set et sts=4: */
$(document).ready(function () {
"use strict";
$("#shell").click (function() {
$("#shell-window").slideToggle("fast");
if ( $("#shell-window").is(':visible') ) {
$("#shell-input").focus();
}
});
$("#shell-input").keypress(function (event) {
if(event.which === 13) {
var command = $("#shell-input").val();
event.preventDefault();
var data = { command: command };
$.post("/runCommand", data, function (data) {
data = ">>> " + command + "\n\n" + data;
$("#shell-result").val(data);
$("#shell-input").val("");
});
}
});
});
......@@ -10,6 +10,7 @@
<link href="{{ url_for('static', filename='css/colorbox.css', _external=False) }}" rel="stylesheet" type="text/css" media="screen" />
<script src="{{ url_for('static', filename='js/jquery/jquery.colorbox-min.js') }}" type="application/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/scripts/softwareFolder.js') }}" type="application/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/scripts/shell.js') }}" type="application/javascript" charset="utf-8"></script>
{% endblock %}
{% block body %}
<style>
......@@ -50,11 +51,18 @@
<li id="fullscreen"><span class="expand_editor" title="Show Editor in Full window. Hint: Use Ctrl+E">&nbsp;</span></li>
<li id="save"><span class="save_btn" title="Save current file. Hint: Use Ctrl+S">&nbsp;</span></li>
<li id="option"><span class="fmenu_btn" title='Show more options' rel='tooltip'>Menu</span></li>
<li id="shell"><span class="shell_btn" title="Run a command in a shell">Shell</span></li>
</ul>
<div id="tabControl"></div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div id="shell-window">
<textarea id="shell-result" cols="80" readonly>
</textarea>
<input type="text" name="command" id="shell-input" />
</div>
<div class="clear"></div>
<div class="software_details">
<div id="details_box">
<div id="fileTree" class="file_tree_short"></div>
......
......@@ -6,6 +6,7 @@
import json
import os
import shutil
import subprocess
import thread
import urllib
......@@ -706,6 +707,34 @@ def isSRReady():
return isSoftwareReleaseReady(app.config)
def runCommand():
cwd = open(app.config['minishell_cwd_file'], 'r').read().strip()
command = request.form.get("command", '').strip()
parsed_commands = command.split(';');
# does the user want to change current directory ?
for cmd in parsed_commands:
if 'cd' == cmd[:2]:
cmd = cmd.split(' ');
if len(cmd) == 1:
cmd.append(os.environ.get('HOME'))
# shorten directory's name, to avoid things like : /a/../b
cd_dir = os.path.realpath(os.path.join(cwd, cmd[1]))
if os.path.exists(cd_dir):
cwd = cd_dir
# save new cwd in the config file
open(app.config['minishell_cwd_file'], 'w').write(cwd)
# if the command was just cd, execute it. Otherwise, execute the rest
command = command.replace(' '.join(cmd), '').strip(';')
if not command:
return "Changed directory, now in : " + cwd
try:
return subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True, cwd=cwd)
except subprocess.CalledProcessError as e:
error = "Error : process exited with exit code " + str(e.returncode) + \
"\nProcess says :\n" + e.output
return error
#Setup List of URLs
app.add_url_rule('/', 'home', home)
app.add_url_rule('/browseWorkspace', 'browseWorkspace', browseWorkspace)
......@@ -789,3 +818,4 @@ app.add_url_rule('/shell', 'shell', shell)
app.add_url_rule('/isSRReady', 'isSRReady', isSRReady)
app.add_url_rule('/addUser', 'addUser', addUser, methods=['POST'])
app.add_url_rule('/getSlapgridParameters', 'getSlapgridParameters', getSlapgridParameters, methods=['GET'])
app.add_url_rule('/runCommand', 'runCommand', runCommand, methods=['POST'])
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