risotto/ansible/action_plugins/build_images.py

45 lines
1.8 KiB
Python
Raw Normal View History

2022-10-01 22:33:11 +02:00
#!/usr/bin/python3
from os import listdir, makedirs
from os.path import isfile, isdir, join, dirname
from shutil import copy2, copytree, rmtree
from ansible.plugins.action import ActionBase
from risotto.utils import RISOTTO_CONFIG
2023-01-23 20:23:32 +01:00
2022-10-01 22:33:11 +02:00
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
super(ActionModule, self).run(tmp, task_vars)
module_args = self._task.args.copy()
modules = module_args['modules']
2023-01-23 20:23:32 +01:00
copy_tests = module_args.get('copy_tests', False)
2022-12-21 16:35:58 +01:00
dataset_directories = RISOTTO_CONFIG['directories']['datasets']
2022-10-01 22:33:11 +02:00
install_dir = join('/tmp/risotto/images')
if isdir(install_dir):
rmtree(install_dir)
2023-01-23 20:23:32 +01:00
if copy_tests:
install_tests_dir = join('/tmp/risotto/tests')
if isdir(install_tests_dir):
rmtree(install_tests_dir)
2022-10-01 22:33:11 +02:00
for module_name, depends in modules.items():
2022-12-21 16:35:58 +01:00
for dataset_directory in dataset_directories:
for depend in depends:
2023-01-23 20:23:32 +01:00
if copy_tests:
tests_dir = join(dataset_directory, depend, 'tests')
if isdir(tests_dir):
for filename in listdir(tests_dir):
src_file = join(tests_dir, filename)
dst_file = join(install_tests_dir, module_name, filename)
copy(src_file, dst_file)
# manual = join(dataset_directory, depend, 'manual', 'image')
# if not isdir(manual):
# continue
# for filename in listdir(manual):
# src_file = join(manual, filename)
# dst_file = join(install_dir, module_name, filename)
# copy(src_file, dst_file)
2022-10-01 22:33:11 +02:00
return dict(ansible_facts=dict({}))