kiwi-scp/src/kiwi/subcommands/copy_conf.py

50 lines
1.3 KiB
Python
Raw Normal View History

2020-08-17 14:47:08 +00:00
# system
import logging
import os
import subprocess
# parent
from .._constants import KIWI_ROOT
# local
from ._subcommand import SubCommand
from .utils.dockercommand import DockerCommand
from .utils.project import list_projects, get_project_dir
from .utils.rootkit import Rootkit, prefix_path
2020-08-17 14:47:08 +00:00
def _add_prefix(prefix, path):
abs_path = os.path.abspath(path)
return os.path.realpath(prefix + '/' + abs_path)
class CopyConfCommand(SubCommand):
"""kiwi copy-conf"""
def __init__(self):
super().__init__(
'copy-conf',
description="Synchronize all config files to target directory"
)
def run(self, runner, config, args):
conf_dirs = []
2020-08-17 14:47:08 +00:00
for project_name in list_projects(config):
project_conf = f"{get_project_dir(config, project_name)}/conf"
if os.path.isdir(project_conf):
conf_dirs.append(project_conf)
2020-08-17 14:47:08 +00:00
if conf_dirs:
# add target directory
conf_dirs.append(config['runtime:storage'])
logging.info(f"Sync directories: {conf_dirs}")
2020-08-17 14:47:08 +00:00
Rootkit('rsync').run(
config, args, ['rsync', '-r', *prefix_path(conf_dirs)],
2020-08-17 14:47:08 +00:00
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
return True