Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.toolbox
Commits
9a7a2f32
Commit
9a7a2f32
authored
Aug 05, 2014
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runner: minishell has an history
parent
4c36ce04
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
3 deletions
+67
-3
slapos/runner/static/js/scripts/shell.js
slapos/runner/static/js/scripts/shell.js
+39
-2
slapos/runner/templates/softwareFolder.html
slapos/runner/templates/softwareFolder.html
+1
-1
slapos/runner/utils.py
slapos/runner/utils.py
+14
-0
slapos/runner/views.py
slapos/runner/views.py
+13
-0
No files found.
slapos/runner/static/js/scripts/shell.js
View file @
9a7a2f32
...
...
@@ -3,9 +3,21 @@
/*global path: true */
/* vim: set et sts=4: */
var
shellHistory
=
""
;
var
currentCommand
=
0
;
$
(
document
).
ready
(
function
()
{
"
use strict
"
;
var
updateHistory
=
function
()
{
$
.
getJSON
(
"
/getMiniShellHistory
"
,
function
(
data
)
{
shellHistory
=
data
;
currentCommand
=
shellHistory
.
length
;
});
};
updateHistory
();
$
(
"
#shell
"
).
click
(
function
()
{
$
(
"
#shell-window
"
).
slideToggle
(
"
fast
"
);
if
(
$
(
"
#shell-window
"
).
is
(
'
:visible
'
)
)
{
...
...
@@ -14,15 +26,40 @@ $(document).ready(function () {
});
$
(
"
#shell-input
"
).
keypress
(
function
(
event
)
{
//if Enter is pressed
if
(
event
.
which
===
13
)
{
var
command
=
$
(
"
#shell-input
"
).
val
();
event
.
preventDefault
();
var
command
=
$
(
"
#shell-input
"
).
val
();
var
data
=
{
command
:
command
};
$
.
post
(
"
/runCommand
"
,
data
,
function
(
data
)
{
data
=
"
>>>
"
+
command
+
"
\n\n
"
+
data
;
$
(
"
#shell-result
"
).
val
(
data
);
$
(
"
#shell-input
"
).
val
(
""
);
updateHistory
();
});
}
});
$
(
"
#shell-input
"
).
keydown
(
function
(
event
)
{
//if Key Up is pressed
if
(
event
.
which
==
38
)
{
event
.
preventDefault
();
currentCommand
--
;
if
(
currentCommand
<=
0
)
currentCommand
=
0
;
$
(
"
#shell-input
"
).
val
(
shellHistory
[
currentCommand
]);
}
//if Key Down is pressed
if
(
event
.
which
===
40
)
{
event
.
preventDefault
();
currentCommand
++
;
if
(
currentCommand
>
shellHistory
.
length
)
{
currentCommand
=
shellHistory
.
length
;
$
(
"
#shell-input
"
).
val
(
""
);
}
else
{
$
(
"
#shell-input
"
).
val
(
shellHistory
[
currentCommand
]);
}
}
});
});
slapos/runner/templates/softwareFolder.html
View file @
9a7a2f32
...
...
@@ -60,7 +60,7 @@
<div
id=
"shell-window"
>
<textarea
id=
"shell-result"
cols=
"80"
readonly
>
</textarea>
<input
type=
"text"
name=
"command"
id=
"shell-input"
/>
<input
type=
"text"
name=
"command"
id=
"shell-input"
autocomplete=
"off"
/>
</div>
<div
class=
"clear"
></div>
<div
class=
"software_details"
>
...
...
slapos/runner/utils.py
View file @
9a7a2f32
...
...
@@ -926,3 +926,17 @@ def setupDefaultSR(config):
configNewSR(config, config['
default_sr
'])
if config['
auto_deploy
']:
thread.start_new_thread(buildAndRun, (config,))
def setMiniShellHistory(config, command):
history_max_size = 10
command = command + "
\
n
"
history_file = config['
minishell_history_file
']
if os.path.exists(history_file):
history = open(history_file, 'r').readlines()
if len(history) >= history_max_size:
del history[0]
else:
history = []
history.append(command)
open(history_file, '
w
+
').write(''.join(history))
slapos/runner/views.py
View file @
9a7a2f32
...
...
@@ -28,6 +28,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR,
removeSoftwareByName
,
runInstanceWithLock
,
runSoftwareWithLock
,
runSlapgridUntilSuccess
,
saveSession
,
saveBuildAndRunParams
,
setMiniShellHistory
,
svcStartStopProcess
,
svcStopAll
,
tail
,
updateInstanceParameter
)
...
...
@@ -728,6 +729,7 @@ def runCommand():
if
not
command
:
return
"Changed directory, now in : "
+
cwd
try
:
setMiniShellHistory
(
app
.
config
,
command
)
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
)
+
\
...
...
@@ -735,6 +737,16 @@ def runCommand():
return
error
def
getMiniShellHistory
():
history_file
=
app
.
config
[
'minishell_history_file'
]
if
not
os
.
path
.
exists
(
history_file
):
return
""
history
=
open
(
history_file
,
'r'
).
readlines
()
for
line
,
text
in
enumerate
(
history
):
history
[
line
]
=
text
.
strip
()
return
json
.
dumps
(
history
)
#Setup List of URLs
app
.
add_url_rule
(
'/'
,
'home'
,
home
)
app
.
add_url_rule
(
'/browseWorkspace'
,
'browseWorkspace'
,
browseWorkspace
)
...
...
@@ -819,3 +831,4 @@ 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'
])
app
.
add_url_rule
(
"/getMiniShellHistory"
,
'getMiniShellHistory'
,
getMiniShellHistory
,
methods
=
[
'GET'
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment