Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
a11d63f5
Commit
a11d63f5
authored
Jan 19, 2011
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Splitted validators library
parent
1d1acb01
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
32 deletions
+46
-32
settingsd-server.py
settingsd-server.py
+3
-3
config.py
settingsd/config.py
+3
-3
server.py
settingsd/server.py
+1
-1
__init__.py
settingsd/validators/__init__.py
+8
-0
common.py
settingsd/validators/common.py
+30
-0
network.py
settingsd/validators/network.py
+1
-25
No files found.
settingsd-server.py
View file @
a11d63f5
...
...
@@ -51,21 +51,21 @@ if __name__ == "__main__" :
elif
opts_list_item
in
(
"--log-level"
,)
:
try
:
log_level
=
validators
.
validRange
(
int
(
args_list_item
),
const
.
ALL_LOG_LEVELS_LIST
)
log_level
=
validators
.
common
.
validRange
(
int
(
args_list_item
),
const
.
ALL_LOG_LEVELS_LIST
)
except
Exception
,
err1
:
print
"Incorrect option
\"
%
s
\"
:
%
s"
%
(
opts_list_item
,
str
(
err1
))
sys
.
exit
(
1
)
elif
opts_list_item
in
(
"--use-syslog"
,)
:
try
:
use_syslog_flag
=
validators
.
validBool
(
args_list_item
)
use_syslog_flag
=
validators
.
common
.
validBool
(
args_list_item
)
except
Exception
,
err1
:
print
"Incorrect option
\"
%
s
\"
:
%
s"
%
(
opts_list_item
,
str
(
err1
))
sys
.
exit
(
1
)
elif
opts_list_item
in
(
"--bus-type"
,)
:
try
:
bus_type
=
validators
.
validRange
(
args_list_item
,
const
.
ALL_BUS_TYPES_LIST
)
bus_type
=
validators
.
common
.
validRange
(
args_list_item
,
const
.
ALL_BUS_TYPES_LIST
)
except
Exception
,
err1
:
print
"Incorrect option
\"
%
s
\"
:
%
s"
%
(
opts_list_item
,
str
(
err1
))
sys
.
exit
(
1
)
...
...
settingsd/config.py
View file @
a11d63f5
...
...
@@ -23,9 +23,9 @@ ConfigDictObject = {
APPLICATION_SECTION
:
{
"service_name"
:
(
const
.
DEFAULT_SERVICE_NAME
,
str
),
"service_path"
:
(
const
.
DEFAULT_SERVICE_PATH
,
str
),
"bus_type"
:
(
const
.
DEFAULT_BUS_TYPE
,
(
lambda
arg
:
validators
.
validRange
(
arg
,
const
.
ALL_BUS_TYPES_LIST
)
)),
"log_level"
:
(
const
.
DEFAULT_LOG_LEVEL
,
(
lambda
arg
:
validators
.
validRange
(
int
(
arg
),
const
.
ALL_LOG_LEVELS_LIST
)
)),
"log_use_colors"
:(
const
.
DEFAULT_LOG_USE_COLORS_FLAG
,
validators
.
validBool
)
"bus_type"
:
(
const
.
DEFAULT_BUS_TYPE
,
(
lambda
arg
:
validators
.
common
.
validRange
(
arg
,
const
.
ALL_BUS_TYPES_LIST
)
)),
"log_level"
:
(
const
.
DEFAULT_LOG_LEVEL
,
(
lambda
arg
:
validators
.
common
.
validRange
(
int
(
arg
),
const
.
ALL_LOG_LEVELS_LIST
)
)),
"log_use_colors"
:(
const
.
DEFAULT_LOG_USE_COLORS_FLAG
,
validators
.
common
.
validBool
)
},
RUNTIME_SECTION
:
{
"application"
:
(
None
,
None
),
...
...
settingsd/server.py
View file @
a11d63f5
...
...
@@ -72,7 +72,7 @@ class Server(object) :
def
loadServicesConfigs
(
self
)
:
for
service_name
in
self
.
__services_dict
.
keys
()
:
service_options_list
=
list
(
self
.
__services_dict
[
service_name
][
"service_class"
]
.
options
())
service_options_list
.
append
((
service_name
,
"enabled"
,
"no"
,
validators
.
validBool
))
service_options_list
.
append
((
service_name
,
"enabled"
,
"no"
,
validators
.
common
.
validBool
))
for
service_options_list_item
in
service_options_list
:
try
:
...
...
settingsd/validators/__init__.py
0 → 100644
View file @
a11d63f5
# -*- coding: utf-8 -*-
from
common
import
ValidatorError
import
common
import
network
settingsd/validators/common.py
0 → 100644
View file @
a11d63f5
# -*- coding: utf-8 -*-
import
re
##### Exceptions #####
class
ValidatorError
(
Exception
)
:
pass
##### Public methods #####
def
validBool
(
arg
)
:
arg
=
str
(
arg
)
.
lower
()
true_args_list
=
(
"1"
,
"true"
,
"yes"
)
false_args_list
=
(
"0"
,
"false"
,
"no"
)
if
not
arg
in
true_args_list
+
false_args_list
:
raise
ValidatorError
(
"Argument
\"
%
s
\"
not in list
%
s or
%
s"
%
(
arg
,
true_args_list
,
false_args_list
))
return
(
arg
in
true_args_list
)
def
validRange
(
arg
,
valid_args_list
)
:
if
not
arg
in
valid_args_list
:
raise
ValidatorError
(
"Argument
\"
%
s
\"
not in range
%
s"
%
(
arg
,
str
(
valid_args_list
)))
return
arg
def
validStringList
(
arg
)
:
return
re
.
split
(
r"[,\t ]+"
,
str
(
arg
))
settingsd/validators.py
→
settingsd/validators
/network
.py
View file @
a11d63f5
# -*- coding: utf-8 -*-
import
re
##### Exceptions #####
class
ValidatorError
(
Exception
)
:
pass
from
common
import
ValidatorError
##### Public methods #####
def
validBool
(
arg
)
:
arg
=
str
(
arg
)
.
lower
()
true_args_list
=
(
"1"
,
"true"
,
"yes"
)
false_args_list
=
(
"0"
,
"false"
,
"no"
)
if
not
arg
in
true_args_list
+
false_args_list
:
raise
ValidatorError
(
"Argument
\"
%
s
\"
not in list
%
s or
%
s"
%
(
arg
,
true_args_list
,
false_args_list
))
return
(
arg
in
true_args_list
)
def
validRange
(
arg
,
valid_args_list
)
:
if
not
arg
in
valid_args_list
:
raise
ValidatorError
(
"Argument
\"
%
s
\"
not in range
%
s"
%
(
arg
,
str
(
valid_args_list
)))
return
arg
def
validStringList
(
arg
)
:
return
re
.
split
(
r"[,\t ]+"
,
str
(
arg
))
###
def
validIpv4Address
(
arg
)
:
arg
=
str
(
arg
)
.
strip
()
...
...
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