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
234ea151
Verified
Commit
234ea151
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
use pathlib instead of os
parent
5d4ec482
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
+12
-13
12 additions, 13 deletions
utils.py
with
12 additions
and
13 deletions
utils.py
+
12
−
13
View file @
234ea151
...
...
@@ -3,7 +3,6 @@
"""
EnvSetup utilities.
"""
from
collections
import
OrderedDict
import
os
from
pathlib
import
Path
import
re
import
subprocess
...
...
@@ -84,7 +83,7 @@ def get_dir(file_path: str) -> str:
:rtype: str
"""
return
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
file_path
))
)
return
str
(
Path
(
file_
path
)
.
expanduser
(
).
resolve
().
parent
)
def
exec_cmd
(
cmd
:
Any
,
log_output
:
bool
=
True
,
get_output
:
bool
=
True
)
->
tuple
:
...
...
@@ -153,14 +152,14 @@ def load_conf() -> dict:
conf
=
{}
base_dir
=
get_dir
(
__file__
)
files
=
(
(
os
.
path
.
join
(
base_dir
,
DEFAULT_CONF_PATH
),
True
),
(
os
.
path
.
join
(
base_dir
,
AUTO_CONF_PATH
),
False
),
(
os
.
path
.
join
(
base_dir
,
CONF_PATH
),
False
),
(
str
(
Path
(
base_dir
,
DEFAULT_CONF_PATH
)
)
,
True
),
(
str
(
Path
(
base_dir
,
AUTO_CONF_PATH
)
)
,
False
),
(
str
(
Path
(
base_dir
,
CONF_PATH
)
)
,
False
),
)
only_default
=
True
override
=
OrderedDict
()
for
path
,
is_default
in
files
:
if
not
os
.
path
.
exists
(
path
):
if
not
Path
(
path
)
.
exists
():
if
is_default
:
log
(
"
The configuration file
'
{}
'
does not exist.
"
.
format
(
path
),
...
...
@@ -190,7 +189,7 @@ def load_conf() -> dict:
log
(
"
\033
[93mWarning:
\033
[0m
"
)
log
(
"
The configuration is using only default values.
"
)
log
(
"
Perhaps you forget to change the configuration.
"
)
log
(
"
Path of configuration file: %s
"
%
os
.
path
.
join
(
base_dir
,
CONF_PATH
))
log
(
"
Path of configuration file: %s
"
%
str
(
Path
(
base_dir
,
CONF_PATH
))
)
log
(
"
Perhaps you want to quit this script to change the configuration?
\n
"
)
return
conf
...
...
@@ -279,15 +278,15 @@ def run_commands(cmds: list):
raise
Exception
(
"
No target file to write in.
"
)
if
(
cmd
.
get
(
"
backup
"
)
and
os
.
path
.
exists
(
cmd
[
"
target
"
])
and
not
os
.
path
.
exists
(
cmd
[
"
target
"
]
+
"
.back
"
)
Path
(
cmd
[
"
target
"
])
.
exists
()
and
not
Path
(
cmd
[
"
target
"
]
,
"
.back
"
)
.
exists
()
):
os
.
rename
(
cmd
[
"
target
"
]
,
cmd
[
"
target
"
]
+
"
.back
"
)
Path
(
cmd
[
"
target
"
]
).
rename
(
Path
(
cmd
[
"
target
"
]
,
"
.back
"
)
)
log
(
"
A backup file has been created for:
\n
%s
"
%
cmd
[
"
target
"
])
# Load content from template if any
content
=
cmd
.
get
(
"
content
"
,
""
)
if
cmd
.
get
(
"
template
"
):
if
not
os
.
path
.
exists
(
cmd
[
"
template
"
]):
if
not
Path
(
cmd
[
"
template
"
])
.
exists
()
:
raise
Exception
(
"
Template file does not exist: %s.
"
%
cmd
[
"
template
"
]
)
...
...
@@ -303,8 +302,8 @@ def run_commands(cmds: list):
elif
cmd
[
"
line
"
]
==
"
backup
"
:
if
not
cmd
.
get
(
"
target
"
):
raise
Exception
(
"
No target file to backup.
"
)
if
not
os
.
path
.
exists
(
cmd
[
"
target
"
]
+
"
.back
"
):
os
.
rename
(
cmd
[
"
target
"
]
,
cmd
[
"
target
"
]
+
"
.back
"
)
if
not
Path
(
cmd
[
"
target
"
]
,
"
.back
"
)
.
exists
()
:
Path
(
cmd
[
"
target
"
]
).
rename
(
Path
(
cmd
[
"
target
"
]
,
"
.back
"
)
)
log
(
"
A backup file has been created for:
\n
%s
"
%
cmd
[
"
target
"
])
else
:
log
(
"
A backup file already exist for:
\n
%s
"
%
cmd
[
"
target
"
])
...
...
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