Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
72ce6adc
Commit
72ce6adc
authored
Sep 10, 2015
by
LE GAC Renaud
Browse files
Polish the script run.
parent
ebdec501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
33 deletions
+39
-33
scripts/run
scripts/run
+39
-33
No files found.
scripts/run
View file @
72ce6adc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" NAME
run -- run a script or test within t
rack_publications
run -- run a script or
python
test
s
within t
he application framework
SYNOPSIS
run [options] <command> [args]
DESCRIPTION
The
run
command has to be run in the scripts directory
It can execute two commands script and pytest.
The command has to be run in the scripts directory
It can execute two
sub
commands
'
script
'
and
'
pytest
'
.
The first command
, script,
run a given script in the application
The first
sub
command run
s
a given script in the application
context (model, modules and database are available).
The second command
, pytest,
run python
s
test within the pytest
framework a
s well as
the application context.
The second
sub
command run
s
python test
s
within the pytest
framework a
nd
the application context.
The python tests are located in the directory myapplication/tests.
The scripts are located in myapplication/scripts.
The path of the test are relative to that directory.
OPTIONS
...
...
@@ -38,7 +39,7 @@
> ./run pytest -h
> ./run pytest
> ./run pytest -xq test_foo/test_faa.py
> ./run pytest -xq test_foo/test_faa.py
::test_fii
> ...
AUTHOR
...
...
@@ -69,6 +70,33 @@ def get_application():
return
os
.
getcwd
().
split
(
os
.
sep
)[
-
2
]
def
process
(
application
,
script
,
args
):
"""Process the script within the framework of the application
Args:
application (str): the name of the application
script (str): filename for the script
args (str): optional argument to be passed to the script
Returns:
int: return code of the subprocess
"""
script_path
=
os
.
path
.
join
(
os
.
getcwd
(),
script
)
cmd
=
[
WEB2PY
,
'--no-banner'
,
'--shell'
,
application
,
'--import_models'
,
'--run'
,
script_path
]
if
args
:
cmd
.
extend
([
'--args'
,
args
])
return
subprocess
.
call
(
cmd
)
def
run_pytest
(
args
):
"""Run python test.
...
...
@@ -95,16 +123,7 @@ def run_pytest(args):
cmd
=
"%s %s"
%
(
cmd
,
path
)
# run pytest script in the application context
script_path
=
os
.
path
.
join
(
os
.
getcwd
(),
PYTEST_SCRIPT
)
cmd
=
[
WEB2PY
,
'--no-banner'
,
'--shell'
,
args
.
shell
,
'--import_models'
,
'--run'
,
script_path
,
'--args'
,
cmd
]
return_code
=
subprocess
.
call
(
cmd
)
return_code
=
process
(
args
.
shell
,
PYTEST_SCRIPT
,
cmd
)
sys
.
exit
(
return_code
)
...
...
@@ -112,20 +131,7 @@ def run_script(args):
"""Run the given script.
"""
# run the script in the application context
script_path
=
os
.
path
.
join
(
os
.
getcwd
(),
args
.
filename
)
cmd
=
[
WEB2PY
,
'--no-banner'
,
'--shell'
,
args
.
shell
,
'--import_models'
,
'--run'
,
script_path
]
if
args
.
args
:
cmd
.
append
(
'--ARGS'
)
cmd
.
extend
(
args
.
args
)
return_code
=
subprocess
.
call
(
cmd
)
return_code
=
process
(
args
.
shell
,
args
.
filename
,
args
.
args
)
sys
.
exit
(
return_code
)
...
...
@@ -187,8 +193,8 @@ if __name__ == "__main__":
help
=
"the name of the python script."
)
SCRIPT
.
add_argument
(
"args"
,
nargs
=
"
*
"
,
help
=
"additional arguments to
run
the script."
)
nargs
=
"
?
"
,
help
=
"additional arguments to
be passed to
the script."
)
SCRIPT
.
set_defaults
(
func
=
run_script
)
...
...
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