aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/utils.py
diff options
context:
space:
mode:
authorGravatar Christopher Rosell <chrippa@tanuki.se>2011-08-15 04:37:22 +0200
committerGravatar Christopher Rosell <chrippa@tanuki.se>2011-08-15 04:37:22 +0200
commit03ff523bfe2f2a3848470ce0ca46f2ef7116453c (patch)
treeeca46b63d5eee1b67c662c67874ac1f4a6bca5de /src/livestreamer/utils.py
Initial commit.
Diffstat (limited to 'src/livestreamer/utils.py')
-rw-r--r--src/livestreamer/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/livestreamer/utils.py b/src/livestreamer/utils.py
new file mode 100644
index 0000000..6dd13f4
--- /dev/null
+++ b/src/livestreamer/utils.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+class CommandLine(object):
+ def __init__(self, command):
+ self.command = command
+ self.args = {}
+
+ def arg(self, key, value):
+ self.args[key] = value
+
+ def format(self):
+ args = []
+
+ for key, value in self.args.items():
+ if value == True:
+ args.append(("--{0}").format(key))
+ else:
+ escaped = value.replace('"', '\\"').replace("$", "\$").replace("`", "\`")
+ args.append(("--{0} \"{1}\"").format(key, escaped))
+
+ args = (" ").join(args)
+ cmdline = ("{0} {1}").format(self.command, args)
+
+ return cmdline