Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
dumux-repositories
dumux
Commits
dd0b83b4
Commit
dd0b83b4
authored
4 years ago
by
Dennis Gläser
Browse files
Options
Downloads
Patches
Plain Diff
[bin][util] add python file with reusable functionality
parent
06e80c55
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2230
Feature/install script generator
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/util/common.py
+35
-0
35 additions, 0 deletions
bin/util/common.py
with
35 additions
and
0 deletions
bin/util/common.py
0 → 100644
+
35
−
0
View file @
dd0b83b4
import
os
import
sys
import
functools
import
subprocess
# execute a command and retrieve the output
def
runCommand
(
command
):
try
:
return
subprocess
.
run
(
command
,
shell
=
True
,
check
=
True
,
text
=
True
,
capture_output
=
True
).
stdout
except
Exception
as
e
:
print
()
print
(
"
An error occurred during subprocess run:
"
)
print
(
"
-- command: {}
"
.
format
(
command
))
print
(
"
-- folder: {}
"
.
format
(
os
.
getcwd
()))
print
(
"
-- error: {}
"
.
format
(
sys
.
exc_info
()[
1
]))
if
"
git
"
in
command
:
print
()
print
(
"
It seems that a git command failed. Please check:
\n
"
\
"
-- is the module registered as git repository?
\n
"
\
"
-- is upstream defined for the branch?
\n
"
)
raise
# decorator to call function from within the given path
def
callFromPath
(
path
):
def
decorator_callFromPath
(
callFunc
):
@functools.wraps
(
callFunc
)
def
wrapper_callFromPath
(
*
args
,
**
kwargs
):
curPath
=
os
.
getcwd
()
os
.
chdir
(
path
)
result
=
callFunc
(
*
args
,
**
kwargs
)
os
.
chdir
(
curPath
)
return
result
return
wrapper_callFromPath
return
decorator_callFromPath
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