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
Xiaowu Zhang
slapos.core
Commits
d02436db
Commit
d02436db
authored
Apr 28, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
naming consistency (args/options/config..)
parent
5d6e6b96
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
78 additions
and
88 deletions
+78
-88
slapos/cli/bang.py
slapos/cli/bang.py
+4
-4
slapos/cli/cache.py
slapos/cli/cache.py
+4
-4
slapos/cli/config.py
slapos/cli/config.py
+3
-3
slapos/cli/register.py
slapos/cli/register.py
+1
-0
slapos/cli/supervisorctl.py
slapos/cli/supervisorctl.py
+5
-5
slapos/cli_legacy/bang.py
slapos/cli_legacy/bang.py
+9
-12
slapos/cli_legacy/cache.py
slapos/cli_legacy/cache.py
+4
-4
slapos/cli_legacy/console.py
slapos/cli_legacy/console.py
+4
-4
slapos/cli_legacy/entry.py
slapos/cli_legacy/entry.py
+14
-14
slapos/cli_legacy/format.py
slapos/cli_legacy/format.py
+8
-10
slapos/cli_legacy/register.py
slapos/cli_legacy/register.py
+6
-7
slapos/cli_legacy/remove.py
slapos/cli_legacy/remove.py
+8
-11
slapos/cli_legacy/supply.py
slapos/cli_legacy/supply.py
+8
-8
slapos/cli_legacy/util.py
slapos/cli_legacy/util.py
+0
-2
No files found.
slapos/cli/bang.py
View file @
d02436db
...
...
@@ -11,10 +11,10 @@ class BangCommand(ConfigCommand):
log
=
logging
.
getLogger
(
__name__
)
def
get_parser
(
self
,
prog_name
):
parser
=
super
(
BangCommand
,
self
).
get_parser
(
prog_name
)
parser
.
add_argument
(
'-m'
,
'--message'
,
ap
=
super
(
BangCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'-m'
,
'--message'
,
help
=
'Message for bang'
)
return
parser
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
...
...
slapos/cli/cache.py
View file @
d02436db
...
...
@@ -11,11 +11,11 @@ class CacheLookupCommand(ConfigCommand):
log
=
logging
.
getLogger
(
__name__
)
def
get_parser
(
self
,
prog_name
):
parser
=
super
(
CacheLookupCommand
,
self
).
get_parser
(
prog_name
)
ap
=
super
(
CacheLookupCommand
,
self
).
get_parser
(
prog_name
)
# XXX this argument could use a better name
parser
.
add_argument
(
'software_url'
,
ap
.
add_argument
(
'software_url'
,
help
=
'Your software url or MD5 hash'
)
return
parser
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
...
...
slapos/cli/config.py
View file @
d02436db
...
...
@@ -21,9 +21,9 @@ class ConfigCommand(Command):
default_config_path
=
'/etc/opt/slapos/slapos.cfg'
def
get_parser
(
self
,
prog_name
):
parser
=
super
(
ConfigCommand
,
self
).
get_parser
(
prog_name
)
parser
.
add_argument
(
'--cfg'
,
help
=
'SlapOS configuration file'
)
return
parser
ap
=
super
(
ConfigCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'--cfg'
,
help
=
'SlapOS configuration file'
)
return
ap
def
_get_config
(
self
,
cfg_path
,
required
=
False
):
"""
...
...
slapos/cli/register.py
View file @
d02436db
...
...
@@ -74,6 +74,7 @@ class RegisterCommand(Command):
return_code
=
do_register
(
config
)
except
SystemExit
,
err
:
# Catch exception raised by optparse
# XXX returning exception with sys.exit?
return_code
=
err
sys
.
exit
(
return_code
)
slapos/cli/supervisorctl.py
View file @
d02436db
...
...
@@ -15,11 +15,11 @@ class SupervisorctlCommand(ConfigCommand):
log
=
logging
.
getLogger
(
__name__
)
def
get_parser
(
self
,
prog_name
):
parser
=
super
(
SupervisorctlCommand
,
self
).
get_parser
(
prog_name
)
parser
.
add_argument
(
'supervisor_args'
,
ap
=
super
(
SupervisorctlCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'supervisor_args'
,
nargs
=
argparse
.
REMAINDER
,
help
=
'parameters passed to supervisorctl'
)
return
parser
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
...
...
slapos/cli_legacy/bang.py
View file @
d02436db
...
...
@@ -34,17 +34,14 @@ from slapos.bang import do_bang
def
main
(
*
args
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-m'
,
'--message'
,
default
=
''
,
help
=
'Message for bang.'
)
parser
.
add_argument
(
'configuration_file'
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
'-m'
,
'--message'
,
default
=
''
,
help
=
'Message for bang.'
)
ap
.
add_argument
(
'configuration_file'
,
type
=
argparse
.
FileType
(),
help
=
'SlapOS configuration file.'
)
if
len
(
args
)
==
0
:
arg
ument
=
parser
.
parse_args
(
)
if
args
:
arg
s
=
ap
.
parse_args
(
list
(
args
)
)
else
:
argument
=
parser
.
parse_args
(
list
(
args
))
configuration_file
=
argument
.
configuration_file
[
0
]
message
=
argument
.
message
# Loads config (if config specified)
args
=
ap
.
parse_args
()
config
=
ConfigParser
.
SafeConfigParser
()
config
.
readfp
(
configuration_file
)
do_bang
(
config
,
message
)
config
.
readfp
(
args
.
configuration_file
)
do_bang
(
config
,
args
.
message
)
slapos/cli_legacy/cache.py
View file @
d02436db
...
...
@@ -7,10 +7,10 @@ from slapos.cache import do_lookup
def
cache_lookup
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"configuration_file"
,
help
=
"SlapOS configuration file"
)
parser
.
add_argument
(
"software_url"
,
help
=
"Your software url or MD5 hash"
)
args
=
parser
.
parse_args
()
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"configuration_file"
,
help
=
"SlapOS configuration file"
)
ap
.
add_argument
(
"software_url"
,
help
=
"Your software url or MD5 hash"
)
args
=
ap
.
parse_args
()
config
=
ConfigParser
.
SafeConfigParser
()
config
.
read
(
args
.
configuration_file
)
...
...
slapos/cli_legacy/console.py
View file @
d02436db
...
...
@@ -40,12 +40,12 @@ examples :
ap
.
add_argument
(
'configuration_file'
,
help
=
'path to slapos.cfg'
)
option
s
=
ap
.
parse_args
()
arg
s
=
ap
.
parse_args
()
if
not
os
.
path
.
isfile
(
option
s
.
configuration_file
):
ap
.
error
(
"%s: Not found or not a regular file."
%
option
s
.
configuration_file
)
if
not
os
.
path
.
isfile
(
arg
s
.
configuration_file
):
ap
.
error
(
"%s: Not found or not a regular file."
%
arg
s
.
configuration_file
)
config
=
ClientConfig
(
options
,
get_config_parser
(
option
s
.
configuration_file
))
config
=
ClientConfig
(
args
,
get_config_parser
(
arg
s
.
configuration_file
))
local
=
init
(
config
)
do_console
(
local
)
slapos/cli_legacy/entry.py
View file @
d02436db
...
...
@@ -72,9 +72,9 @@ def checkSlaposCfg():
for
element
in
sys
.
argv
:
if
'.cfg'
in
element
:
if
os
.
path
.
exists
(
element
):
config
uration
=
ConfigParser
.
SafeConfigParser
()
config
uration
.
read
(
element
)
if
config
uration
.
has_section
(
'slapos'
):
config
=
ConfigParser
.
SafeConfigParser
()
config
.
read
(
element
)
if
config
.
has_section
(
'slapos'
):
return
True
return
False
...
...
@@ -207,19 +207,19 @@ Node subcommands usage:
# Parse arguments
# XXX remove the "positional arguments" from help message
parser
=
argparse
.
ArgumentParser
(
usage
=
usage
)
parser
.
add_argument
(
'command'
)
parser
.
add_argument
(
'argument_list'
,
nargs
=
argparse
.
REMAINDER
)
ap
=
argparse
.
ArgumentParser
(
usage
=
usage
)
ap
.
add_argument
(
'command'
)
ap
.
add_argument
(
'argument_list'
,
nargs
=
argparse
.
REMAINDER
)
namespace
=
parser
.
parse_args
()
args
=
ap
.
parse_args
()
# Set sys.argv for the sub-entry point that we will call
command_line
=
[
namespace
.
command
]
command_line
.
extend
(
namespace
.
argument_list
)
command_line
=
[
args
.
command
]
command_line
.
extend
(
args
.
argument_list
)
sys
.
argv
=
command_line
try
:
if
not
dispatch
(
namespace
.
command
,
is_node
):
parser
.
print_help
()
if
not
dispatch
(
args
.
command
,
is_node
):
ap
.
print_help
()
sys
.
exit
(
1
)
except
EntryPointNotImplementedError
,
exception
:
print
(
'The command %s does not exist or is not yet implemented. Please '
...
...
slapos/cli_legacy/format.py
View file @
d02436db
...
...
@@ -38,8 +38,6 @@ from slapos.format import FormatConfig, UsageError, tracing_monkeypatch, do_form
def
main
(
*
args
):
"Run default configuration."
# Parse arguments
ap
=
argparse
.
ArgumentParser
(
usage
=
'usage: %s [options] CONFIGURATION_FILE'
%
sys
.
argv
[
0
])
ap
.
add_argument
(
'-x'
,
'--computer_xml'
,
...
...
@@ -96,14 +94,14 @@ def main(*args):
help
=
'path to slapos.cfg'
)
if
args
:
option
s
=
ap
.
parse_args
(
list
(
args
))
arg
s
=
ap
.
parse_args
(
list
(
args
))
else
:
option
s
=
ap
.
parse_args
()
arg
s
=
ap
.
parse_args
()
logger
=
logging
.
getLogger
(
"slapformat"
)
logger
.
addHandler
(
logging
.
StreamHandler
())
if
option
s
.
verbose
:
if
arg
s
.
verbose
:
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
debug
(
"Verbose mode enabled."
)
else
:
...
...
@@ -112,13 +110,13 @@ def main(*args):
config
=
FormatConfig
(
logger
=
logger
)
configuration_parser
=
ConfigParser
.
SafeConfigParser
()
if
configuration_parser
.
read
(
options
.
configuration_file
)
!=
[
option
s
.
configuration_file
]:
raise
UsageError
(
'Cannot find or parse configuration file: %s'
%
option
s
.
configuration_file
)
if
configuration_parser
.
read
(
args
.
configuration_file
)
!=
[
arg
s
.
configuration_file
]:
raise
UsageError
(
'Cannot find or parse configuration file: %s'
%
arg
s
.
configuration_file
)
try
:
config
.
setConfig
(
option
s
,
configuration_parser
)
except
UsageError
as
e
rr
:
sys
.
stderr
.
write
(
e
rr
.
message
+
'
\
n
'
)
config
.
setConfig
(
arg
s
,
configuration_parser
)
except
UsageError
as
e
xc
:
sys
.
stderr
.
write
(
e
xc
.
message
+
'
\
n
'
)
sys
.
stderr
.
write
(
"For help use --help
\
n
"
)
sys
.
exit
(
1
)
...
...
slapos/cli_legacy/register.py
View file @
d02436db
...
...
@@ -35,8 +35,6 @@ from slapos.register.register import do_register, RegisterConfig
def
main
():
"Run default configuration."
ap
=
argparse
.
ArgumentParser
(
usage
=
'usage: slapos node %s NODE_NAME [options]'
%
sys
.
argv
[
0
])
ap
.
add_argument
(
'node_name'
,
...
...
@@ -86,9 +84,9 @@ def main():
default
=
False
,
action
=
'store_true'
)
option
s
=
ap
.
parse_args
()
arg
s
=
ap
.
parse_args
()
if
options
.
password
and
not
option
s
.
login
:
if
args
.
password
and
not
arg
s
.
login
:
ap
.
error
(
'Please enter your login with your password'
)
logger
=
logging
.
getLogger
(
'Register'
)
...
...
@@ -100,10 +98,11 @@ def main():
try
:
config
=
RegisterConfig
(
logger
=
logger
)
config
.
setConfig
(
option
s
)
config
.
setConfig
(
arg
s
)
return_code
=
do_register
(
config
)
except
SystemExit
,
err
:
except
SystemExit
as
exc
:
# Catch exception raised by optparse
return_code
=
err
# XXX returning exception with sys.exit?
return_code
=
exc
sys
.
exit
(
return_code
)
slapos/cli_legacy/remove.py
View file @
d02436db
...
...
@@ -7,17 +7,14 @@ from slapos.cli_legacy.util import get_config_parser
def
remove
():
"""
Run when invoking slapos remove. Mostly argument parsing.
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'configuration_file'
,
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
'configuration_file'
,
help
=
'SlapOS configuration file'
)
parser
.
add_argument
(
'software_url'
,
ap
.
add_argument
(
'software_url'
,
help
=
'Your software url'
)
parser
.
add_argument
(
'node'
,
ap
.
add_argument
(
'node'
,
help
=
'Target node'
)
args
=
parser
.
parse_args
()
args
=
ap
.
parse_args
()
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
...
...
slapos/cli_legacy/supply.py
View file @
d02436db
...
...
@@ -10,14 +10,14 @@ def supply():
"""
Run when invoking slapos supply. Mostly argument parsing.
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'configuration_file'
,
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
'configuration_file'
,
help
=
'SlapOS configuration file'
)
parser
.
add_argument
(
'software_url'
,
ap
.
add_argument
(
'software_url'
,
help
=
'Your software url'
)
parser
.
add_argument
(
'node'
,
ap
.
add_argument
(
'node'
,
help
=
'Target node'
)
args
=
parser
.
parse_args
()
args
=
ap
.
parse_args
()
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
...
...
slapos/cli_legacy/util.py
View file @
d02436db
...
...
@@ -11,5 +11,3 @@ def get_config_parser(path):
raise
OSError
(
'Specified configuration file %s does not exist. Exiting.'
%
path
)
configuration_parser
.
read
(
path
)
return
configuration_parser
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