/usr/share/pyshared/doit/cmd_clean.py is in python-doit 0.24.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | from .cmd_base import DoitCmdBase
from .cmd_base import check_tasks_exist, tasks_and_deps_iter, subtasks_iter
opt_clean_dryrun = {
'name': 'dryrun',
'short': 'n', # like make dry-run
'long': 'dry-run',
'type': bool,
'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',
}
opt_clean_cleanall = {
'name': 'cleanall',
'short': 'a', # all
'long': 'clean-all',
'type': bool,
'default': False,
'help': 'clean all task',
}
class Clean(DoitCmdBase):
doc_purpose = "clean action / remove targets"
doc_usage = "[TASK ...]"
doc_description = ("If no task is specified clean default tasks and "
"set --clean-dep automatically.")
cmd_options = (opt_clean_cleandep, opt_clean_cleanall, opt_clean_dryrun)
def clean_tasks(self, tasks, dryrun):
"""ensure task clean-action is executed only once"""
cleaned = set()
for task in tasks:
if task.name not in cleaned:
cleaned.add(task.name)
task.clean(self.outstream, dryrun)
def _execute(self, dryrun, cleandep, cleanall, pos_args=None):
"""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 cleandep (bool): execute clean from task_dep
@param cleanall (bool): clean all tasks
@var default_tasks (list - string): list of default tasks
@var selected_tasks (list - string): list of tasks selected from cmd line
"""
tasks = dict([(t.name, t) for t in self.task_list])
default_tasks = self.config.get('default_tasks')
selected_tasks = pos_args
check_tasks_exist(tasks, selected_tasks)
# get base list of tasks to be cleaned
if cleanall:
clean_list = [t.name for t in self.task_list]
elif selected_tasks:
clean_list = selected_tasks
else:
if default_tasks is None:
clean_list = [t.name for t in self.task_list]
else:
clean_list = default_tasks
# if cleaning default tasks enable clean_dep automatically
cleandep = True
# include dependencies in list
if cleandep:
# including repeated entries will garantee that deps are listed
# first when the list is reversed
to_clean = list(tasks_and_deps_iter(tasks, clean_list, True))
to_clean.reverse()
# include only subtasks in list
else:
to_clean = []
for name in clean_list:
task = tasks[name]
to_clean.extend(subtasks_iter(tasks, task))
to_clean.append(task)
self.clean_tasks(to_clean, dryrun)
|