Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Ivan Tyagov
slapos.core
Commits
64879137
Commit
64879137
authored
Mar 22, 2023
by
Joanne Hugé
Committed by
Thomas Gambier
Mar 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: support args when passing a script file
parent
92b93714
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
slapos/cli/console.py
slapos/cli/console.py
+9
-6
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+9
-0
No files found.
slapos/cli/console.py
View file @
64879137
...
...
@@ -27,6 +27,7 @@
#
##############################################################################
import
sys
import
textwrap
from
slapos.cli.config
import
ClientConfigCommand
...
...
@@ -81,8 +82,8 @@ class ConsoleCommand(ClientConfigCommand):
action
=
'store_true'
,
help
=
'Use plain Python shell'
)
shell
.
add_argument
(
'script_file
'
,
nargs
=
'?
'
,
help
=
'Script to run
'
)
shell
.
add_argument
(
'script_file
_and_arguments'
,
nargs
=
'*
'
,
help
=
'Script to run
, with arguments'
,
default
=
[]
)
return
ap
...
...
@@ -91,10 +92,12 @@ class ConsoleCommand(ClientConfigCommand):
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
,
self
.
app
.
log
)
if
args
.
script_file
:
with
open
(
args
.
script_file
)
as
f
:
code
=
compile
(
f
.
read
(),
args
.
script_file
,
'exec'
)
local
[
'__file__'
]
=
args
.
script_file
if
args
.
script_file_and_arguments
:
script_file
=
args
.
script_file_and_arguments
[
0
]
with
open
(
script_file
)
as
f
:
code
=
compile
(
f
.
read
(),
script_file
,
'exec'
)
local
[
'__file__'
]
=
script_file
sys
.
argv
=
args
.
script_file_and_arguments
return
exec_
(
code
,
local
,
local
)
if
not
any
([
args
.
python
,
args
.
ipython
,
args
.
bpython
]):
...
...
slapos/tests/test_cli.py
View file @
64879137
...
...
@@ -874,6 +874,15 @@ print(request('software_release', 'instance').getInstanceParameterDict()['parame
app
.
run
((
'console'
,
'--cfg'
,
config_file
,
script
.
name
))
self
.
assertIn
(
'OK __file__ is set to script'
,
stdout
.
getvalue
())
def
test_console_script_and_args
(
self
):
with
self
.
_test_console
()
as
(
app
,
config_file
,
mock_request
,
stdout
),
\
tempfile
.
NamedTemporaryFile
(
'w'
)
as
script
:
script
.
write
(
'import sys; print(sys.argv)'
)
script
.
flush
()
app
.
run
((
'console'
,
'--cfg'
,
config_file
,
script
.
name
,
'arg1'
,
'arg2'
))
self
.
assertEqual
(
stdout
.
getvalue
().
strip
(),
str
([
script
.
name
,
'arg1'
,
'arg2'
]))
class
TestCliComplete
(
CliMixin
):
def
test_complete_bash
(
self
):
...
...
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