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
742ff730
Commit
742ff730
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
add new utils to write option in conf.sh | refs
#27883
parent
4e858f63
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.py
+39
-0
39 additions, 0 deletions
utils.py
with
39 additions
and
0 deletions
utils.py
+
39
−
0
View file @
742ff730
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
os
import
os
from
pathlib
import
Path
from
pathlib
import
Path
import
re
import
subprocess
import
subprocess
import
sys
import
sys
from
typing
import
Any
from
typing
import
Any
...
@@ -210,6 +211,44 @@ def get_conf(name: str, default: str = None) -> str:
...
@@ -210,6 +211,44 @@ def get_conf(name: str, default: str = None) -> str:
return
conf
.
get
(
name
,
default
)
return
conf
.
get
(
name
,
default
)
def
set_conf
(
key
:
str
,
value
:
str
,
override
:
bool
=
False
)
->
bool
:
"""
Write the given configuration option in `conf.sh`.
:param key: Option name
:type key: str
:param value: Option value
:type value: str
:param override: Wether to override the option if it already exists, defaults to False
:param override: bool, optional
:return: True if the option have changed, False otherwise
:rtype: bool
"""
state
=
False
# open conf.sh file
conf_fh
=
open
(
Path
(
__file__
,
CONF_PATH
).
resolve
(),
"
w
"
)
# get its content
conf
=
conf_fh
.
read
()
# check if option already exists
regex
=
re
.
compile
(
r
"
^
"
+
key
.
upper
()
+
"
=(.*)$
"
,
flags
=
re
.
M
)
match
=
regex
.
search
(
conf
)
if
match
and
override
:
conf
=
regex
.
sub
(
"
{}=
'
{}
'"
.
format
(
key
.
upper
(),
str
(
value
)),
conf
)
state
=
True
else
:
# add option
conf
=
conf
+
"
\n
{}=
'
{}
'
\n
"
.
format
(
key
.
upper
(),
str
(
value
))
state
=
True
# write file
conf_fh
.
write
(
conf
)
conf_fh
.
close
()
return
state
def
run_commands
(
cmds
:
list
):
def
run_commands
(
cmds
:
list
):
"""
Run a serie of successive commands.
"""
Run a serie of successive commands.
...
...
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