Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
codes
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
38
Issues
38
List
Boards
Labels
Milestones
Merge Requests
8
Merge Requests
8
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
codes
codes
Commits
e0c15cb2
Commit
e0c15cb2
authored
Apr 09, 2014
by
Jonathan Jenkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added exception capability to configurator
parent
84c93747
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
scripts/codes_configurator.py
scripts/codes_configurator.py
+5
-1
scripts/configurator.py
scripts/configurator.py
+25
-1
scripts/example/params.py
scripts/example/params.py
+2
-0
No files found.
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
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