Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
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
mediaserver
envsetup
Commits
3d77f065
Commit
3d77f065
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
set_conf: fix read/write handling | refs
#27883
parent
e68faf97
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils.py
+13
-15
13 additions, 15 deletions
utils.py
with
13 additions
and
15 deletions
utils.py
+
13
−
15
View file @
3d77f065
...
...
@@ -224,13 +224,11 @@ def set_conf(key: str, value: str, override: bool = False) -> bool:
:rtype: bool
"""
state
=
False
# open conf.sh file
base_dir
=
Path
(
__file__
).
resolve
().
parent
conf_fh
=
open
(
Path
(
base_dir
,
CONF_PATH
).
resolve
(),
"
w+
"
)
# get its content
conf
=
conf_fh
.
read
()
conf_path
=
Path
(
base_dir
,
CONF_PATH
).
resolve
()
# read conf.sh
with
open
(
conf_path
)
as
read_conf_fh
:
conf
=
read_conf_fh
.
read
()
# check if option already exists
regex
=
re
.
compile
(
r
"
^
"
+
key
.
upper
()
+
"
=(.*)$
"
,
flags
=
re
.
M
)
...
...
@@ -238,17 +236,17 @@ def set_conf(key: str, value: str, override: bool = False) -> bool:
if
match
and
override
:
# override option
conf
=
regex
.
sub
(
"
{}=
'
{}
'"
.
format
(
key
.
upper
(),
str
(
value
)),
conf
)
state
=
True
with
open
(
conf_path
,
"
w
"
)
as
conf_fh
:
conf_fh
.
write
(
conf
)
return
True
elif
not
match
:
# add option
conf
=
conf
+
"
\n
{}=
'
{}
'
\n
"
.
format
(
key
.
upper
(),
str
(
value
))
state
=
True
# write file
conf_fh
.
write
(
conf
)
conf_fh
.
close
()
return
state
with
open
(
conf_path
,
"
a
"
)
as
conf_fh
:
conf_fh
.
write
(
"
\n
{}=
'
{}
'
\n
"
.
format
(
key
.
upper
(),
str
(
value
)))
return
True
else
:
# no override
return
False
def
run_commands
(
cmds
:
list
):
...
...
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