Skip to content

Instantly share code, notes, and snippets.

@methane
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save methane/a8c794c301b61fbdb356 to your computer and use it in GitHub Desktop.
Save methane/a8c794c301b61fbdb356 to your computer and use it in GitHub Desktop.
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,))
@hamiltont
Copy link

Note: Potentially include a pkill based on something like this

  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  out, err = p.communicate()
  for line in out.splitlines():
    if 'mono-server' in line:
      pid = int(line.split(None, 2)[1])
      os.kill(pid, 15)
  return 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment