Created
March 24, 2013 04:44
-
-
Save schettino72/5230589 to your computer and use it in GitHub Desktop.
doit - example of how to detect obsolote targets in tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOIT_CONFIG = {'verbosity': 2} | |
def targets_diff(task, values): | |
"""to be used as uptodate check - check if targets changed | |
it also save the 'tdiff' to be used by other actions | |
""" | |
now_list = task.targets | |
# set value to be saved if execution is successful | |
def save_list(): | |
return {'target_list': now_list} | |
task.value_savers.append(save_list) | |
# get value saved on last successful execution | |
last_success = values.get('target_list', None) | |
# calculate diff between previous list and now | |
set_new = set(now_list) | |
if last_success is not None: | |
set_old = set(last_success) | |
diff_dict = { | |
'added': (set_new - set_old), | |
'removed': (set_old - set_new), | |
} | |
else: | |
diff_dict = { | |
'added': set_new, | |
'removed': set(), | |
} | |
# hack - add calculated diff to task.options to be used by its actions | |
task.options = {'tdiff': diff_dict} | |
return now_list == last_success | |
def task_x(): | |
def print_diff(tdiff): | |
"""example of action that use target change info, | |
could remove obsolote targets""" | |
print tdiff | |
# simulate targets changing | |
targets = ['1','2','3'] | |
#targets = ['2','3','4'] | |
return { | |
'targets': targets, | |
'actions': ['echo execute task', print_diff], | |
'uptodate': [targets_diff], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment