Skip to content

Commit

Permalink
runs the custom command if and only if the user agreed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Bord committed Dec 1, 2008
1 parent 625454f commit fa74b19
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions tdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ class Watcher(object):
"""
file_list = {}
debug = False
use_custom_command = False

def __init__(self, file_path, test_program, debug=False):
def __init__(self, file_path, test_program, debug=False, custom_command=None):
# check configuration
self.check_configuration(file_path, test_program)
self.check_configuration(file_path, test_program, custom_command)
self.file_path = file_path
self.file_list = self.walk(file_path)
self.test_program = test_program
if not custom_command:
self.test_program = test_program
else:
self.test_program = custom_command
self.use_custom_command = True

self.debug = debug

def check_configuration(self, file_path, test_program):
def check_configuration(self, file_path, test_program, custom_command):
"""Checks if configuration is ok."""
# checking filepath
if not os.path.isdir(file_path):
Expand All @@ -56,7 +62,7 @@ def check_configuration(self, file_path, test_program):
)

# checking test_program option
if test_program not in IMPLEMENTED_TEST_PROGRAMS:
if not custom_command and test_program not in IMPLEMENTED_TEST_PROGRAMS:
raise InvalidTestProgram("""INVALID CONFIGURATION: The test program %s is unknown. Valid options are %s""" % (test_program, ', '.join(IMPLEMENTED_TEST_PROGRAMS)))

def include(self, path):
Expand Down Expand Up @@ -112,7 +118,9 @@ def run(self, cmd):
def run_tests(self):
"""Execute tests"""
cmd = None
if self.test_program in ('nose', 'nosetests'):
if self.use_custom_command:
cmd = self.test_program
elif self.test_program in ('nose', 'nosetests'):
cmd = "cd %s && nosetests" % self.file_path
elif self.test_program == 'django':
cmd = "python %s/manage.py test" % self.file_path
Expand Down Expand Up @@ -152,16 +160,35 @@ def main(prog_args=None):
default=False)
parser.add_option('-s', '--size-max', dest='size_max', default=25, type="int",
help="Sets the maximum size (in MB) of files.")
parser.add_option('-c', '--custom-command', dest='custom_command',
default=None, help="Specifies the test command to run."
"\nBIG FAT WARNING: This will run a shell command. Use it at your own"
"risks!!!"
"\nIf the program deletes your whole project, it'll be you fault!")

opt, args = parser.parse_args(prog_args)

if opt.custom_command:
answer = raw_input(
'BIG FAT WARNING! You are about to run the command\n\n $ %s\n\n'
"Every time any file will be added/deleted/edited in your project."
"\nYou must be aware that any shell command automatically ran may"
"erase or corrupt your files."
"\nUSE VERY CAREFULLY!!!"
"\nNow that you've been warned, do you still want to go on? [y/N] " %
opt.custom_command
)
if not answer.startswith('y'):
sys.exit("Ok, bye...")


if args[1:]:
path = args[1]
else:
path = '.'

try:
watcher = Watcher(path, opt.test_program, opt.debug)
watcher = Watcher(path, opt.test_program, opt.debug, opt.custom_command)
agree = True
watcher_file_size = watcher.file_sizes()
if watcher_file_size > opt.size_max:
Expand Down

0 comments on commit fa74b19

Please sign in to comment.