Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/19 interactive output #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions tdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
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 shlex
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',
Expand Down Expand Up @@ -53,7 +54,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):
"""
Expand All @@ -63,7 +64,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)
Expand Down Expand Up @@ -119,7 +120,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':
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -268,7 +271,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:
Expand Down