Skip to content

Commit

Permalink
sub-command "clean" option "clean-dep" to follow dependencies (#444247)
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : eduardo%40eduardo-laptop-20100401152205-wa3lklyc79iqly0h
  • Loading branch information
schettino72 committed Apr 1, 2010
1 parent 5a0b69f commit a89b559
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Changes
0.7.0
=======

-
- sub-command "clean" option "clean-dep" to follow dependencies (#444247)
- task dependency "False" means never up-to-date, "None" ignored
- sub-command "list" by default do not show tasks starting with an underscore, added option (-p/--private)
- new sub-coomand "auto"
Expand Down
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
----------

. 524387 configure options on dodo file
. 444247 command clean follow dependencies
. 444243 clean and forget acts on all tasks, they should act only on default tasks
. 441084 tests for cmdline

Expand Down
30 changes: 22 additions & 8 deletions doit/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,34 @@ def doit_run(dependencyFile, task_list, output, options=None,



def doit_clean(task_list, outstream, dryrun, clean_tasks):
def doit_clean(task_list, outstream, dryrun, clean_dep, clean_tasks):
"""Clean tasks
@param task_list (list - L{Task}): list of all tasks from dodo file
@ivar dryrun (bool): if True clean tasks are not executed
(just print out what would be executed)
@param clean_tasks (list - string): tasks bo be clean. clean all if
empty list.
@param clean_dep (bool): execute clean from task_dep
"""
tasks = dict([(t.name, t) for t in task_list])
cleaned = set()

def clean_task(task_name):
if task_name not in cleaned:
cleaned.add(task_name)
tasks[task_name].clean(outstream, dryrun)

# clean all tasks if none specified
if not clean_tasks:
# clean all tasks
for task_ in task_list:
task_.clean(outstream, dryrun)
else:
tasks = dict([(t.name, t) for t in task_list])
for name in clean_tasks:
tasks[name].clean(outstream, dryrun)
clean_tasks = [t.name for t in task_list]

for name in clean_tasks:
if clean_dep:
for td in tasks[name].task_dep:
clean_task(td)
clean_task(name)




Expand Down
13 changes: 10 additions & 3 deletions doit/doit_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def cmd_run(params, args):
'default': False,
'help': "print private tasks (start with '_')"}

# TODO list should support "args" as a filter.

def cmd_list(params, args):
dodo_module = main.get_module(params['dodoFile'], params['cwdPath'])
command_names = params['sub'].keys()
Expand All @@ -236,12 +236,19 @@ def cmd_list(params, args):
'default': False,
'help': 'print actions without really executing them'}

opt_clean_cleandep = {'name': 'cleandep',
'short': 'c', # clean
'long': 'clean-dep',
'type': bool,
'default': False,
'help': 'clean task dependencies too'}

def cmd_clean(params, args):
dodo_module = main.get_module(params['dodoFile'], params['cwdPath'])
command_names = params['sub'].keys()
dodo_tasks = main.load_task_generators(dodo_module, command_names)
return doit_clean(dodo_tasks['task_list'], sys.stdout, params['dryrun'],
args)
params['cleandep'], args)


##########################################################
Expand Down Expand Up @@ -384,7 +391,7 @@ def cmd_main(cmd_args):
subCmd['run'] = cmdparse.Command('run', run_options, cmd_run, run_doc)

# clean command
clean_options = (opt_dodo, opt_cwd, opt_clean_dryrun)
clean_options = (opt_dodo, opt_cwd, opt_clean_cleandep, opt_clean_dryrun)
subCmd['clean'] = cmdparse.Command('clean', clean_options, cmd_clean,
clean_doc)

Expand Down
6 changes: 5 additions & 1 deletion doit/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,11 @@ def execute(self, out=None, err=None, verbosity=None):


def clean(self, outstream, dryrun):
"""Execute task's clean"""
"""Execute task's clean
@ivar outstream: 'write' output into this stream
@ivar dryrun (bool): if True clean tasks are not executed
(just print out what would be executed)
"""
# if clean is True remove all targets
if self._remove_targets is True:
files = filter(os.path.isfile, self.targets)
Expand Down
30 changes: 20 additions & 10 deletions tests/test_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,35 @@ class TestCmdClean(object):

def pytest_funcarg__tasks(self, request):
def create_tasks():
self.count = 0
self.tasks = [Task("t1", None, clean=[(self.increment,)]),
Task("t2", None, clean=[(self.increment,)]),]
self.cleaned = []
def myclean(name):
self.cleaned.append(name)
self.tasks = [Task("t1", None, dependencies=[':t2'],
clean=[(myclean,('t1',))]),
Task("t2", None, clean=[(myclean,('t2',))]),]
return request.cached_setup(
setup=create_tasks,
scope="function")

def increment(self):
self.count += 1
return True

def test_clean_all(self, tasks):
output = StringIO.StringIO()
cmds.doit_clean(self.tasks, output, False, [])
assert 2 == self.count
cmds.doit_clean(self.tasks, output, False, False, [])
assert ['t1','t2'] == self.cleaned

def test_clean_selected(self, tasks):
output = StringIO.StringIO()
cmds.doit_clean(self.tasks, output, False, ['t2'])
cmds.doit_clean(self.tasks, output, False, False, ['t2'])
assert ['t2'] == self.cleaned

def test_clean_taskdep(self, tasks):
output = StringIO.StringIO()
cmds.doit_clean(self.tasks, output, False, True, ['t1'])
assert ['t2', 't1'] == self.cleaned

def test_clean_taskdep_once(self, tasks):
output = StringIO.StringIO()
cmds.doit_clean(self.tasks, output, False, True, ['t1', 't2'])
assert ['t2', 't1'] == self.cleaned


class TestCmdIgnore(object):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_ruOnce_or_fileDependency(self):

def test_title(self):
t = task.Task("MyName",["MyAction"])
assert "MyName" == t.name, t.name
assert "MyName" == t.title()


def test_custom_title(self):
Expand Down

0 comments on commit a89b559

Please sign in to comment.