Skip to content

Instantly share code, notes, and snippets.

@mastier mastier/cmdwrap.py
Created Oct 18, 2015

Embed
What would you like to do?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
def run_cmd(*args):
process = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out = process.communicate()
if process.returncode != 0:
raise Exception(
args, process.returncode, out
)
else:
return out
class CmdWrap(object):
def __init__(self, name, *args):
self.name = name
self.default_args = args
def __getattr__(self, name):
if name in self.__dict__:
return self.__dict__['name']
else:
return lambda *args: run_cmd(
self.name, name, *args
)
def __call__(self, *args):
return run_cmd(self.name, *args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.