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

39 lines
1.1 KiB
Python
Raw Normal View History

2020-08-18 13:56:58 +00:00
# system
import logging
import os
# local
from .utils.misc import get_project_names, get_project_dir, get_project_down_dir
from ._subcommand import ProjectCommand
class DisableCommand(ProjectCommand):
"""kiwi disable"""
def __init__(self):
super().__init__(
'disable', num_projects='+',
description="Disable whole project(s) in this instance"
)
def run(self, runner, config, args):
result = True
for project_name in get_project_names(args):
project_dir = get_project_dir(config, project_name)
project_down_dir = get_project_down_dir(config, project_name)
if os.path.isdir(project_dir):
logging.info(f"Disabling project '{project_name}'")
os.rename(project_dir, project_down_dir)
elif os.path.isdir(project_down_dir):
logging.warning(f"Project '{project_name}' is already disabled!")
result = False
else:
logging.warning(f"Project '{project_name}' not found in instance!")
result = False
return result