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
896755e6
Commit
896755e6
authored
Oct 01, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default option and configuration file if missing
parent
198cc830
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
8 deletions
+59
-8
slapos/entry.py
slapos/entry.py
+59
-8
No files found.
slapos/entry.py
View file @
896755e6
...
...
@@ -27,6 +27,8 @@
##############################################################################
import
argparse
import
ConfigParser
import
os
import
sys
from
slapos.bang
import
main
as
bang
from
slapos.console
import
run
as
console
...
...
@@ -43,10 +45,51 @@ class EntryPointNotImplementedError(NotImplementedError):
def
__init__
(
self
,
*
args
,
**
kw_args
):
NotImplementedError
.
__init__
(
self
,
*
args
,
**
kw_args
)
def
checkSlaposCfg
():
"""
Check if a slapos configuration file was given as a argument.
If a slapos configuration file is given it return True else False
"""
for
element
in
sys
.
argv
:
if
'.cfg'
in
element
:
if
os
.
path
.
exists
(
element
):
configuration
=
ConfigParser
.
SafeConfigParser
()
configuration
.
read
(
element
)
if
configuration
.
has_section
(
'slapos'
):
return
True
return
False
def
checkOption
(
option
):
"""
Check if a given option is already in call line
Add it and its values if missing
"""
option
=
option
.
split
()
key
=
option
[
0
]
for
element
in
sys
.
argv
:
if
key
in
element
:
return
True
sys
.
argv
.
append
(
key
)
if
len
(
option
)
>
1
:
sys
.
argv
=
sys
.
argv
+
option
[
1
:]
return
True
def
call
(
fun
,
config
=
False
,
option
=
[]):
"""
Add missing options to argv
Add config if asked and it is missing
Call function fun
"""
for
element
in
option
:
checkOption
(
element
)
if
config
:
if
not
checkSlaposCfg
():
sys
.
argv
.
append
(
config
)
fun
()
def
showUsage
():
# We are out of option. We have to admit it: no other option than error.
# XXX Real error message
sys
.
exit
(
1
)
def
dispatch
(
command
,
is_node
):
...
...
@@ -54,19 +97,27 @@ def dispatch(command, is_node):
Here we could use introspection to get rid of the big "if" statements,
but we want to control every input.
"""
# XXX console_config =
if
is_node
:
config
=
'/etc/opt/slapos/slapos.cfg'
if
command
in
'register'
:
register
(
)
call
(
register
)
elif
command
==
'software'
:
software
()
call
(
software
,
config
=
config
,
option
=
[
'--logfile /opt/slapos/slapgrid-sr.log'
,
'--pidfile /opt/slapos/slapgrid-sr.pid'
])
elif
command
==
'instance'
:
instance
()
call
(
instance
,
config
=
config
,
option
=
[
'--logfile /opt/slapos/slapgrid-cp.log'
,
'--pidfile /opt/slapos/slapgrid-cp.pid'
])
elif
command
==
'report'
:
report
()
call
(
report
,
config
=
config
,
option
=
[
'--logfile /opt/slapos/slapgrid-ur.log'
])
elif
command
==
'bang'
:
bang
(
)
call
(
bang
,
config
=
True
)
elif
command
==
'format'
:
format
()
call
(
format
,
config
=
config
,
option
=
[
'--log_file /opt/slapos/slapformat.log'
])
elif
command
in
[
'start'
,
'stop'
,
'status'
,
'tail'
]:
supervisord
()
supervisorctl
()
...
...
@@ -105,12 +156,12 @@ def main():
is_node
=
False
namespace
=
parser
.
parse_args
()
# Set sys.argv for the sub-entry point that we will call
command_line
=
[
namespace
.
command
]
command_line
.
extend
(
namespace
.
argument_list
)
sys
.
argv
=
command_line
dispatch
(
namespace
.
command
,
is_node
)
# If configuration file is not given: define it arbitrarily
# If client commands: use ~/.slapos.cfg
# If node commands: use /etc/opt/slapos/slapos.cfg
...
...
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