summaryrefslogtreecommitdiffstats
path: root/src/pyfedpkg/__init__.py
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2010-08-20 14:42:29 -0700
committerJesse Keating <jkeating@redhat.com>2010-08-20 14:42:29 -0700
commit64de44f9c840da0d51e9a91da08e3abb043d235a (patch)
treea698ac0bf972043caa4c296c19daca250a1bc7f8 /src/pyfedpkg/__init__.py
parentbc308193dc814a4aaef0634def8688835aa52112 (diff)
downloadfedora-packager-64de44f9c840da0d51e9a91da08e3abb043d235a.tar.gz
fedora-packager-64de44f9c840da0d51e9a91da08e3abb043d235a.tar.xz
fedora-packager-64de44f9c840da0d51e9a91da08e3abb043d235a.zip
Add support for running a command from a specific dir
Diffstat (limited to 'src/pyfedpkg/__init__.py')
-rw-r--r--src/pyfedpkg/__init__.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 53d218d..f4a02bf 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -91,7 +91,7 @@ def _hash_file(file, hashtype):
input.close()
return sum.hexdigest()
-def _run_command(cmd, shell=False, env=None, pipe=[]):
+def _run_command(cmd, shell=False, env=None, pipe=[], cwd=None):
"""Run the given command.
Will determine if caller is on a real tty and if so stream to the tty
@@ -106,6 +106,8 @@ def _run_command(cmd, shell=False, env=None, pipe=[]):
pipe is a command to pipe the output of cmd into
+ cwd is the optional directory to run the command from
+
Raises on error, or returns nothing.
"""
@@ -136,15 +138,18 @@ def _run_command(cmd, shell=False, env=None, pipe=[]):
if pipe:
proc = subprocess.Popen(command, env=environ,
stdout=subprocess.PIPE,
- stderr=sys.stderr, shell=shell)
+ stderr=sys.stderr, shell=shell,
+ cwd=cwd)
subprocess.check_call(pipecmd, env=environ,
stdout=sys.stdout,
stderr=sys.stderr,
stdin=proc.stdout,
- shell=shell)
+ shell=shell,
+ cwd=cwd)
else:
subprocess.check_call(command, env=environ, stdout=sys.stdout,
- stderr=sys.stderr, shell=shell)
+ stderr=sys.stderr, shell=shell,
+ cwd=cwd)
except (subprocess.CalledProcessError,
OSError), e:
raise FedpkgError(e)
@@ -163,16 +168,19 @@ def _run_command(cmd, shell=False, env=None, pipe=[]):
if pipe:
proc1 = subprocess.Popen(command, env=environ,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=shell)
+ stderr=subprocess.PIPE, shell=shell,
+ cwd=cwd)
proc2 = subprocess.Popen(pipecmd, env=environ,
stdin=proc1.stdout,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=shell)
+ stderr=subprocess.PIPE, shell=shell,
+ cwd=cwd)
output, error = proc2.communicate()
else:
proc = subprocess.Popen(command, env=environ,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=shell)
+ stderr=subprocess.PIPE, shell=shell,
+ cwd=cwd)
output, error = proc.communicate()
except OSError, e:
raise FedpkgError(e)