Add tasks_from_directory function

This commit is contained in:
Ivan Malison 2016-11-14 06:09:41 -06:00
parent 94593b2685
commit b97c83f6a6
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -38,3 +38,27 @@ def build_task_factory(ns):
def namespace_and_factory(): def namespace_and_factory():
ns = Collection() ns = Collection()
return ns, build_task_factory(ns) return ns, build_task_factory(ns)
def extension_checker(extension):
extension_suffix = ".{}".format(extension)
def ends_with(string):
return string.endswith(extension_suffix)
return ends_with
def tasks_from_directory(directory_path, file_predicate=extension_checker("sh")):
ns, make_task = namespace_and_factory()
def task_from_file(filepath):
@make_task()
def run_script(ctx):
ctx.run(filepath)
return run_script
filepaths = filter(os.path.isfile,
[os.path.join(directory_path, filename)
for filename in os.listdir(directory_path)])
map(task_from_file, filepaths)
return ns