Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
56f7386bc6b9
Commit
38a3d96e
authored
May 21, 2019
by
Laurent Peuch
Browse files
[cubicweb-ctl] backport --dbglevel option of pyramid to all instance commands
Closes #17219653
parent
5add82b08a6d
Changes
4
Hide whitespace changes
Inline
Side-by-side
cubicweb/cwctl.py
View file @
56f7386b
...
...
@@ -42,10 +42,12 @@ from logilab.common.decorators import clear_cache
from
cubicweb
import
ConfigurationError
,
ExecutionError
,
BadCommandUsage
from
cubicweb.cwconfig
import
CubicWebConfiguration
as
cwcfg
,
CONFIGURATIONS
from
cubicweb.server
import
set_debug
from
cubicweb.toolsutils
import
Command
,
rm
,
create_dir
,
underline_title
from
cubicweb.__pkginfo__
import
version
as
cw_version
LOG_LEVELS
=
(
'debug'
,
'info'
,
'warning'
,
'error'
)
DBG_FLAGS
=
(
'RQL'
,
'SQL'
,
'REPO'
,
'HOOKS'
,
'OPS'
,
'SEC'
,
'MORE'
)
# don't check duplicated commands, it occurs when reloading site_cubicweb
CWCTL
=
CommandLine
(
'cubicweb-ctl'
,
'The CubicWeb swiss-knife.'
,
...
...
@@ -136,6 +138,13 @@ class InstanceCommand(Command):
%
(
', '
.
join
(
LOG_LEVELS
)),
}
),
(
'dbglevel'
,
{
'type'
:
'multiple_choice'
,
'metavar'
:
'<debug level>'
,
'default'
:
None
,
'choices'
:
DBG_FLAGS
,
'help'
:
(
'Set the server debugging flags; you may choose several '
'values in %s; imply "debug" loglevel if loglevel is not set'
%
(
DBG_FLAGS
,)),
}),
)
actionverb
=
None
...
...
@@ -157,10 +166,17 @@ class InstanceCommand(Command):
# certain situations if it's not explicitly set by the user and we want
# to detect that (the "None" case)
if
self
[
'loglevel'
]
is
None
:
init_cmdline_log_threshold
(
self
.
cwconfig
,
'error'
)
# if no loglevel is set but dbglevel is here we want to set level to debug
if
self
[
'dbglevel'
]:
init_cmdline_log_threshold
(
self
.
cwconfig
,
'debug'
)
else
:
init_cmdline_log_threshold
(
self
.
cwconfig
,
'error'
)
else
:
init_cmdline_log_threshold
(
self
.
cwconfig
,
self
[
'loglevel'
])
if
self
[
'dbglevel'
]:
set_debug
(
'|'
.
join
(
'DBG_'
+
x
.
upper
()
for
x
in
self
[
'dbglevel'
]))
try
:
status
=
cmdmeth
(
appid
)
or
0
except
(
ExecutionError
,
ConfigurationError
)
as
ex
:
...
...
cubicweb/pyramid/pyramidctl.py
View file @
56f7386b
...
...
@@ -37,7 +37,7 @@ from logilab.common.configuration import merge_options
from
cubicweb.cwctl
import
CWCTL
,
InstanceCommand
,
init_cmdline_log_threshold
from
cubicweb.pyramid
import
wsgi_application_from_cwconfig
from
cubicweb.pyramid.config
import
get_random_secret_key
from
cubicweb.server
import
serverctl
,
set_debug
from
cubicweb.server
import
serverctl
from
cubicweb.web.webctl
import
WebCreateHandler
from
cubicweb.toolsutils
import
fill_templated_file
...
...
@@ -45,8 +45,6 @@ import waitress
MAXFD
=
1024
DBG_FLAGS
=
(
'RQL'
,
'SQL'
,
'REPO'
,
'HOOKS'
,
'OPS'
,
'SEC'
,
'MORE'
)
def
_generate_pyramid_ini_file
(
pyramid_ini_path
):
"""Write a 'pyramid.ini' file into apphome."""
...
...
@@ -107,13 +105,6 @@ class PyramidStartHandler(InstanceCommand):
(
'reload-interval'
,
{
'type'
:
'int'
,
'default'
:
1
,
'help'
:
'Interval, in seconds, between file modifications checks'
}),
(
'dbglevel'
,
{
'type'
:
'multiple_choice'
,
'metavar'
:
'<dbg level>'
,
'default'
:
None
,
'choices'
:
DBG_FLAGS
,
'help'
:
(
'Set the server debugging flags; you may choose several '
'values in %s; imply "debug" loglevel'
%
(
DBG_FLAGS
,)),
}),
(
'profile'
,
{
'action'
:
'store_true'
,
'default'
:
False
,
...
...
@@ -260,12 +251,9 @@ class PyramidStartHandler(InstanceCommand):
self
[
'reload-interval'
],
extra_files
,
filelist_path
=
filelist_path
)
if
self
[
'dbglevel'
]:
set_debug
(
'|'
.
join
(
'DBG_'
+
x
.
upper
()
for
x
in
self
[
'dbglevel'
]))
# if no loglevel is specified and --debug or --dbglevel are here, set log level at debug
if
self
[
'loglevel'
]
is
None
and
(
self
[
'debug'
]
or
self
[
'dbglevel'
]):
init_cmdline_log_threshold
(
cwconfig
,
'debug'
)
# if no loglevel is specified and --debug is here, set log level at debug
if
self
[
'loglevel'
]
is
None
and
self
[
'debug'
]:
init_cmdline_log_threshold
(
self
.
cwconfig
,
'debug'
)
app
=
wsgi_application_from_cwconfig
(
cwconfig
,
profile
=
self
[
'profile'
],
...
...
cubicweb/test/unittest_cwctl.py
View file @
56f7386b
...
...
@@ -24,7 +24,7 @@ from unittest.mock import patch, MagicMock
from
logilab.common.clcommands
import
CommandLine
from
cubicweb
import
cwctl
from
cubicweb
import
cwctl
,
server
from
cubicweb.cwctl
import
ListCommand
,
InstanceCommand
from
cubicweb.devtools.testlib
import
CubicWebTC
from
cubicweb.server.migractions
import
ServerMigrationHelper
...
...
@@ -112,9 +112,9 @@ class InstanceCommandTest(unittest.TestCase):
self
.
fake_config
.
global_set_option
=
MagicMock
()
# pretend that this instance exists
patcher
=
patch
.
object
(
cwcfg
,
'config_for'
,
return_value
=
self
.
fake_config
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
config_
patcher
=
patch
.
object
(
cwcfg
,
'config_for'
,
return_value
=
self
.
fake_config
)
config_
patcher
.
start
()
self
.
addCleanup
(
config_
patcher
.
stop
)
@
patch
.
object
(
_TestCommand
,
'test_instance'
,
return_value
=
0
)
def
test_getting_called
(
self
,
test_instance
):
...
...
@@ -181,6 +181,20 @@ class InstanceCommandTest(unittest.TestCase):
self
.
fake_config
.
global_set_option
.
assert_called_with
(
'log-threshold'
,
log_level
.
upper
())
@
patch
.
object
(
server
,
"DEBUG"
,
0
)
def
test_set_dblevel
(
self
):
DBG_FLAGS
=
(
'RQL'
,
'SQL'
,
'REPO'
,
'HOOKS'
,
'OPS'
,
'SEC'
,
'MORE'
)
total_value
=
0
for
dbg_flag
in
DBG_FLAGS
:
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
self
.
CWCTL
.
run
([
"test"
,
"some_instance"
,
"--dbglevel"
,
dbg_flag
])
self
.
assertEqual
(
cm
.
exception
.
code
,
0
)
total_value
+=
getattr
(
server
,
"DBG_%s"
%
dbg_flag
)
self
.
assertEqual
(
total_value
,
server
.
DEBUG
)
if
__name__
==
'__main__'
:
unittest
.
main
()
doc/changes/3.27.rst
View file @
56f7386b
...
...
@@ -20,8 +20,8 @@ New features
* add a --pdb flag to all cubicweb-ctl command to launch (i)pdb if an exception
occurs during a command execution.
* the --loglevel
flag is
available for all cubicweb-ctl
instance commands (and
not only the ``pyramid`` one)
* the --loglevel
and --dbglevel flags are
available for all cubicweb-ctl
instance commands (and
not only the ``pyramid`` one)
Backwards incompatible changes
------------------------------
...
...
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