Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# pylint: skip-file
name = "silex_client"
timestamp = 0
version = "deadline-0.0.1"
version = "prod.0.1.0"


authors = ["ArtFx TD gang"]

Expand Down
2 changes: 1 addition & 1 deletion silex_client/action/action_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def execute_commands(self, step_by_step: bool = False) -> None:
if step_by_step:
command_iterator = [next(self.command_iterator)]

# Execut all the commands one by one
# Execute all the commands one by one
for command in command_iterator:
# Set the status to initialized
command.status = Status.INITIALIZED
Expand Down
12 changes: 9 additions & 3 deletions silex_client/cli/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,25 @@ def launch_handler(dcc: str, **kwargs) -> None:
return

command = [dcc]
args_list = []


if kwargs.get("task_id") is not None:
os.environ["SILEX_TASK_ID"] = kwargs["task_id"]

if kwargs.get("file") is not None:
command.append(kwargs["file"])
actions = Config.get().actions

# check for env variable
if os.environ.get("SILEX_DCC_BIN") is not None:
command[0] = os.environ["SILEX_DCC_BIN"]
command.pop(0)
args_list = [os.environ["SILEX_DCC_BIN"]]

additional_args = os.environ.get("SILEX_DCC_BIN_ARGS")
if additional_args is not None:
command.extend(additional_args.split(" "))
args_list.extend(additional_args.split(" "))

new_command = args_list + command

subprocess.Popen(command, cwd=os.getcwd(), shell=True)
subprocess.Popen(new_command, cwd=os.getcwd(), shell=True)
19 changes: 18 additions & 1 deletion silex_client/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"""

import argparse
from typing import Callable, Dict, Optional

from silex_client.cli import handlers


def main():
def main(handlers_mapping: Optional[Dict[str, Callable]] = None):
"""
Parse the given arguments and call the appropriate handlers
"""
Expand All @@ -18,6 +19,8 @@ def main():
"command": handlers.command_handler,
"launch": handlers.launch_handler,
}
if handlers_mapping:
HANDLERS_MAPPING.update(handlers_mapping)

context_parser = argparse.ArgumentParser(add_help=False)
context_parser.add_argument(
Expand Down Expand Up @@ -127,6 +130,20 @@ def main():
type=str,
required=False,
)
launcher_parser.add_argument(
"--action",
"-a",
help="the action we want to execute when file open",
type=str,
required=False,
)
launcher_parser.add_argument(
"--command",
"-cm",
help="the command to execute when the file open",
type=str,
required=False,
)

args = vars(parser.parse_args())

Expand Down
157 changes: 157 additions & 0 deletions silex_client/cli/parser.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""
@author: TD gang

Entry point for the CLI tools of silex
"""

import argparse
from typing import Callable, Dict, Optional

from silex_client.cli import handlers


def main(handlers_mapping: Optional[Dict[str, Callable]] = None):
"""
Parse the given arguments and call the appropriate handlers
"""
HANDLERS_MAPPING = {
"action": handlers.action_handler,
"command": handlers.command_handler,
"launch": handlers.launch_handler,
}
if handlers_mapping:
HANDLERS_MAPPING.update(handlers_mapping)

context_parser = argparse.ArgumentParser(add_help=False)
context_parser.add_argument(
"--task-id",
"-t",
help="Specify the ID of the task you can the set the context in",
dest="task_id",
type=str,
)

execution_parser = argparse.ArgumentParser(add_help=False)
execution_parser.add_argument(
"--list",
"-l",
default=False,
help="List the available options for the subcommand in the context",
action="store_true",
)

parser = argparse.ArgumentParser(
prog="silex", description="CLI for the silex pipeline ecosystem"
)
subparsers = parser.add_subparsers(
help="The action to perform under the given context", dest="subcommand"
)

action_parser = subparsers.add_parser(
"action",
help="Execute the given action in the context",
parents=[execution_parser, context_parser],
)
command_parser = subparsers.add_parser(
"command",
help="Execute the given command in the context",
parents=[execution_parser, context_parser],
)
launcher_parser = subparsers.add_parser(
"launch",
help="Launch the given program in the context",
parents=[context_parser],
)

action_parser.add_argument(
"action_name",
help="The name of the action to perform under the context",
default=None,
nargs="?",
)
action_parser.add_argument(
"--list-parameters",
"-lp",
help="Print the parameters of the selected action",
default=False,
action="store_true",
dest="list_parameters",
)
action_parser.add_argument(
"--parameter",
"-p",
help="Set the parameters value with <path> = <value>",
dest="set_parameters",
action="append",
default=[],
)
action_parser.add_argument(
"--batch",
"-b",
help="The action will run without prompting input from user",
default=False,
action="store_true",
dest="batch",
)
action_parser.add_argument(
"--simplify",
"-s",
help="Execute the action in simplify mode",
default=False,
action="store_true",
dest="simplify",
)
action_parser.add_argument(
"--category",
"-c",
help="The category the action belong to",
default="action",
dest="category",
)

command_parser.add_argument(
"command_name",
help="The python path of the command to perform under the context",
default=None,
nargs="?",
)

launcher_parser.add_argument(
"dcc",
help="The dcc to start",
default=None,
nargs="?",
)

launcher_parser.add_argument(
"--file",
"-f",
help="The file to open within the dcc",
type=str,
required=False,
)
launcher_parser.add_argument(
"--action",
"-a",
help="the action we want to execute when file open",
type=str,
required=False,
)
launcher_parser.add_argument(
"--command",
"-cm",
help="the command to execute when the file open",
type=str,
required=False,
)

args = vars(parser.parse_args())

subcommand = args.pop("subcommand", None)
if subcommand is not None:
# Execute the appropriate handler according to the subparser
HANDLERS_MAPPING[subcommand](**args)


if __name__ == "__main__":
main()
Loading