Created
October 18, 2015 09:46
-
-
Save mastier/90d4abf52be1f038412d 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
#!/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