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
Xavier Thompson
slapos.core
Commits
e06180e0
Commit
e06180e0
authored
Oct 27, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: WIP: add some logs and fix errors
parent
d8846274
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
slapos/format.py
slapos/format.py
+31
-9
No files found.
slapos/format.py
View file @
e06180e0
...
...
@@ -42,6 +42,9 @@ from netifaces import AF_INET, AF_INET6
def
do_format
(
conf
):
# starting logs
conf
.
logStartInfo
()
# wrap system calls for tracing and dry-run
with
WrappedSystem
(
conf
):
# load configuration
computer
=
Computer
(
conf
)
...
...
@@ -118,33 +121,45 @@ class FormatConfig(Parameters, Options):
def
__init__
(
self
,
logger
):
self
.
logger
=
logger
def
wrong
(
self
,
fmt
,
*
args
):
return
self
.
error
(
fmt
,
*
args
,
exc
=
UsageError
)
def
error
(
self
,
fmt
,
*
args
):
message
=
fmt
%
tuple
(
args
)
self
.
logger
.
error
(
message
)
raise
UsageError
(
message
)
raise
ValueError
(
message
)
def
warn
(
self
,
fmt
,
*
args
):
self
.
logger
.
warning
(
fmt
,
*
args
)
def
info
(
self
,
fmt
,
*
args
):
self
.
logger
.
info
(
fmt
,
*
args
)
def
debug
(
self
,
fmt
,
*
args
):
self
.
logger
.
debug
(
fmt
,
*
args
)
def
parse
(
self
,
name
,
value
,
t
):
if
not
isinstance
(
value
,
str
):
if
type
(
value
).
__name__
!=
t
and
value
is
not
None
:
self
.
error
(
"Option %s takes type %s, not %r"
,
name
,
t
,
value
)
self
.
wrong
(
"Option %s takes type %s, not %r"
,
name
,
t
,
value
)
return
value
if
t
==
'int'
:
try
:
return
int
(
value
)
except
ValueError
:
self
.
error
(
"Option %s takes type %s, not %r"
,
name
,
t
,
value
)
self
.
wrong
(
"Option %s takes type %s, not %r"
,
name
,
t
,
value
)
if
t
==
'bool'
:
try
:
return
bool
((
'false'
,
'true'
).
index
(
value
.
lower
()))
except
IndexError
:
self
.
error
(
"Option %r must be 'true' or 'false', not %r"
,
name
,
value
)
self
.
wrong
(
"Option %r must be 'true' or 'false', not %r"
,
name
,
value
)
return
value
def
get
(
self
,
option
):
try
:
return
getattr
(
self
,
option
)
except
AttributeError
:
self
.
error
(
"Parameter %r is not defined"
,
option
)
self
.
wrong
(
"Parameter %r is not defined"
,
option
)
def
mergeConfig
(
self
,
args
,
configp
):
# args (from command line) override configp (from cfg) options
...
...
@@ -157,14 +172,14 @@ class FormatConfig(Parameters, Options):
for
option
in
self
.
DEPRECATED
:
if
option
in
self
.
__dict__
:
if
option
==
'computer_xml'
:
self
.
error
(
self
.
wrong
(
"Option %r is no longer supported
\
n
"
"Use --output_definition_file to migrate existing computer_xml"
", then use the generated file as input_definition_file"
,
option
)
else
:
self
.
error
(
"Option %r is no longer supported"
%
option
)
self
.
wrong
(
"Option %r is no longer supported"
%
option
)
# Mandatory parameters
for
option
,
t
in
Parameters
.
__annotations__
.
items
():
setattr
(
self
,
option
,
self
.
parse
(
option
,
self
.
get
(
option
),
t
))
...
...
@@ -176,15 +191,22 @@ class FormatConfig(Parameters, Options):
path
=
getattr
(
self
,
option
)
if
path
:
if
not
os
.
path
.
exists
(
path
):
self
.
error
(
"File %r does not exist or is not readable"
,
path
)
self
.
wrong
(
"File %r does not exist or is not readable"
,
path
)
setattr
(
self
,
option
,
os
.
path
.
abspath
(
path
))
# Paths normalization
for
option
in
self
.
NORMALIZE_PATHS
:
path
=
getattr
(
self
,
option
)
if
path
:
setattr
(
self
,
option
,
os
.
path
.
abspath
(
path
))
# XXX Check command line tools
def
logStartInfo
(
self
):
if
self
.
dry_run
:
self
.
logger
.
info
(
"Starting run in dry-run mode"
)
else
:
self
.
logger
.
info
(
"Starting run"
)
# XXX more logs
# XXX Check command line tools + Logs
class
Definition
(
defaultdict
):
...
...
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