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

Package subcommands.utils

This commit is contained in:
Jörn-Michael Miehe 2020-08-12 16:43:13 +02:00
parent a602076291
commit daced4dd7d
7 changed files with 48 additions and 42 deletions

View file

@ -0,0 +1,18 @@
from ..parser import Parser
class SubCommand:
__name = None
_sub_parser = None
def __init__(self, name, **kwargs):
self.__name = name
self._sub_parser = Parser().get_subparsers().add_parser(name, **kwargs)
def __str__(self):
return self.__name
def run(self, config, args):
pass

View file

@ -4,7 +4,8 @@ import os
from .._constants import KIWI_CONF_NAME
from ..config import DefaultConfig
from ._utils import SubCommand, is_executable, find_exe_file, get_exe_key
from ._subcommand import SubCommand
from .utils.executable import get_exe_key, is_executable, find_exe_file
def user_input(config, key, prompt):

View file

@ -1,6 +1,7 @@
import logging
from ._utils import SubCommand, DockerCommand
from ._subcommand import SubCommand
from .utils.dockercommand import DockerCommand
class LogsCommand(SubCommand):

View file

@ -1,4 +1,4 @@
from ._utils import SubCommand
from ._subcommand import SubCommand
class ShowCommand(SubCommand):

View file

@ -0,0 +1 @@
# git keep

View file

@ -1,44 +1,8 @@
import logging
import os
import subprocess
from ..parser import Parser
from ..config import LoadedConfig
def is_executable(filename):
if filename is None:
return False
return os.path.isfile(filename) and os.access(filename, os.X_OK)
def find_exe_file(exe_name):
for path in os.environ['PATH'].split(os.pathsep):
exe_file = os.path.join(path, exe_name)
if is_executable(exe_file):
return exe_file
return None
def get_exe_key(exe_name):
return f'executables:{exe_name}'
class SubCommand:
__name = None
_sub_parser = None
def __init__(self, name, **kwargs):
self.__name = name
self._sub_parser = Parser().get_subparsers().add_parser(name, **kwargs)
def __str__(self):
return self.__name
def run(self, config, args):
pass
from ...config import LoadedConfig
from .executable import get_exe_key
class DockerCommand:
@ -100,4 +64,4 @@ class DockerCommand:
DockerCommand.__instances[exe_name] = DockerCommand.__DockerCommand(exe_name)
def __getattr__(self, item):
return getattr(self.__instances[self.__exe_name], item)
return getattr(self.__instances[self.__exe_name], item)

View file

@ -0,0 +1,21 @@
import os
def get_exe_key(exe_name):
return f'executables:{exe_name}'
def is_executable(filename):
if filename is None:
return False
return os.path.isfile(filename) and os.access(filename, os.X_OK)
def find_exe_file(exe_name):
for path in os.environ['PATH'].split(os.pathsep):
exe_file = os.path.join(path, exe_name)
if is_executable(exe_file):
return exe_file
return None