Last active
August 29, 2015 14:03
-
-
Save methane/a8c794c301b61fbdb356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class TargetRunner(object): | |
def __init__(self, target, directory, stdout, stderr, args): | |
self.target = target | |
self.directory = directory | |
self.stdout = stdout | |
self.stderr = stderr | |
self.args = args | |
def __getattr__(self, name): | |
"""For backward compatibility.""" | |
return getattr(self.args, name) | |
def start(self): | |
return self.target.start(self, stdout, stderr) | |
def stop(self): | |
return self.target.stop(stdout, stderr) | |
# Utility functions called from setup module. | |
def sh(self, command, **kwargs): | |
"""Utility function for call shell command.""" | |
kwargs.setdefault('cwd', self.directory) | |
self.stdout.write("RUN: %s (cwd=%s)\n" % (command, kwargs.get('cwd'))) | |
self.stdout.flush() | |
subprocess.check_call(command, shell=True, stderr=self.stderr, stdout=self.stdout, **kwargs) | |
def kill_pid(self, pidfile): | |
return self.sh("kill `cat '%s'`" % (pidfile,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Potentially include a pkill based on something like this