dyngle 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dyngle might be problematic. Click here for more details.
- {dyngle-0.2.0 → dyngle-0.3.0}/PKG-INFO +1 -1
- {dyngle-0.2.0 → dyngle-0.3.0}/dyngle/__init__.py +4 -0
- {dyngle-0.2.0 → dyngle-0.3.0}/dyngle/__main__.py +1 -2
- dyngle-0.3.0/dyngle/command/run_command.py +47 -0
- dyngle-0.3.0/dyngle/template.py +30 -0
- {dyngle-0.2.0 → dyngle-0.3.0}/pyproject.toml +1 -1
- dyngle-0.2.0/dyngle/command/run_command.py +0 -52
- {dyngle-0.2.0 → dyngle-0.3.0}/PACKAGE.md +0 -0
- {dyngle-0.2.0 → dyngle-0.3.0}/dyngle/command/__init__.py +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
import subprocess
|
|
3
|
+
from wizlib.parser import WizParser
|
|
4
|
+
from yaml import safe_load
|
|
5
|
+
|
|
6
|
+
from dyngle.command import DyngleCommand
|
|
7
|
+
from dyngle.template import Template
|
|
8
|
+
from dyngle import DyngleError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RunCommand(DyngleCommand):
|
|
12
|
+
"""Run a workflow defined in the configuration"""
|
|
13
|
+
|
|
14
|
+
name = 'run'
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def add_args(cls, parser: WizParser):
|
|
18
|
+
super().add_args(parser)
|
|
19
|
+
parser.add_argument('operation', help='Operation name to run')
|
|
20
|
+
|
|
21
|
+
def handle_vals(self):
|
|
22
|
+
super().handle_vals()
|
|
23
|
+
|
|
24
|
+
def _validate_operation_exists(self, operations):
|
|
25
|
+
"""Validate that the requested operation exists in configuration"""
|
|
26
|
+
if self.operation not in operations:
|
|
27
|
+
available_operations = ', '.join(operations.keys())
|
|
28
|
+
raise DyngleError(
|
|
29
|
+
f'Operation "{self.operation}" not found. " + \
|
|
30
|
+
f"Available operations: {available_operations}')
|
|
31
|
+
|
|
32
|
+
@DyngleCommand.wrap
|
|
33
|
+
def execute(self):
|
|
34
|
+
operations = self.app.config.get('dyngle-operations')
|
|
35
|
+
self._validate_operation_exists(operations)
|
|
36
|
+
steps = operations[self.operation]
|
|
37
|
+
data_string = self.app.stream.text
|
|
38
|
+
data = safe_load(data_string)
|
|
39
|
+
for step_template in steps:
|
|
40
|
+
step = Template(step_template).render(data)
|
|
41
|
+
parts = shlex.split(step)
|
|
42
|
+
result = subprocess.run(parts)
|
|
43
|
+
if result.returncode != 0:
|
|
44
|
+
raise DyngleError(
|
|
45
|
+
f'Task failed with code {result.returncode}: {step}')
|
|
46
|
+
|
|
47
|
+
return f'Operation "{self.operation}" completed successfully'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from functools import partial
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
PATTERN = re.compile(r'\{\{\s*([^}]+)\s*\}\}')
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Template:
|
|
11
|
+
|
|
12
|
+
template: str
|
|
13
|
+
|
|
14
|
+
def render(self, data):
|
|
15
|
+
"""Render the template with the provided data."""
|
|
16
|
+
resolver = partial(self._resolve, data=data)
|
|
17
|
+
return PATTERN.sub(resolver, self.template)
|
|
18
|
+
|
|
19
|
+
def _resolve(self, match, *, data):
|
|
20
|
+
"""Resolve a single name/path from the template."""
|
|
21
|
+
path = match.group(1).strip()
|
|
22
|
+
# Try an expression first, then data
|
|
23
|
+
if False:
|
|
24
|
+
pass
|
|
25
|
+
else:
|
|
26
|
+
parts = path.split('.')
|
|
27
|
+
current = data
|
|
28
|
+
for part in parts:
|
|
29
|
+
current = current[part]
|
|
30
|
+
return current
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import shlex
|
|
2
|
-
import subprocess
|
|
3
|
-
from wizlib.parser import WizParser
|
|
4
|
-
|
|
5
|
-
from dyngle.command import DyngleCommand
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class RunCommand(DyngleCommand):
|
|
9
|
-
"""Run a workflow defined in the configuration"""
|
|
10
|
-
|
|
11
|
-
name = 'run'
|
|
12
|
-
|
|
13
|
-
@classmethod
|
|
14
|
-
def add_args(cls, parser: WizParser):
|
|
15
|
-
super().add_args(parser)
|
|
16
|
-
parser.add_argument('flow', help='Operation name to run')
|
|
17
|
-
|
|
18
|
-
def handle_vals(self):
|
|
19
|
-
super().handle_vals()
|
|
20
|
-
if not self.provided('flow'):
|
|
21
|
-
self.flow = self.app.ui.get_input('Enter flow name: ')
|
|
22
|
-
|
|
23
|
-
def _validate_flow_exists(self, operations):
|
|
24
|
-
"""Validate that the requested flow exists in configuration"""
|
|
25
|
-
if not operations:
|
|
26
|
-
raise RuntimeError('No operations configured')
|
|
27
|
-
|
|
28
|
-
if self.flow not in operations:
|
|
29
|
-
available_operations = ', '.join(operations.keys())
|
|
30
|
-
raise RuntimeError(
|
|
31
|
-
f'Operation "{self.flow}" not found. " + \
|
|
32
|
-
f"Available operations: {available_operations}')
|
|
33
|
-
|
|
34
|
-
def _execute_task(self, task_str):
|
|
35
|
-
"""Execute a single task and handle errors"""
|
|
36
|
-
task_parts = shlex.split(task_str)
|
|
37
|
-
result = subprocess.run(task_parts)
|
|
38
|
-
|
|
39
|
-
if result.returncode != 0:
|
|
40
|
-
raise RuntimeError(
|
|
41
|
-
f'Task failed with code {result.returncode}: {task_str}')
|
|
42
|
-
|
|
43
|
-
@DyngleCommand.wrap
|
|
44
|
-
def execute(self):
|
|
45
|
-
operations = self.app.config.get('dyngle-operations')
|
|
46
|
-
self._validate_flow_exists(operations)
|
|
47
|
-
|
|
48
|
-
tasks = operations[self.flow]
|
|
49
|
-
for task_str in tasks:
|
|
50
|
-
self._execute_task(task_str)
|
|
51
|
-
|
|
52
|
-
return f'Operation "{self.flow}" completed successfully'
|
|
File without changes
|
|
File without changes
|