From e5e90d6dd58148102a511ffc52e56785eca94092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Justen=20=28=40turicas=29?= Date: Thu, 17 Sep 2015 18:02:26 -0300 Subject: [PATCH 1/2] PEP8 fixes --- tdaemon.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tdaemon.py b/tdaemon.py index c39c817..969f2d1 100755 --- a/tdaemon.py +++ b/tdaemon.py @@ -10,18 +10,18 @@ file for more details. """ - -import sys -import os -import optparse -from time import sleep -import hashlib -import subprocess import datetime +import hashlib +import optparse +import os import re import subprocess +import sys + +from time import sleep + -SPECIAL_CHARS_REGEX_PATTERN = r'[#&;`|*?~<>^()\[\]{}$\\]+' +SPECIAL_CHARS_REGEX_PATTERN = r'[#&;`|*?~<>^()\[\]{}$\\]+' IGNORE_EXTENSIONS = ('pyc', 'pyo') IGNORE_DIRS = ('.bzr', '.git', '.hg', '.darcs', '.svn', '.tox') IMPLEMENTED_TEST_PROGRAMS = ('nose', 'nosetests', 'django', 'py', 'symfony', @@ -53,7 +53,7 @@ def ask(message='Are you sure? [y/N]'): def escapearg(args): """Escapes characters you don't want in arguments (preventing shell injection)""" - return re.sub(SPECIAL_CHARS_REGEX_PATTERN, '', args) + return re.sub(SPECIAL_CHARS_REGEX_PATTERN, '', args) class Watcher(object): """ @@ -63,7 +63,7 @@ class Watcher(object): file_list = {} debug = False - def __init__(self, file_path, test_program, debug=False, custom_args='', + def __init__(self, file_path, test_program, debug=False, custom_args='', ignore_dirs=None, quiet=False): # Safe filter custom_args = escapearg(custom_args) @@ -119,7 +119,7 @@ def check_dependencies(self): sys.exit('django is not available on your system. Please install it and try to run it again') if self.test_program == 'phpunit': try: - process = subprocess.check_call(['phpunit','--version']) + process = subprocess.check_call(['phpunit','--version']) except: sys.exit('phpunit is not available on your system. Please install it and try to run it again') if self.test_program == 'tox': @@ -268,7 +268,7 @@ def main(prog_args=None): try: - watcher = Watcher(path, opt.test_program, opt.debug, opt.custom_args, + watcher = Watcher(path, opt.test_program, opt.debug, opt.custom_args, opt.ignore_dirs, opt.quiet) watcher_file_size = watcher.file_sizes() if watcher_file_size > opt.size_max: From 57d92c062520334236566ff6e2fee567e9061152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Justen=20=28=40turicas=29?= Date: Thu, 17 Sep 2015 18:02:38 -0300 Subject: [PATCH 2/2] Implement interactive call. Fix #19 --- tdaemon.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tdaemon.py b/tdaemon.py index 969f2d1..0bb1ee4 100755 --- a/tdaemon.py +++ b/tdaemon.py @@ -15,6 +15,7 @@ import optparse import os import re +import shlex import subprocess import sys @@ -213,9 +214,11 @@ def diff_list(self, list1, list2): def run(self, cmd): """Runs the appropriate command""" print datetime.datetime.now() - output = subprocess.Popen(cmd, shell=True) - output = output.communicate()[0] - print output + process = subprocess.Popen(shlex.split(cmd), + stdin=sys.stdin, + stdout=sys.stdout, + stderr=sys.stderr) + process.wait() def run_tests(self): """Execute tests"""