mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43:00 +00:00
Package subcommands.utils
This commit is contained in:
parent
a602076291
commit
daced4dd7d
7 changed files with 48 additions and 42 deletions
18
src/kiwi/subcommands/_subcommand.py
Normal file
18
src/kiwi/subcommands/_subcommand.py
Normal 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
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ import os
|
||||||
from .._constants import KIWI_CONF_NAME
|
from .._constants import KIWI_CONF_NAME
|
||||||
from ..config import DefaultConfig
|
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):
|
def user_input(config, key, prompt):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from ._utils import SubCommand, DockerCommand
|
from ._subcommand import SubCommand
|
||||||
|
from .utils.dockercommand import DockerCommand
|
||||||
|
|
||||||
|
|
||||||
class LogsCommand(SubCommand):
|
class LogsCommand(SubCommand):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from ._utils import SubCommand
|
from ._subcommand import SubCommand
|
||||||
|
|
||||||
|
|
||||||
class ShowCommand(SubCommand):
|
class ShowCommand(SubCommand):
|
||||||
|
|
1
src/kiwi/subcommands/utils/__init__.py
Normal file
1
src/kiwi/subcommands/utils/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# git keep
|
|
@ -1,44 +1,8 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from ..parser import Parser
|
from ...config import LoadedConfig
|
||||||
from ..config import LoadedConfig
|
from .executable import get_exe_key
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class DockerCommand:
|
class DockerCommand:
|
||||||
|
@ -100,4 +64,4 @@ class DockerCommand:
|
||||||
DockerCommand.__instances[exe_name] = DockerCommand.__DockerCommand(exe_name)
|
DockerCommand.__instances[exe_name] = DockerCommand.__DockerCommand(exe_name)
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return getattr(self.__instances[self.__exe_name], item)
|
return getattr(self.__instances[self.__exe_name], item)
|
21
src/kiwi/subcommands/utils/executable.py
Normal file
21
src/kiwi/subcommands/utils/executable.py
Normal 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
|
Loading…
Reference in a new issue