Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LINC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ResearchAndDevelopment
LINC
Commits
38e8d33a
Commit
38e8d33a
authored
5 years ago
by
Tammo Jan Dijkema
Browse files
Options
Downloads
Patches
Plain Diff
Prettify parset_concat, allow no args
parent
ae83c2c4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/parset_concat.py
+37
-18
37 additions, 18 deletions
utils/parset_concat.py
with
37 additions
and
18 deletions
utils/parset_concat.py
+
37
−
18
View file @
38e8d33a
...
@@ -12,7 +12,7 @@ def parse_arguments(args):
...
@@ -12,7 +12,7 @@ def parse_arguments(args):
parser
.
add_argument
(
'
step_name
'
,
help
=
'
name of the step
'
)
parser
.
add_argument
(
'
step_name
'
,
help
=
'
name of the step
'
)
parser
.
add_argument
(
'
step_type
'
,
help
=
'
type of the step
'
)
parser
.
add_argument
(
'
step_type
'
,
help
=
'
type of the step
'
)
parser
.
add_argument
(
'
--input_parset
'
,
default
=
None
,
help
=
'
input parset
'
)
parser
.
add_argument
(
'
--input_parset
'
,
default
=
None
,
help
=
'
input parset
'
)
parser
.
add_argument
(
'
step_arguments
'
,
help
=
'
step arguments
'
,
nargs
=
'
+
'
)
parser
.
add_argument
(
'
step_arguments
'
,
help
=
'
step arguments
'
,
nargs
=
'
*
'
)
return
parser
.
parse_args
()
return
parser
.
parse_args
()
...
@@ -25,26 +25,37 @@ def main(args):
...
@@ -25,26 +25,37 @@ def main(args):
arguments
.
step_arguments
)
arguments
.
step_arguments
)
def
concatenate
(
parsetfile
,
step_name
,
step_type
,
args
):
def
concatenate
(
lines
,
step_name
,
step_type
,
step_args
):
"""
Append a new step to existing parset. Output is printed to stdout.
Args:
lines (List[str]): list of existing lines
step_name (str): name of new step
step_type (str): type of new step
step_args (List[str]): key-value pairs, e.g. [
"
applybeam=true
"
]
Returns:
None
"""
steps
=
[]
steps
=
[]
if
parsetfile
and
os
.
path
.
exists
(
parsetfile
):
if
lines
:
with
open
(
parsetfile
,
"
r
"
)
as
f_stream
:
for
line
in
lines
:
for
line
in
f_stream
.
read
().
splitlines
():
if
line
.
startswith
(
"
steps=
"
):
if
line
.
startswith
(
"
steps=
"
):
_
,
steps
=
line
.
split
(
"
=
"
)
_
,
steps
=
line
.
split
(
"
=
"
)
steps
=
[
step
for
step
in
steps
.
strip
().
lstrip
(
"
[
"
).
rstrip
(
"
]
"
).
split
(
"
,
"
)
if
step
]
steps
=
[
step
for
step
in
steps
.
strip
().
lstrip
(
"
[
"
).
rstrip
(
"
]
"
).
split
(
"
,
"
)
if
step
]
else
:
else
:
print
(
line
)
print
(
line
)
print
(
"
%s.type=%s
"
%
(
step_name
,
step_type
))
print
(
"
%s.type=%s
"
%
(
step_name
,
step_type
))
for
arg
in
args
:
if
step_args
:
if
not
'
=
'
in
arg
:
for
arg
in
step_args
:
logging
.
error
(
'
Argument invalid (es. key=value): %s
'
,
arg
)
if
not
'
=
'
in
arg
:
logging
.
error
(
'
Argument invalid (e.g. key=value): %s
'
,
arg
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
key
=
'
.
'
.
join
([
step_name
,
arg
.
strip
()])
key
=
'
.
'
.
join
([
step_name
,
arg
.
strip
()])
print
(
key
)
print
(
key
)
if
step_name
in
steps
:
if
step_name
in
steps
:
logging
.
error
(
'
Step named %s already present in steps: %s
'
,
step_name
,
steps
)
logging
.
error
(
'
Step named %s already present in steps: %s
'
,
step_name
,
steps
)
exit
(
1
)
exit
(
1
)
...
@@ -52,5 +63,13 @@ def concatenate(parsetfile, step_name, step_type, args):
...
@@ -52,5 +63,13 @@ def concatenate(parsetfile, step_name, step_type, args):
steps
+=
[
step_name
]
steps
+=
[
step_name
]
print
(
"
steps=[%s]
"
%
"
,
"
.
join
(
steps
))
print
(
"
steps=[%s]
"
%
"
,
"
.
join
(
steps
))
def
concatenate_file
(
parsetfile
,
step_name
,
step_type
,
args
):
print
(
args
)
if
parsetfile
and
os
.
path
.
exists
(
parsetfile
):
with
open
(
parsetfile
,
"
r
"
)
as
f_stream
:
concatenate
(
f_stream
.
read
().
splitlines
(),
step_name
,
step_type
,
args
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
(
sys
.
argv
)
main
(
sys
.
argv
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment