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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
699603e5
Commit
699603e5
authored
Dec 09, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli: make resetLogger a context manager restoring the state
parent
127ff568
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
48 deletions
+58
-48
slapos/cli/cache_pypi.py
slapos/cli/cache_pypi.py
+3
-3
slapos/cli/cache_url.py
slapos/cli/cache_url.py
+3
-3
slapos/cli/command.py
slapos/cli/command.py
+14
-2
slapos/cli/computer_info.py
slapos/cli/computer_info.py
+11
-12
slapos/cli/computer_list.py
slapos/cli/computer_list.py
+8
-8
slapos/cli/computer_token.py
slapos/cli/computer_token.py
+10
-11
slapos/cli/info.py
slapos/cli/info.py
+2
-2
slapos/cli/list.py
slapos/cli/list.py
+7
-7
No files found.
slapos/cli/cache_pypi.py
View file @
699603e5
...
...
@@ -86,9 +86,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
logger
.
info
(
'Python egg %s version %s'
,
name
,
version
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
resetLogger
(
logger
)
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
with
resetLogger
(
logger
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
except
HTTPError
as
e
:
if
e
.
code
==
404
:
logger
.
info
(
'Object not found in cache.'
)
...
...
slapos/cli/cache_url.py
View file @
699603e5
...
...
@@ -84,9 +84,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
logger
.
info
(
'Software source URL: %s'
,
url
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
resetLogger
(
logger
)
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
with
resetLogger
(
logger
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
except
HTTPError
as
e
:
if
e
.
code
==
404
:
logger
.
info
(
'Object not found in cache.'
)
...
...
slapos/cli/command.py
View file @
699603e5
...
...
@@ -28,6 +28,7 @@
##############################################################################
import
argparse
import
contextlib
import
functools
import
logging
import
os
...
...
@@ -36,9 +37,20 @@ import sys
from
cliff
import
command
@
contextlib
.
contextmanager
def
resetLogger
(
logger
):
logger
.
propagate
=
False
logger
.
addHandler
(
logging
.
StreamHandler
(
sys
.
stdout
))
has_propagate
=
hasattr
(
logger
,
'propagate'
)
# XXX mocked Loggers do not have this
if
has_propagate
:
propagate
=
logger
.
propagate
logger
.
propagate
=
False
stdout_handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
logger
.
addHandler
(
stdout_handler
)
try
:
yield
finally
:
if
has_propagate
:
logger
.
propagate
=
propagate
logger
.
removeHandler
(
stdout_handler
)
class
Command
(
command
.
Command
):
...
...
slapos/cli/computer_info.py
View file @
699603e5
...
...
@@ -58,16 +58,15 @@ class InfoCommand(ClientConfigCommand):
def
do_info
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
try
:
computer
=
local
[
'slap'
].
registerComputer
(
conf
.
reference
).
getInformation
()
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
logger
.
info
(
'Computer Reference: %s'
,
computer
.
_reference
)
logger
.
info
(
'Computer Title : %s'
,
computer
.
_title
)
with
resetLogger
(
logger
):
try
:
computer
=
local
[
'slap'
].
registerComputer
(
conf
.
reference
).
getInformation
()
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
logger
.
info
(
'Computer Reference: %s'
,
computer
.
_reference
)
logger
.
info
(
'Computer Title : %s'
,
computer
.
_title
)
slapos/cli/computer_list.py
View file @
699603e5
...
...
@@ -51,11 +51,11 @@ class ListCommand(ClientConfigCommand):
def
do_list
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
computer_dict
=
local
[
'slap'
].
getComputerDict
()
if
computer_dict
==
{}:
logger
.
info
(
'No existing computer.'
)
return
logger
.
info
(
'List of Computers:'
)
for
title
,
computer
in
six
.
iteritems
(
computer_dict
):
logger
.
info
(
'%s %s'
,
computer
.
_reference
,
title
)
with
resetLogger
(
logger
):
computer_dict
=
local
[
'slap'
].
getComputerDict
()
if
computer_dict
==
{}:
logger
.
info
(
'No existing computer.'
)
return
logger
.
info
(
'List of Computers:'
)
for
title
,
computer
in
six
.
iteritems
(
computer_dict
):
logger
.
info
(
'%s %s'
,
computer
.
_reference
,
title
)
slapos/cli/computer_token.py
View file @
699603e5
...
...
@@ -54,15 +54,14 @@ class TokenCommand(ClientConfigCommand):
def
do_token
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
try
:
token
=
local
[
'slap'
].
registerToken
().
request
()
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
logger
.
info
(
'Computer token: %s'
,
token
)
with
resetLogger
(
logger
):
try
:
token
=
local
[
'slap'
].
registerToken
().
request
()
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
logger
.
info
(
'Computer token: %s'
,
token
)
slapos/cli/info.py
View file @
699603e5
...
...
@@ -70,7 +70,6 @@ class InfoCommand(ClientConfigCommand):
def
do_info
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
try
:
instance
=
local
[
'slap'
].
registerOpenOrder
().
getInformation
(
partition_reference
=
conf
.
reference
,
...
...
@@ -126,5 +125,6 @@ def do_info(logger, conf, local):
if
conf
.
news
:
info
[
'news'
]
=
news
logger
.
info
(
json
.
dumps
(
info
,
indent
=
2
))
with
resetLogger
(
logger
):
logger
.
info
(
json
.
dumps
(
info
,
indent
=
2
))
slapos/cli/list.py
View file @
699603e5
...
...
@@ -52,12 +52,12 @@ class ListCommand(ClientConfigCommand):
def
do_list
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
# XXX catch exception
instance_dict
=
local
[
'slap'
].
getOpenOrderDict
()
logger
.
info
(
json
.
dumps
(
{
title
:
instance
.
_software_release_url
for
(
title
,
instance
)
in
six
.
iteritems
(
instance_dict
)},
sort_keys
=
True
,
indent
=
2
))
with
resetLogger
(
logger
):
logger
.
info
(
json
.
dumps
(
{
title
:
instance
.
_software_release_url
for
(
title
,
instance
)
in
six
.
iteritems
(
instance_dict
)},
sort_keys
=
True
,
indent
=
2
))
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