Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
6da4acf9
Commit
6da4acf9
authored
8 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
add ability to execute command in a given directory
parent
464d4b29
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
src/python/dm/common/utility/dmSubprocess.py
+22
-9
22 additions, 9 deletions
src/python/dm/common/utility/dmSubprocess.py
with
22 additions
and
9 deletions
src/python/dm/common/utility/dmSubprocess.py
+
22
−
9
View file @
6da4acf9
...
...
@@ -26,17 +26,17 @@ class DmSubprocess(subprocess.Popen):
# Execute command
@classmethod
def
executeCommand
(
cls
,
command
):
def
executeCommand
(
cls
,
command
,
cwd
=
None
):
"""
Create subprocess and run it, return subprocess object.
"""
p
=
cls
.
getSubprocess
(
command
)
p
=
cls
.
getSubprocess
(
command
,
cwd
)
p
.
run
()
return
p
# Execute command, ignore errors.
@classmethod
def
executeCommandAndIgnoreFailure
(
cls
,
command
):
def
executeCommandAndIgnoreFailure
(
cls
,
command
,
cwd
=
None
):
"""
Create subprocess, run it, igore any failures, and return subprocess object.
"""
p
=
cls
.
getSubprocess
(
command
)
p
=
cls
.
getSubprocess
(
command
,
cwd
)
try
:
p
.
run
()
except
CommandFailed
,
ex
:
...
...
@@ -44,9 +44,9 @@ class DmSubprocess(subprocess.Popen):
return
p
@classmethod
def
executeCommandAndLogToStdOut
(
cls
,
command
):
def
executeCommandAndLogToStdOut
(
cls
,
command
,
cwd
=
None
):
"""
Execute command, display output to stdout, maintain log file and return subprocess object.
"""
p
=
cls
.
getSubprocess
(
command
)
p
=
cls
.
getSubprocess
(
command
,
cwd
)
p
.
__commandLog
()
while
True
:
...
...
@@ -76,6 +76,7 @@ class DmSubprocess(subprocess.Popen):
self
.
_stdout
=
None
self
.
_stderr
=
None
self
.
_args
=
args
self
.
_cwd
=
cwd
self
.
useExceptions
=
useExceptions
self
.
quietMode
=
quietMode
...
...
@@ -125,13 +126,25 @@ class DmSubprocess(subprocess.Popen):
def
getExitStatus
(
self
):
return
self
.
returncode
def
toDict
(
self
):
result
=
{
'
command
'
:
self
.
_args
,
'
exitStatus
'
:
self
.
returncode
,
'
stdErr
'
:
self
.
_stderr
,
'
stdOut
'
:
self
.
_stdout
,
'
workingDir
'
:
self
.
_cwd
}
return
result
#######################################################################
# Testing.
if
__name__
==
'
__main__
'
:
p
=
DmSubprocess
(
'
ls -l
'
,
useExceptions
=
False
)
print
p
.
toDict
()
p
.
run
()
print
p
.
getStdOut
()
print
p
.
getStdErr
()
print
p
.
getExitStatus
()
#print p.getStdOut()
#print p.getStdErr()
#print p.getExitStatus()
print
p
.
toDict
()
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