Skip to content
Permalink
Browse files

Now seems to work. At least partially.

  • Loading branch information
felixfontein committed Jan 14, 2015
1 parent c455ee6 commit ff493d64ca11506c05f1bc5a19b27e9c84d8c5fe
Showing with 44 additions and 24 deletions.
  1. +44 −24 test.py
68 test.py
@@ -17,27 +17,39 @@ def __init__(self, program):
self.program = program

def _generate_level(self, levels):
if len(levels) == 0: return []
level = levels[0]
tasks = generate_tasks('level_' + str(level), self.program.get_tasks(level))
names = set()
print("GENERATE {0}".format(level))

def flatten(task):
if isinstance(task, dict):
yield task
else:
for t in task:
for ft in flatten(t):
yield ft

for task in self.program.get_tasks(level):
for t in flatten(task):
names.add(t['basename'])
yield t
mid_name = 'level_' + str(level) + '_wait'
done_name = 'level_' + str(level) + '_done'
yield { 'basename': mid_name, 'doc': None, 'task_dep': list(names), 'actions': ['echo'] }
done_deps = [mid_name]
if len(levels) > 1:
eol_name = 'level_' + str(level) + '_wait'
tasks.extend(generate_tasks(eol_name, { 'basename': eol_name, 'task_dep': [ t.name for t in tasks ], 'actions': [ ] }))
next_level = levels[1]
tasks.append(Task('level_' + str(next_level) + '_generate', None, loader=DelayedLoader(lambda: self._generate_more(levels[1:]), executed='level_' + str(level) + '_wait')))
return tasks

def _generate_more(self, levels):
tasks = self._generate_level(levels)
for t in tasks:
yield t
gen_name = 'level_' + str(levels[1]) + '_done'
done_deps.append(gen_name)
yield Task(gen_name, None, loader=DelayedLoader(lambda: self._generate_level(levels[1:]), executed=mid_name))
yield { 'basename': done_name, 'doc': None, 'task_dep': done_deps, 'actions': ['echo'] }

def load_tasks(self, cmd, opt_values, pos_args):
DOIT_CONFIG = {
'reporter': ExecutedOnlyReporter,
'outfile': sys.stderr,
}
tasks = self._generate_level(self.program.get_task_levels())
levels = self.program.get_task_levels()
tasks = generate_tasks('level_' + str(levels[0]) + '_generate', self._generate_level(levels))
return tasks, DOIT_CONFIG


@@ -67,33 +79,37 @@ def _do_copy(self, source, destination):
write_content(destination, content)

def get_task_levels(self):
return [1, 2, 3]
return [1, 2, 3, 4]

def _create_tasks(self, *files):
def _create_tasks(self, basename, *files):
for src_file, dst_file in files:
yield {
'basename': 'copy',
'basename': basename,
'name': dst_file,
'file_dep': [src_file],
'targets': [dst_file],
'actions': [(self._do_copy, (src_file, dst_file))],
'clean': True,
}

def _get_tasks_impl(self, level):
def _get_tasks_impl(self, suffix, level):
if level == 1:
yield self._create_tasks(('1', 'dest/1.a'), ('2', 'dest/2.a'), ('dest/2.a', 'dest/2.b'))
yield self._create_tasks('copy' + suffix, ('1', 'dest/1.a'), ('2', 'dest/2.a'), ('dest/2.a', 'dest/2.b'))
elif level == 2:
yield self._create_tasks(('dest/1.a', 'dest/1.b'))
yield self._create_tasks('copy' + suffix, ('dest/1.a', 'dest/1.b'), ('2', 'dest/2.e'))
elif level == 3:
yield self._create_tasks(('1', 'dest/1.c'), ('dest/2.b', 'dest/2.c'))
yield self._create_tasks('copy' + suffix, ('1', 'dest/1.c'), ('dest/2.b', 'dest/2.c'))
elif level == 4:
yield self._create_tasks('copy' + suffix, ('dest/1.c', 'dest/1.d'), ('dest/2.d', 'dest/2.f'), ('dest/2.c', 'dest/2.d'))

def get_tasks(self, level):
suffix = '_' + str(level)
yield {
'basename': 'copy',
'basename': 'copy' + suffix,
'name': None,
'doc': 'Copies modified or non-existing files over',
}
yield self._get_tasks_impl(level)
yield self._get_tasks_impl(suffix, level)

def get_all_tasks(self):
yield {
@@ -102,7 +118,7 @@ def get_all_tasks(self):
'doc': 'Copies modified or non-existing files over',
}
for level in self.get_task_levels():
yield self._get_tasks_impl(level)
yield self._get_tasks_impl('', level)


def main(args=None):
@@ -111,11 +127,15 @@ def main(args=None):


if __name__ == "__main__":
#sys.exit(main(['clean']))
try:
pass
shutil.rmtree('dest', True)
except:
pass
os.mkdir('dest')
write_content('1', 'bla')
write_content('2', 'bla')
sys.exit(main(['run', '-n', '4', '-P', 'thread']))
#sys.exit(main(['list']))
sys.exit(main(['run', '-v', '2']))
#sys.exit(main(['run', '-n', '4', '-v', '2', '-P', 'thread']))

0 comments on commit ff493d6

Please sign in to comment.
You can’t perform that action at this time.