Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mkexp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esmenv
mkexp
Commits
3ea194a3
Commit
3ea194a3
authored
3 years ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
Globals: added tool to restore global vars from a base config (unmergeconfig)
parent
e24dac62
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGES.txt
+2
-2
2 additions, 2 deletions
CHANGES.txt
unmergeconfig
+121
-0
121 additions, 0 deletions
unmergeconfig
with
123 additions
and
2 deletions
CHANGES.txt
+
2
−
2
View file @
3ea194a3
...
...
@@ -19,8 +19,8 @@ Global
* namelist2config: re-enable here-doc detection to remove spurious data,
use global variables in namelists and output, remove array slice syntax
* Fixes related to python3, perl-5.26, and jinja2-3.0 compatibility
* Added tools to
find
differences/similarities between config files
(compconfig.py, diffconfig.py)
* Added tools to
manage
differences/similarities between config files
(compconfig.py, diffconfig.py
, unmergeconfig
)
Release 1.1.2
=============
...
...
This diff is collapsed.
Click to expand it.
unmergeconfig
0 → 100755
+
121
−
0
View file @
3ea194a3
#! /usr/bin/env python
'''
\
Create top level variables based on a higher level config
$Id$
'''
from
__future__
import
print_function
import
sys
import
io
import
argparse
import
package_info
import
re
from
feedback
import
die
,
warn
from
configobj
import
Section
from
expconfig
import
ConfigObj
#
# Helper routines
#
# Get base config keys that contain globals
global_matcher
=
re
.
compile
(
r
'
\$(\w+)
'
)
def
get_globals
(
config
,
result
):
for
key
in
config
.
sections
:
get_globals_section
(
config
[
key
],
key
,
config
.
scalars
,
result
)
def
get_globals_section
(
section
,
path
,
global_keys
,
result
):
for
key
in
section
.
scalars
:
value
=
section
[
key
]
if
not
isinstance
(
value
,
(
list
,
tuple
)):
match
=
global_matcher
.
match
(
value
)
if
match
:
global_key
=
match
.
group
(
1
)
if
True
:
### global_key in global_keys:
result
[
path
+
'
/
'
+
key
]
=
global_key
for
key
in
section
.
sections
:
get_globals_section
(
section
[
key
],
path
+
'
/
'
+
key
,
global_keys
,
result
)
def
eval_globals
(
config
,
global_dict
):
for
key
in
config
.
sections
:
eval_globals_section
(
config
[
key
],
key
,
global_dict
)
def
eval_globals_section
(
section
,
path
,
global_dict
):
for
key
in
section
.
scalars
:
value
=
section
[
key
]
if
not
isinstance
(
value
,
(
list
,
tuple
)):
global_key
=
path
+
'
/
'
+
key
if
global_key
in
global_dict
:
global_var
=
global_dict
[
global_key
]
if
global_var
in
section
.
main
:
if
section
.
main
[
global_var
]
!=
value
:
warn
(
"
global
'
%s
'
already set to
'
%s
'
,
"
"
keeping
'
%s
'
at
'
%s
'"
,
global_var
,
section
.
main
[
global_var
],
global_key
,
value
)
else
:
section
[
key
]
=
'
$
'
+
global_var
else
:
section
.
main
[
global_var
]
=
value
section
[
key
]
=
'
$
'
+
global_var
for
key
in
section
.
sections
:
eval_globals_section
(
section
[
key
],
path
+
'
/
'
+
key
,
global_dict
)
#
# Main routine
#
# Check command line
command_line
=
argparse
.
ArgumentParser
(
description
=
__doc__
.
split
(
'
\n
'
,
1
)[
0
])
# TODO: print differences option, ...
command_line
.
add_argument
(
'
--indent-string
'
,
default
=
'
'
,
help
=
'
set indent string [%(default)s]
'
)
command_line
.
add_argument
(
'
--inline-comments
'
,
'
-c
'
,
action
=
'
store_true
'
,
help
=
'
compact white space before inline comments
'
'
(BETA)
'
)
command_line
.
add_argument
(
'
--trailing-space
'
,
'
-t
'
,
action
=
'
store_true
'
,
help
=
'
remove white space at end of lines
'
)
command_line
.
add_argument
(
'
base_config
'
,
help
=
'
name of high level config
'
)
command_line
.
add_argument
(
'
config
'
,
help
=
'
name of low level/expanded config
'
)
command_line
.
add_argument
(
'
-V
'
,
'
--version
'
,
action
=
'
version
'
,
version
=
package_info
.
version
)
args
=
command_line
.
parse_args
()
# File handling
try
:
base_config
=
ConfigObj
(
args
.
base_config
,
interpolation
=
False
,
file_error
=
True
)
config
=
ConfigObj
(
args
.
config
,
interpolation
=
False
,
file_error
=
True
)
except
IOError
as
error
:
die
(
error
.
args
[
0
])
global_dict
=
{}
get_globals
(
base_config
,
global_dict
)
### for k, v in global_dict.items():
### print(k+':', v)
### exit()
eval_globals
(
config
,
global_dict
)
### exit()
# Ready to roll out
lines
=
io
.
BytesIO
()
config
.
write
(
lines
)
lines
.
seek
(
0
)
for
line
in
io
.
TextIOWrapper
(
lines
):
if
args
.
inline_comments
:
line
=
re
.
sub
(
r
'
= (.*?) #
'
,
r
'
= \1 #
'
,
line
)
if
args
.
trailing_space
:
print
(
line
.
rstrip
())
else
:
print
(
line
,
end
=
''
)
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