2020-08-17 14:47:08 +00:00
|
|
|
# system
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
# parent
|
2020-08-18 10:24:55 +00:00
|
|
|
from .._constants import CONF_DIRECTORY_NAME
|
2020-08-17 14:47:08 +00:00
|
|
|
|
|
|
|
# local
|
|
|
|
from ._subcommand import SubCommand
|
|
|
|
from .utils.project import list_projects, get_project_dir
|
2020-08-18 10:24:55 +00:00
|
|
|
from .utils.rootkit import Rootkit, _prefix_path_mnt
|
2020-08-17 14:47:08 +00:00
|
|
|
|
|
|
|
|
2020-08-18 10:24:55 +00:00
|
|
|
class ConfCopyCommand(SubCommand):
|
|
|
|
"""kiwi conf-copy"""
|
2020-08-17 14:47:08 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
2020-08-18 10:24:55 +00:00
|
|
|
'conf-copy',
|
2020-08-17 14:47:08 +00:00
|
|
|
description="Synchronize all config files to target directory"
|
|
|
|
)
|
|
|
|
|
|
|
|
def run(self, runner, config, args):
|
2020-08-17 15:56:29 +00:00
|
|
|
conf_dirs = []
|
2020-08-17 14:47:08 +00:00
|
|
|
|
|
|
|
for project_name in list_projects(config):
|
2020-08-18 10:24:55 +00:00
|
|
|
project_conf = f"{get_project_dir(config, project_name)}/{CONF_DIRECTORY_NAME}"
|
2020-08-17 14:47:08 +00:00
|
|
|
|
|
|
|
if os.path.isdir(project_conf):
|
2020-08-17 15:56:29 +00:00
|
|
|
conf_dirs.append(project_conf)
|
2020-08-17 14:47:08 +00:00
|
|
|
|
2020-08-17 15:56:29 +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
|
|
|
|
2020-08-17 15:56:29 +00:00
|
|
|
Rootkit('rsync').run(
|
2020-08-18 10:24:55 +00:00
|
|
|
config, args, ['rsync', '-r', *_prefix_path_mnt(conf_dirs)],
|
2020-08-17 14:47:08 +00:00
|
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
|
|
|
)
|
|
|
|
|
|
|
|
return True
|
2020-08-18 10:24:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ConfPurgeCommand(SubCommand):
|
|
|
|
"""kiwi conf-purge"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
'conf-purge',
|
|
|
|
description="Remove all config files in target directory"
|
|
|
|
)
|
|
|
|
|
|
|
|
def run(self, runner, config, args):
|
|
|
|
conf_target = f"{config['runtime:storage']}/{CONF_DIRECTORY_NAME}"
|
|
|
|
logging.info(f"Purging directories: {conf_target}")
|
|
|
|
|
|
|
|
Rootkit().run(
|
|
|
|
config, args, ['rm', '-rf', _prefix_path_mnt(conf_target)],
|
|
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
|
|
|
)
|
|
|
|
|
|
|
|
return True
|