Skip to content

Instantly share code, notes, and snippets.

@mastier
Created October 18, 2015 09:46
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 mastier/90d4abf52be1f038412d to your computer and use it in GitHub Desktop.
Save mastier/90d4abf52be1f038412d to your computer and use it in GitHub Desktop.
#!/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