mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-25 18:42:59 +00:00
readability
This commit is contained in:
parent
9617597257
commit
3014e7057c
3 changed files with 34 additions and 15 deletions
|
@ -2,7 +2,7 @@
|
|||
import logging
|
||||
|
||||
# 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
|
||||
from ..parser import Parser
|
||||
|
@ -42,8 +42,8 @@ class ProjectCommand(SubCommand):
|
|||
|
||||
projects = "a project"
|
||||
|
||||
if not str(num_projects) == '1':
|
||||
projects = "projects"
|
||||
if not num_projects == 1:
|
||||
projects = "project(s)"
|
||||
|
||||
self._sub_parser.add_argument(
|
||||
'projects', metavar='project', nargs=num_projects, type=str,
|
||||
|
@ -62,8 +62,8 @@ class ServiceCommand(ProjectCommand):
|
|||
|
||||
services = "a service"
|
||||
|
||||
if not str(num_services) == '1':
|
||||
services = "services"
|
||||
if not num_services == 1:
|
||||
services = "service(s)"
|
||||
|
||||
self._sub_parser.add_argument(
|
||||
'services', metavar='service', nargs=num_services, type=str,
|
||||
|
@ -104,7 +104,7 @@ class FlexCommand(ServiceCommand):
|
|||
pass
|
||||
|
||||
def run(self, runner, config, args):
|
||||
project_name = get_project_name(args)
|
||||
project_name = get_first_project_name(args)
|
||||
services = get_services(args)
|
||||
|
||||
if project_name is None:
|
||||
|
|
|
@ -5,7 +5,7 @@ import subprocess
|
|||
|
||||
# local
|
||||
from .executable import Executable
|
||||
from .misc import get_project_dir, get_project_name
|
||||
from .misc import get_project_dir, get_first_project_name
|
||||
|
||||
# parent
|
||||
from ..._constants import CONF_DIRECTORY_NAME
|
||||
|
@ -13,7 +13,7 @@ from ..._constants import CONF_DIRECTORY_NAME
|
|||
|
||||
def _update_kwargs(config, args, **kwargs):
|
||||
# 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:
|
||||
# execute command in project directory
|
||||
kwargs['cwd'] = get_project_dir(config, project_name)
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_project_name(args):
|
||||
"""get project name from CLI args"""
|
||||
def get_project_names(args):
|
||||
"""get project names from CLI args"""
|
||||
|
||||
if args is not None and 'projects' in args:
|
||||
if isinstance(args.projects, list) and len(args.projects) > 0:
|
||||
return args.projects[0]
|
||||
else:
|
||||
return args.projects
|
||||
if isinstance(args.projects, list):
|
||||
if 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
|
||||
|
||||
|
@ -28,10 +41,16 @@ def get_project_dir(config, project_name):
|
|||
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):
|
||||
"""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):
|
||||
|
|
Loading…
Reference in a new issue