Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Xin Wang
codes-dev
Commits
e0c15cb2
Commit
e0c15cb2
authored
Apr 09, 2014
by
Jonathan Jenkins
Browse files
added exception capability to configurator
parent
84c93747
Changes
3
Hide whitespace changes
Inline
Side-by-side
scripts/codes_configurator.py
View file @
e0c15cb2
...
...
@@ -53,7 +53,11 @@ def parse_args():
parser
.
add_argument
(
"substitute_py"
,
help
=
'python file defining "cfields" variable consisting of '
'elements of the form '
'( replacement_token, [replacements...])'
)
'( replacement_token, [replacements...]). An optional '
'variable "exceptions" may also be provided, of the form '
'( {replace_token : replacement, ...}, ...). This will '
'exclude any configuration that exhibits the key/value '
'pairs in any of the input dictionaries'
)
parser
.
add_argument
(
"token_pairs"
,
nargs
=
'*'
,
help
=
"a list of whitespace-separated token, replace pairs for "
"command-line-driven replacement (useful in shell scripts "
...
...
scripts/configurator.py
View file @
e0c15cb2
...
...
@@ -15,6 +15,7 @@ class configurator:
self
.
replace_map
=
{
k
[
0
]
:
None
for
k
in
self
.
mod
.
cfields
}
self
.
start_iter
=
False
self
.
in_iter
=
False
self
.
has_except
=
"excepts"
in
self
.
mod
.
__dict__
for
i
in
range
(
0
,
len
(
replace_pairs
),
2
):
k
,
vstr
=
replace_pairs
[
i
],
replace_pairs
[
i
+
1
]
...
...
@@ -44,6 +45,10 @@ class configurator:
v
=
self
.
iterables
[
i
].
next
()
self
.
replace_map
[
self
.
labels
[
i
]]
=
v
self
.
start_iter
=
False
# check if this is a valid config, if not, then recurse
if
self
.
has_except
and
is_replace_except
(
self
.
mod
.
excepts
,
self
.
replace_map
):
return
self
.
next
()
else
:
# > first iteration, perform the updates
# generate the next config
...
...
@@ -61,7 +66,11 @@ class configurator:
else
:
# last iterable has finished, have generated full set
raise
StopIteration
return
None
if
self
.
has_except
and
is_replace_except
(
self
.
mod
.
excepts
,
self
.
replace_map
):
return
self
.
next
()
else
:
return
None
def
write_header
(
self
,
fout
):
fout
.
write
(
"# format:
\n
# <config index>"
)
...
...
@@ -77,6 +86,15 @@ class configurator:
else
:
fout
.
write
(
'
\n
'
)
def
is_replace_except
(
except_map
,
replace_map
):
for
d
in
except_map
:
for
k
in
d
:
if
d
[
k
]
!=
replace_map
[
k
]:
break
else
:
return
True
return
False
# checks - make sure cfields is set and is the correct type
def
check_cfields
(
module
):
if
"cfields"
not
in
module
.
__dict__
:
...
...
@@ -87,6 +105,12 @@ def check_cfields(module):
isinstance
(
module
.
cfields
[
0
][
1
],
Sequence
)):
raise
TypeError
(
"cfields in incorrect format, see usage"
)
if
"excepts"
in
module
.
__dict__
and
not
\
(
isinstance
(
module
.
excepts
,
Sequence
)
and
\
isinstance
(
module
.
excepts
[
0
],
dict
))
:
raise
TypeError
(
"excepts not in correct format, see usage"
)
# import a python file (assumes there is a .py suffix!!!)
def
import_from
(
filename
):
path
,
name
=
os
.
path
.
split
(
filename
)
...
...
scripts/example/params.py
View file @
e0c15cb2
cfields
=
(
(
"C_NUM_SERVERS"
,
[
1
<<
i
for
i
in
range
(
1
,
3
)]),
(
"C_NUM_REQS"
,
[
1
,
2
]),
(
"C_PAYLOAD_SZ"
,
[
1024
*
i
for
i
in
range
(
1
,
3
)])
)
excepts
=
(
{
"C_NUM_SERVERS"
:
4
,
"C_PAYLOAD_SZ"
:
1024
},
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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