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
Carlos Ramos Carreño
slapos.core
Commits
e2ca58dc
Commit
e2ca58dc
authored
May 02, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node format: set up log handler from config
parent
0f3198ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
17 deletions
+32
-17
slapos/cli/format.py
slapos/cli/format.py
+12
-2
slapos/cli_legacy/format.py
slapos/cli_legacy/format.py
+17
-1
slapos/format.py
slapos/format.py
+3
-14
No files found.
slapos/cli/format.py
View file @
e2ca58dc
...
...
@@ -14,7 +14,7 @@ class FormatCommand(ConfigCommand):
create users, partitions and network configuration
"""
log
=
logging
.
getLogger
(
'
slap
format'
)
log
=
logging
.
getLogger
(
'format'
)
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
FormatCommand
,
self
).
get_parser
(
prog_name
)
...
...
@@ -65,8 +65,18 @@ class FormatCommand(ConfigCommand):
conf
=
FormatConfig
(
logger
=
self
.
log
)
conf
.
mergeConfig
(
args
,
configp
)
if
not
args
.
log_file
and
conf
.
log_file
:
# no log file is provided by argparser,
# we set up the one from config
file_handler
=
logging
.
FileHandler
(
conf
.
log_file
)
formatter
=
logging
.
Formatter
(
self
.
app
.
LOG_FILE_MESSAGE_FORMAT
)
file_handler
.
setFormatter
(
formatter
)
self
.
log
.
addHandler
(
file_handler
)
try
:
conf
.
setConfig
(
args
,
configp
)
conf
.
setConfig
()
except
UsageError
as
err
:
sys
.
stderr
.
write
(
err
.
message
+
'
\
n
'
)
sys
.
stderr
.
write
(
"For help use --help
\
n
"
)
...
...
slapos/cli_legacy/format.py
View file @
e2ca58dc
...
...
@@ -31,6 +31,7 @@ import argparse
import
ConfigParser
import
logging
import
sys
import
os
from
slapos.format
import
FormatConfig
,
UsageError
,
tracing_monkeypatch
,
do_format
...
...
@@ -113,8 +114,23 @@ def main(*args):
if
configp
.
read
(
args
.
configuration_file
)
!=
[
args
.
configuration_file
]:
raise
UsageError
(
'Cannot find or parse configuration file: %s'
%
args
.
configuration_file
)
conf
.
mergeConfig
(
args
,
configp
)
if
conf
.
log_file
:
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
conf
.
log_file
)):
# fallback to console only if directory for logs does not exists and
# continue to run
raise
ValueError
(
'Please create directory %r to store %r log file'
%
(
os
.
path
.
dirname
(
conf
.
log_file
),
conf
.
log_file
))
else
:
file_handler
=
logging
.
FileHandler
(
conf
.
log_file
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
"%(asctime)s - "
"%(name)s - %(levelname)s - %(message)s"
))
conf
.
logger
.
addHandler
(
file_handler
)
conf
.
logger
.
info
(
'Configured logging to file %r'
%
conf
.
log_file
)
try
:
conf
.
setConfig
(
args
,
configp
)
conf
.
setConfig
()
except
UsageError
as
exc
:
sys
.
stderr
.
write
(
exc
.
message
+
'
\
n
'
)
sys
.
stderr
.
write
(
"For help use --help
\
n
"
)
...
...
slapos/format.py
View file @
e2ca58dc
...
...
@@ -1119,9 +1119,10 @@ class FormatConfig(object):
raise
UsageError
(
'Some required binaries are missing or not '
'functional: %s'
%
(
','
.
join
(
missing_binary_list
),
))
def
set
Config
(
self
,
args
,
configp
):
def
merge
Config
(
self
,
args
,
configp
):
"""
Set options given by parameters.
Must be executed before setting up the logger.
"""
self
.
key_file
=
None
self
.
cert_file
=
None
...
...
@@ -1137,6 +1138,7 @@ class FormatConfig(object):
if
not
getattr
(
self
,
key
,
None
):
setattr
(
self
,
key
,
configuration_dict
[
key
])
def
setConfig
(
self
):
# setup some nones
for
parameter
in
[
'interface_name'
,
'partition_base_name'
,
'user_base_name'
,
'tap_base_name'
,
'ipv4_local_network'
,
'ipv6_interface'
]:
...
...
@@ -1205,19 +1207,6 @@ class FormatConfig(object):
sys
.
stderr
.
write
(
message
+
'
\
n
'
)
sys
.
exit
()
if
self
.
log_file
:
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
self
.
log_file
)):
# fallback to console only if directory for logs does not exists and
# continue to run
raise
ValueError
(
'Please create directory %r to store %r log file'
%
(
os
.
path
.
dirname
(
self
.
log_file
),
self
.
log_file
))
else
:
file_handler
=
logging
.
FileHandler
(
self
.
log_file
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
"%(asctime)s - "
"%(name)s - %(levelname)s - %(message)s"
))
self
.
logger
.
addHandler
(
file_handler
)
self
.
logger
.
info
(
'Configured logging to file %r'
%
self
.
log_file
)
# Check mandatory options
for
parameter
in
(
'computer_id'
,
'instance_root'
,
'master_url'
,
'software_root'
,
'computer_xml'
):
...
...
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