Skip to content

Commit 0c154a3

Browse files
committed
Rename interface TreeRoot -> ActionExecutor
1 parent 808bf81 commit 0c154a3

17 files changed

+73
-56
lines changed

contextshell/Action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22
from contextshell.NodePath import NodePath
3-
from contextshell.TreeRoot import ActionArgsPack
3+
from contextshell.ActionExecutor import ActionArgsPack
44

55

66
class Action(ABC):

contextshell/ActionEndpoint.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Optional
3+
4+
from contextshell.Action import Action
5+
from contextshell.ActionExecutor import ActionExecutor, ActionArgsPack
6+
from contextshell.NodePath import NodePath
7+
from collections import OrderedDict
8+
9+
10+
class ActionEndpoint(ActionExecutor):
11+
@abstractmethod
12+
def find_action(self, target: NodePath, action: NodePath) -> Optional[Action]:
13+
raise NotImplementedError()
14+
15+
def execute(self, target: NodePath, action_name: NodePath, args: ActionArgsPack = None):
16+
#print("Execute: {}: {} {}".format(target, action, args))
17+
if not args:
18+
args = OrderedDict()
19+
action_impl = self.find_action(target, action_name)
20+
if action_impl is None:
21+
raise NameError("Could not find action named '{}'".format(action_name))
22+
return action_impl.invoke(target, action_name, args)
23+

contextshell/TreeRoot.py renamed to contextshell/ActionExecutor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from abc import ABC, abstractmethod
2+
from collections import OrderedDict
3+
24
from contextshell.NodePath import NodePath
35
from typing import Dict, Union, Any, Tuple, List
4-
from collections import OrderedDict
56

67
ArgumentValue = Any
78
ActionArgsPack = Dict[Union[NodePath, int], ArgumentValue]
89
PositionalArguments = List[ArgumentValue]
910
KeywordArguments = Dict[str, ArgumentValue]
1011

1112

12-
# CHECK: Rename TreeRoot to ActionEndpoint or something more appropriate?
13-
class TreeRoot(ABC):
13+
class ActionExecutor(ABC):
14+
"""Interface for backends allowing execution of arbitrary actions"""
1415
@abstractmethod
15-
def execute(self, target: NodePath, action: NodePath, args: ActionArgsPack = None):
16+
def execute(self, target: NodePath, action_name: NodePath, args: ActionArgsPack = None):
1617
raise NotImplementedError()
1718

1819

contextshell/CallableAction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Callable
2-
from contextshell.TreeRoot import unpack_argument_tree, ActionArgsPack
2+
from contextshell.ActionExecutor import unpack_argument_tree, ActionArgsPack
33
from contextshell.Action import Action
44
from contextshell.NodePath import NodePath
55

contextshell/CommandInterpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from contextshell.Command import Command
22
from contextshell.NodePath import NodePath
3-
from contextshell.TreeRoot import TreeRoot, parse_argument_tree
3+
from contextshell.ActionExecutor import ActionExecutor, parse_argument_tree
44

55

66
class CommandInterpreter:
7-
def __init__(self, tree: TreeRoot) -> None:
7+
def __init__(self, tree: ActionExecutor) -> None:
88
self.tree = tree
99

1010
def execute(self, command: Command):

contextshell/VirtualTree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
1+
from contextshell.ActionExecutor import ActionExecutor, ActionArgsPack
22
from contextshell.NodePath import NodePath
33
from collections import OrderedDict
44

55

6-
class VirtualTree(TreeRoot):
6+
class VirtualTree(ActionExecutor):
77
"""Abstract frontend allowing embedding (mounting) of more specific tree roots"""
88

99
def __init__(self):
10-
self.mounts: OrderedDict[NodePath, TreeRoot] = OrderedDict()
10+
self.mounts: OrderedDict[NodePath, ActionExecutor] = OrderedDict()
1111

1212
# TODO: rename to attach/detach
13-
def mount(self, path: NodePath, root: TreeRoot):
13+
def mount(self, path: NodePath, root: ActionExecutor):
1414
if path.is_relative:
1515
raise ValueError("Could not mount relative path")
1616
if path in self.mounts:

contextshell/backends/Filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from contextshell.NodePath import NodePath
2-
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
2+
from contextshell.ActionExecutor import ActionExecutor, ActionArgsPack
33
from contextshell.backends.Module import Module
44

55

6-
class FilesystemRoot(TreeRoot):
6+
class FilesystemRoot(ActionExecutor):
77
def __init__(self, root_directory_path: str):
88
self.root_directory_path = root_directory_path
99

contextshell/backends/NodeTree.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from contextshell.Node import Node
22
from contextshell.NodePath import NodePath
3-
from contextshell.TreeRoot import TreeRoot, ActionArgsPack, OrderedDict
3+
from contextshell.ActionEndpoint import ActionEndpoint
4+
from contextshell.ActionExecutor import ActionArgsPack, OrderedDict
45
from contextshell.Action import Action
56
from contextshell.CallableAction import action_from_function
67
from typing import List, Optional
78

89

910
# CHECK: how to implement TemporaryTreeRoot (based on NodeTreeRoot)
10-
class NodeTreeRoot(TreeRoot):
11+
class NodeTreeRoot(ActionEndpoint):
1112
"""Frontend to the (passive) node-based data storage"""
1213
def __init__(self):
1314
self.root = self.create_node(None)
@@ -118,15 +119,6 @@ def find_type(self, target: NodePath, type_name: NodePath): # TODO: add type-hi
118119
return None
119120
return type_node.get()
120121

121-
def execute(self, target: NodePath, action_name: NodePath, args: ActionArgsPack = None):
122-
#print("Execute: {}: {} {}".format(target, action, args))
123-
if not args:
124-
args = OrderedDict()
125-
action_impl = self.find_action(target, action_name)
126-
if action_impl is None:
127-
raise NameError("Could not find action named '{}'".format(action_name))
128-
return action_impl.invoke(target, action_name, args)
129-
130122
def create_node(self, value):
131123
return Node(value)
132124

repl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/python3.6
22
import readline
33

4-
from contextshell.TreeRoot import *
4+
from contextshell.ActionExecutor import ActionExecutor
55
from contextshell.Shell import *
66

7-
def create_context_tree() -> TreeRoot:
7+
def create_context_tree() -> ActionExecutor:
88
pass
99

1010
if __name__ == '__main__':

script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/python3
22
import sys
33

4-
from TreeRoot import *
4+
from ActionEndpoint import *
55

66
from contextshell.Shell import *
77

88
if len(sys.argv) < 2:
99
raise ValueError('Script requires single argument')
1010

11-
tree = TreeRoot()
11+
tree = ActionEndpoint()
1212
shell = Shell(tree)
1313

1414
with open(sys.argv[1]) as script:

0 commit comments

Comments
 (0)