aboutsummaryrefslogtreecommitdiff
path: root/src/toolkit/common.py
diff options
context:
space:
mode:
authortassaron2017-07-29 13:08:28 -0400
committertassaron2017-07-29 13:08:28 -0400
commitc1457b6dad4640b17679dd802e372bd46a13d2a5 (patch)
tree368ea39f9383cd1e0e779a3860b3691fc3e6b68c /src/toolkit/common.py
parent6f8f178778c63f10b3bda42507c7d44f98884fcd (diff)
starting work on Waveform component
split Video class out of Video component for reuse in Waveform
Diffstat (limited to 'src/toolkit/common.py')
-rw-r--r--src/toolkit/common.py37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/toolkit/common.py b/src/toolkit/common.py
index 251a2c1..128ed08 100644
--- a/src/toolkit/common.py
+++ b/src/toolkit/common.py
@@ -6,9 +6,22 @@ import string
import os
import sys
import subprocess
+import signal
+import math
from collections import OrderedDict
+def scale(scale, width, height, returntype=None):
+ width = (float(width) / 100.0) * float(scale)
+ height = (float(height) / 100.0) * float(scale)
+ if returntype == str:
+ return (str(math.ceil(width)), str(math.ceil(height)))
+ elif returntype == int:
+ return (math.ceil(width), math.ceil(height))
+ else:
+ return (width, height)
+
+
def badName(name):
'''Returns whether a name contains non-alphanumeric chars'''
return any([letter in string.punctuation for letter in name])
@@ -34,29 +47,35 @@ def appendUppercase(lst):
lst.append(form.upper())
return lst
-
-def hideCmdWin(func):
- ''' Stops CMD window from appearing on Windows.
- Adapted from here: http://code.activestate.com/recipes/409002/
- '''
- def decorator(commandList, **kwargs):
+def pipeWrapper(func):
+ '''A decorator to insert proper kwargs into Popen objects.'''
+ def pipeWrapper(commandList, **kwargs):
if sys.platform == 'win32':
+ # Stop CMD window from appearing on Windows
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
kwargs['startupinfo'] = startupinfo
+
+ if 'bufsize' not in kwargs:
+ kwargs['bufsize'] = 10**8
+ if 'stdin' not in kwargs:
+ kwargs['stdin'] = subprocess.DEVNULL
return func(commandList, **kwargs)
- return decorator
+ return pipeWrapper
-@hideCmdWin
+@pipeWrapper
def checkOutput(commandList, **kwargs):
return subprocess.check_output(commandList, **kwargs)
-@hideCmdWin
+@pipeWrapper
def openPipe(commandList, **kwargs):
return subprocess.Popen(commandList, **kwargs)
+def closePipe(pipe):
+ pipe.stdout.close()
+ pipe.send_signal(signal.SIGINT)
def disableWhenEncoding(func):
def decorator(self, *args, **kwargs):