Created
September 4, 2016 17:49
-
-
Save radium226/ceb4b81c48357d81510b275a813189b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/env python | |
class Option(object): | |
def __init__(self, key, name, expects_value): | |
self.key = key | |
self.name = name | |
self.expects_value = expects_value | |
def format_value(self, value): | |
formatted_value = None | |
if hasattr(value, "name"): | |
formatted_value = file.name | |
else: | |
formatted_value = str(value) | |
return formatted_value | |
class Binary(object): | |
def __init__(self, path): | |
self.path = path | |
self.options = dict() | |
def option(self, key, name, expects_value = True, value_type = None, hidden = False, default = None): | |
self.options[key] = Option(key, name, expects_value) | |
return self | |
@staticmethod | |
def __format_option(option, value): | |
return [option.name, option.format_value(value)] | |
def __call__(self, *args, **kwargs): | |
arguments = [self.path] | |
for key, value in kwargs.items(): | |
option = self.options[key] | |
arguments += self.__format_option(option, value) | |
arguments += args | |
print(arguments) | |
@classmethod | |
def path(cls, path): | |
return Binary(path) | |
if __name__ == "__main__": | |
ffmpeg = Binary \ | |
.path("/usr/bin/ffmpeg") \ | |
.option("input", "-i", expects_value = True) | |
ffmpeg(input = "test") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment