Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
HDL
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
RTSD
HDL
Commits
17ad00f7
Commit
17ad00f7
authored
10 years ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Added remove_key_from_dict_file(). Added rename_key_in_dict_file().
parent
43b1bbd6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/oneclick/base/common_dict_file.py
+34
-2
34 additions, 2 deletions
tools/oneclick/base/common_dict_file.py
with
34 additions
and
2 deletions
tools/oneclick/base/common_dict_file.py
+
34
−
2
View file @
17ad00f7
...
@@ -195,7 +195,7 @@ class CommonDictFile:
...
@@ -195,7 +195,7 @@ class CommonDictFile:
def
insert_key_in_dict_file_before_another_key
(
self
,
filePathName
,
key
,
value
,
beforeKey
):
def
insert_key_in_dict_file_before_another_key
(
self
,
filePathName
,
key
,
value
,
beforeKey
):
"""
Write a new key = value pair in the filePathName file just before another existing beforeKey.
"""
"""
Write a new key = value pair in the filePathName file just before another existing beforeKey.
"""
# Read dict file into string and insert new key = value pair
at insertLineNr
# Read dict file into string and insert new key = value pair
before beforeKey
dict_string
=
''
dict_string
=
''
with
open
(
filePathName
,
'
r
'
)
as
fp
:
with
open
(
filePathName
,
'
r
'
)
as
fp
:
for
line
in
fp
:
for
line
in
fp
:
...
@@ -207,7 +207,39 @@ class CommonDictFile:
...
@@ -207,7 +207,39 @@ class CommonDictFile:
with
open
(
filePathName
,
'
w
'
)
as
fp
:
with
open
(
filePathName
,
'
w
'
)
as
fp
:
fp
.
write
(
dict_string
)
fp
.
write
(
dict_string
)
def
change_key_in_dict_file
(
self
,
filePathName
,
key
,
value
):
def
remove_key_from_dict_file
(
self
,
filePathName
,
key
):
"""
Remove a key and value pair from the dictfile.
"""
# Read dict file into string and skip the lines of the key = value pair that must be removed
dict_string
=
''
with
open
(
filePathName
,
'
r
'
)
as
fp
:
remove_line
=
False
for
line
in
fp
:
if
remove_line
==
True
:
if
line
.
find
(
self
.
CDF_SEPARATOR
)
>=
0
:
remove_line
=
False
# found next key, which indicates the end of remove key-value pair
if
line
.
find
(
key
)
==
0
:
remove_line
=
True
# found key that has to be removed
if
not
remove_line
:
dict_string
+=
line
# Write string to dict file
with
open
(
filePathName
,
'
w
'
)
as
fp
:
fp
.
write
(
dict_string
)
def
rename_key_in_dict_file
(
self
,
filePathName
,
old_key
,
new_key
):
"""
Write new key name for old_key in the filePathName file.
"""
# Read dict file into string
with
open
(
filePathName
,
'
r
'
)
as
fp
:
dict_string
=
fp
.
read
()
# Rename old_key in dict string
old_key_start
=
dict_string
.
find
(
old_key
)
# find old_key
if
old_key_start
>
0
:
separator_start
=
dict_string
.
find
(
self
.
CDF_SEPARATOR
,
old_key_start
)
# find separator
dict_string
=
dict_string
[
0
:
old_key_start
]
+
new_key
+
'
'
+
dict_string
[
separator_start
:]
# replace old key by new key
# Write string to dict file
with
open
(
filePathName
,
'
w
'
)
as
fp
:
fp
.
write
(
dict_string
)
def
change_key_value_in_dict_file
(
self
,
filePathName
,
key
,
value
):
"""
Write new value for key in the filePathName file. The original key = value pair must fit on one line.
"""
"""
Write new value for key in the filePathName file. The original key = value pair must fit on one line.
"""
# Read dict file into string
# Read dict file into string
with
open
(
filePathName
,
'
r
'
)
as
fp
:
with
open
(
filePathName
,
'
r
'
)
as
fp
:
...
...
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