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
Paul Graydon
slapos.core
Commits
e4445111
Commit
e4445111
authored
Apr 30, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapproxy: optparse -> argparser
parent
0311e91b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
47 deletions
+30
-47
slapos/proxy/__init__.py
slapos/proxy/__init__.py
+30
-47
No files found.
slapos/proxy/__init__.py
View file @
e4445111
...
...
@@ -29,49 +29,13 @@
import
os
import
sys
from
optparse
import
OptionParser
,
Option
import
argparse
import
logging
import
logging.handlers
import
ConfigParser
class
Parser
(
OptionParser
):
"""
Parse all arguments.
"""
def
__init__
(
self
,
usage
=
None
,
version
=
None
):
"""
Initialize all options possibles.
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
Option
(
"-l"
,
"--log_file"
,
help
=
"The path to the log file used by the script."
,
type
=
str
),
Option
(
"-v"
,
"--verbose"
,
default
=
False
,
action
=
"store_true"
,
help
=
"Verbose output."
),
Option
(
"-c"
,
"--console"
,
default
=
False
,
action
=
"store_true"
,
help
=
"Console output."
),
Option
(
"-u"
,
"--database-uri"
,
type
=
str
,
help
=
"URI for sqlite database"
),
])
def
check_args
(
self
):
"""
Check arguments
"""
(
options
,
args
)
=
self
.
parse_args
()
if
len
(
args
)
!=
1
:
self
.
error
(
"Incorrect number of arguments"
)
return
options
,
args
[
0
]
class
Config
:
class
ProxyConfig
(
object
):
def
setConfig
(
self
,
option_dict
,
configuration_file_path
):
"""
Set options given by parameters.
...
...
@@ -94,6 +58,7 @@ class Config:
self
.
logger
=
logging
.
getLogger
(
"slapproxy"
)
self
.
logger
.
setLevel
(
logging
.
INFO
)
if
self
.
console
:
# XXX shouldn't this be default?
self
.
logger
.
addHandler
(
logging
.
StreamHandler
())
if
not
self
.
database_uri
:
...
...
@@ -115,25 +80,43 @@ class Config:
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
self
.
logger
.
debug
(
"Verbose mode enabled."
)
def
run
(
config
):
from
views
import
app
app
.
config
[
'computer_id'
]
=
config
.
computer_id
app
.
config
[
'DATABASE_URI'
]
=
config
.
database_uri
app
.
run
(
host
=
config
.
host
,
port
=
int
(
config
.
port
))
def
main
():
"Run default configuration."
usage
=
"usage: %s [options] CONFIGURATION_FILE"
%
sys
.
argv
[
0
]
ap
=
argparse
.
ArgumentParser
()
try
:
# Parse arguments
config
=
Config
()
config
.
setConfig
(
*
Parser
(
usage
=
usage
).
check_args
())
ap
.
add_argument
(
'-l'
,
'--log_file'
,
help
=
'The path to the log file used by the script.'
)
ap
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
help
=
'Verbose output.'
)
# XXX shouldn't this be deprecated?
ap
.
add_argument
(
'-c'
,
'--console'
,
action
=
'store_true'
,
help
=
'Console output.'
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
run
(
config
)
ap
.
add_argument
(
'configuration_file'
,
help
=
'path to slapos.cfg'
)
args
=
ap
.
parse_args
()
try
:
conf
=
ProxyConfig
()
conf
.
setConfig
(
args
,
args
.
configuration_file
)
run
(
conf
)
return_code
=
0
except
SystemExit
,
err
:
# Catch exception raise by optparse
except
SystemExit
as
err
:
return_code
=
err
sys
.
exit
(
return_code
)
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