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
Eric Zheng
slapos.core
Commits
f3825592
Commit
f3825592
authored
Jun 27, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli: group commands - client, node, other
parent
5fb75eb8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
4 deletions
+65
-4
slapos/cli/bang.py
slapos/cli/bang.py
+1
-0
slapos/cli/config.py
slapos/cli/config.py
+8
-1
slapos/cli/entry.py
slapos/cli/entry.py
+45
-1
slapos/cli/format.py
slapos/cli/format.py
+1
-0
slapos/cli/register.py
slapos/cli/register.py
+1
-0
slapos/cli/slapgrid.py
slapos/cli/slapgrid.py
+1
-0
slapos/cli/supervisorctl.py
slapos/cli/supervisorctl.py
+4
-1
slapos/cli/supervisord.py
slapos/cli/supervisord.py
+4
-1
No files found.
slapos/cli/bang.py
View file @
f3825592
...
...
@@ -9,6 +9,7 @@ class BangCommand(ConfigCommand):
"""
request update on all partitions
"""
command_group
=
'node'
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
BangCommand
,
self
).
get_parser
(
prog_name
)
...
...
slapos/cli/config.py
View file @
f3825592
...
...
@@ -11,7 +11,9 @@ class ConfigError(Exception):
class
ConfigCommand
(
Command
):
"Base class for commands that require a configuration file"
"""
Base class for commands that require a configuration file
"""
default_config_var
=
'SLAPOS_CONFIGURATION'
...
...
@@ -57,5 +59,10 @@ class ConfigCommand(Command):
class
ClientConfigCommand
(
ConfigCommand
):
"""
Base class for client commands, that use the client configuration file
"""
default_config_var
=
'SLAPOS_CLIENT_CONFIGURATION'
default_config_path
=
'~/.slapos/slapos-client.cfg'
command_group
=
'client'
slapos/cli/entry.py
View file @
f3825592
# -*- coding: utf-8 -*-
import
argparse
import
collections
import
logging
import
sys
...
...
@@ -48,6 +50,42 @@ class SlapOSCommandManager(cliff.commandmanager.CommandManager):
sys
.
exit
(
5
)
class
SlapOSHelpAction
(
argparse
.
Action
):
"""
Adapted from cliff.help.HelpAction, this class detects
and outputs command groups, via the .command_group attribute
of the Command class. Must be a class attribute in case the class
cannot be instantiated ('Could not load' message).
"""
def
__call__
(
self
,
parser
,
namespace
,
values
,
option_string
=
None
):
app
=
self
.
default
parser
.
print_help
(
app
.
stdout
)
command_manager
=
app
.
command_manager
groups
=
collections
.
defaultdict
(
list
)
for
name
,
ep
in
sorted
(
command_manager
):
command_group
,
help_line
=
self
.
_help_line
(
ep
,
name
)
groups
[
command_group
].
append
(
help_line
)
for
group
in
sorted
(
groups
):
app
.
stdout
.
write
(
'
\
n
%s commands:
\
n
'
%
group
)
for
line
in
sorted
(
groups
[
group
]):
app
.
stdout
.
write
(
line
)
sys
.
exit
(
0
)
def
_help_line
(
self
,
ep
,
name
):
try
:
factory
=
ep
.
load
()
except
Exception
as
err
:
return
'Could not load %r
\
n
'
%
ep
try
:
cmd
=
factory
(
self
,
None
)
except
Exception
as
err
:
return
'Could not instantiate %r: %s
\
n
'
%
(
ep
,
err
)
one_liner
=
cmd
.
get_description
().
split
(
'
\
n
'
)[
0
]
group
=
getattr
(
factory
,
'command_group'
,
'other'
)
return
group
,
' %-13s %s
\
n
'
%
(
name
,
one_liner
)
class
SlapOSApp
(
cliff
.
app
.
App
):
#
...
...
@@ -83,7 +121,13 @@ class SlapOSApp(cliff.app.App):
default
=
None
,
help
=
'Specify a file to log output (default: console only)'
,
)
parser
.
add_argument
(
'-h'
,
'--help'
,
action
=
SlapOSHelpAction
,
nargs
=
0
,
default
=
self
,
# tricky
help
=
"show this help message and exit"
,
)
return
parser
def
initialize_app
(
self
,
argv
):
...
...
slapos/cli/format.py
View file @
f3825592
...
...
@@ -12,6 +12,7 @@ class FormatCommand(ConfigCommand):
"""
create users, partitions and network configuration
"""
command_group
=
'node'
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
FormatCommand
,
self
).
get_parser
(
prog_name
)
...
...
slapos/cli/register.py
View file @
f3825592
...
...
@@ -19,6 +19,7 @@ class RegisterCommand(Command):
"""
register a node in the SlapOS cloud
"""
command_group
=
'node'
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
RegisterCommand
,
self
).
get_parser
(
prog_name
)
...
...
slapos/cli/slapgrid.py
View file @
f3825592
...
...
@@ -9,6 +9,7 @@ from slapos.grid.slapgrid import (merged_options, check_missing_parameters, chec
class
SlapgridCommand
(
ConfigCommand
):
command_group
=
'node'
method_name
=
NotImplemented
default_pidfile
=
NotImplemented
...
...
slapos/cli/supervisorctl.py
View file @
f3825592
...
...
@@ -11,7 +11,10 @@ import supervisor.supervisorctl
class
SupervisorctlCommand
(
ConfigCommand
):
"""open supervisor console, for process management"""
"""
open supervisor console, for process management
"""
command_group
=
'node'
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
SupervisorctlCommand
,
self
).
get_parser
(
prog_name
)
...
...
slapos/cli/supervisord.py
View file @
f3825592
...
...
@@ -8,7 +8,10 @@ from slapos.grid.svcbackend import launchSupervisord
class
SupervisordCommand
(
ConfigCommand
):
"""launch, if not already running, supervisor daemon"""
"""
launch, if not already running, supervisor daemon
"""
command_group
=
'node'
@
must_be_root
def
take_action
(
self
,
args
):
...
...
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