1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 12:53:00 +00:00

readability

This commit is contained in:
Jörn-Michael Miehe 2020-08-18 15:56:22 +02:00
parent 9617597257
commit 3014e7057c
3 changed files with 34 additions and 15 deletions

View file

@ -2,7 +2,7 @@
import logging import logging
# local # local
from .utils.misc import get_project_name, get_services, list_projects from .utils.misc import get_first_project_name, get_services, list_projects
# parent # parent
from ..parser import Parser from ..parser import Parser
@ -42,8 +42,8 @@ class ProjectCommand(SubCommand):
projects = "a project" projects = "a project"
if not str(num_projects) == '1': if not num_projects == 1:
projects = "projects" projects = "project(s)"
self._sub_parser.add_argument( self._sub_parser.add_argument(
'projects', metavar='project', nargs=num_projects, type=str, 'projects', metavar='project', nargs=num_projects, type=str,
@ -62,8 +62,8 @@ class ServiceCommand(ProjectCommand):
services = "a service" services = "a service"
if not str(num_services) == '1': if not num_services == 1:
services = "services" services = "service(s)"
self._sub_parser.add_argument( self._sub_parser.add_argument(
'services', metavar='service', nargs=num_services, type=str, 'services', metavar='service', nargs=num_services, type=str,
@ -104,7 +104,7 @@ class FlexCommand(ServiceCommand):
pass pass
def run(self, runner, config, args): def run(self, runner, config, args):
project_name = get_project_name(args) project_name = get_first_project_name(args)
services = get_services(args) services = get_services(args)
if project_name is None: if project_name is None:

View file

@ -5,7 +5,7 @@ import subprocess
# local # local
from .executable import Executable from .executable import Executable
from .misc import get_project_dir, get_project_name from .misc import get_project_dir, get_first_project_name
# parent # parent
from ..._constants import CONF_DIRECTORY_NAME from ..._constants import CONF_DIRECTORY_NAME
@ -13,7 +13,7 @@ from ..._constants import CONF_DIRECTORY_NAME
def _update_kwargs(config, args, **kwargs): def _update_kwargs(config, args, **kwargs):
# project given in args: command affects a project in this instance # project given in args: command affects a project in this instance
project_name = get_project_name(args) project_name = get_first_project_name(args)
if project_name is not None: if project_name is not None:
# execute command in project directory # execute command in project directory
kwargs['cwd'] = get_project_dir(config, project_name) kwargs['cwd'] = get_project_dir(config, project_name)

View file

@ -1,14 +1,27 @@
import os import os
def get_project_name(args): def get_project_names(args):
"""get project name from CLI args""" """get project names from CLI args"""
if args is not None and 'projects' in args: if args is not None and 'projects' in args:
if isinstance(args.projects, list) and len(args.projects) > 0: if isinstance(args.projects, list):
return args.projects[0] if args.projects:
else: return args.projects
return args.projects else:
return None
elif isinstance(args.projects, str):
return [args.projects]
return None
def get_first_project_name(args):
"""get first project name from CLI args"""
names = get_project_names(args)
if names is not None:
return names[0]
return None return None
@ -28,10 +41,16 @@ def get_project_dir(config, project_name):
return f"{project_name}{config['markers:project']}" return f"{project_name}{config['markers:project']}"
def get_project_down_dir(config, project_name):
"""get project directory"""
return f"{get_project_dir(config, project_name)}{config['markers:down']}"
def get_target_dir(config, project_name): def get_target_dir(config, project_name):
"""get project's target directory""" """get project's target directory"""
return f"{config['runtime:storage']}{get_project_dir(config, project_name)}" return os.path.join(config['runtime:storage'], get_project_dir(config, project_name))
def list_projects(config): def list_projects(config):