jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__py3-none-any.whl
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 jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -118
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -77
- jaseci/extens/act_lib/file_handler.py +0 -190
- jaseci/extens/act_lib/internal.py +0 -19
- jaseci/extens/act_lib/jaseci.py +0 -62
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -192
- jaseci/extens/act_lib/rand.py +0 -83
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -170
- jaseci/extens/act_lib/std.py +0 -236
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -338
- jaseci/extens/act_lib/task.py +0 -14
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -80
- jaseci/extens/act_lib/vector.py +0 -158
- jaseci/extens/act_lib/webtool.py +0 -29
- jaseci/extens/act_lib/zip.py +0 -34
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -171
- jaseci/extens/api/alias_api.py +0 -140
- jaseci/extens/api/architype_api.py +0 -197
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -85
- jaseci/extens/api/graph_api.py +0 -168
- jaseci/extens/api/health_api.py +0 -21
- jaseci/extens/api/interface.py +0 -269
- jaseci/extens/api/jac_api.py +0 -172
- jaseci/extens/api/jsorc_api.py +0 -317
- jaseci/extens/api/logger_api.py +0 -90
- jaseci/extens/api/master_api.py +0 -134
- jaseci/extens/api/object_api.py +0 -102
- jaseci/extens/api/prometheus_api.py +0 -75
- jaseci/extens/api/queue_api.py +0 -141
- jaseci/extens/api/sentinel_api.py +0 -271
- jaseci/extens/api/share_api.py +0 -64
- jaseci/extens/api/super_api.py +0 -65
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -166
- jaseci/extens/api/walker_api.py +0 -299
- jaseci/extens/api/webhook_api.py +0 -77
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -219
- jaseci/jac/interpreter/interp.py +0 -1784
- jaseci/jac/interpreter/sentinel_interp.py +0 -260
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -249
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -151
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -120
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -86
- jaseci/jac/machine/jac_value.py +0 -227
- jaseci/jac/machine/machine_state.py +0 -386
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -365
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6029
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -140
- jaseci/jsorc/remote_actions.py +0 -158
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -94
- jaseci/prim/architype.py +0 -90
- jaseci/prim/edge.py +0 -173
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -27
- jaseci/prim/master.py +0 -67
- jaseci/prim/node.py +0 -533
- jaseci/prim/obj_mixins.py +0 -238
- jaseci/prim/sentinel.py +0 -282
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -517
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -169
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.6.dist-info/LICENSE +0 -21
- jaseci-1.4.2.6.dist-info/METADATA +0 -39
- jaseci-1.4.2.6.dist-info/RECORD +0 -185
- jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
jaseci/prim/obj_mixins.py
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Jaseci object mixins
|
|
3
|
-
|
|
4
|
-
Various mixins to define properties of Jaseci objects
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from jaseci.utils.id_list import IdList
|
|
8
|
-
from jaseci.utils.utils import logger
|
|
9
|
-
import uuid
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Anchored:
|
|
13
|
-
"""Utility class for objects that hold anchor values"""
|
|
14
|
-
|
|
15
|
-
arch_map = {}
|
|
16
|
-
|
|
17
|
-
def __init__(self):
|
|
18
|
-
self.context = {}
|
|
19
|
-
|
|
20
|
-
def get_architype(self):
|
|
21
|
-
arch = self.get_arch_from_cache() # Optimization
|
|
22
|
-
if arch and id(arch._h) == id(self._h):
|
|
23
|
-
return arch
|
|
24
|
-
arch = (
|
|
25
|
-
self._h._machine.parent().get_arch_for(self)
|
|
26
|
-
if self._h._machine is not None
|
|
27
|
-
and self._h._machine.parent() is not None
|
|
28
|
-
and self._h._machine.parent().j_type == "sentinel"
|
|
29
|
-
else None
|
|
30
|
-
)
|
|
31
|
-
mast = self.get_master()
|
|
32
|
-
if arch is None and mast.active_snt() is not None:
|
|
33
|
-
arch = mast.active_snt().get_arch_for(self)
|
|
34
|
-
elif arch is None and self.parent() and self.parent().j_type == "sentinel":
|
|
35
|
-
arch = self.parent().get_arch_for(self)
|
|
36
|
-
self.cache_arch(arch)
|
|
37
|
-
return arch
|
|
38
|
-
|
|
39
|
-
def cache_arch(self, arch):
|
|
40
|
-
Anchored.arch_map[self.kind + self.name] = arch
|
|
41
|
-
|
|
42
|
-
def get_arch_from_cache(self):
|
|
43
|
-
if (self.kind + self.name) in Anchored.arch_map:
|
|
44
|
-
return Anchored.arch_map[self.kind + self.name]
|
|
45
|
-
return None
|
|
46
|
-
|
|
47
|
-
def flush_cache():
|
|
48
|
-
Anchored.arch_map = {}
|
|
49
|
-
|
|
50
|
-
def anchor_value(self):
|
|
51
|
-
"""Returns value of anchor context object"""
|
|
52
|
-
arch = self.get_architype()
|
|
53
|
-
if arch is not None:
|
|
54
|
-
anch = arch.anchor_var
|
|
55
|
-
if anch and anch in self.context.keys():
|
|
56
|
-
return self.context[anch]
|
|
57
|
-
return None
|
|
58
|
-
|
|
59
|
-
def private_values(self):
|
|
60
|
-
"""Returns value of anchor context object"""
|
|
61
|
-
arch = self.get_architype()
|
|
62
|
-
if arch is not None:
|
|
63
|
-
return arch.private_vars
|
|
64
|
-
return []
|
|
65
|
-
|
|
66
|
-
def set_context(self, ctx):
|
|
67
|
-
"""Assign values to context fields of object"""
|
|
68
|
-
for i in ctx.keys():
|
|
69
|
-
if i in self.get_architype().has_vars:
|
|
70
|
-
self.context[i] = ctx[i]
|
|
71
|
-
else:
|
|
72
|
-
logger.warning(str(f"{i} not a context member of {self}"))
|
|
73
|
-
self.save()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
class Sharable:
|
|
77
|
-
"""Utility class for objects that are sharable between users"""
|
|
78
|
-
|
|
79
|
-
def __init__(self, m_id, mode=None, **kwargs):
|
|
80
|
-
self.set_master(m_id)
|
|
81
|
-
self.j_access = (
|
|
82
|
-
mode
|
|
83
|
-
if mode is not None
|
|
84
|
-
else (
|
|
85
|
-
self._h.get_obj(self._m_id, self._m_id).perm_default
|
|
86
|
-
if self._h.has_obj(self._m_id)
|
|
87
|
-
else "private"
|
|
88
|
-
)
|
|
89
|
-
)
|
|
90
|
-
self.j_r_acc_ids = IdList(self)
|
|
91
|
-
self.j_rw_acc_ids = IdList(self)
|
|
92
|
-
|
|
93
|
-
@property
|
|
94
|
-
def _m_id(self) -> str:
|
|
95
|
-
return self.j_master
|
|
96
|
-
|
|
97
|
-
def set_master(self, m_id):
|
|
98
|
-
if not m_id:
|
|
99
|
-
m_id = uuid.UUID(int=0).urn
|
|
100
|
-
self.j_master = m_id
|
|
101
|
-
|
|
102
|
-
def make_public(self):
|
|
103
|
-
"""Make element publically accessible"""
|
|
104
|
-
self.j_access = "public"
|
|
105
|
-
self.save()
|
|
106
|
-
|
|
107
|
-
def make_read_only(self):
|
|
108
|
-
"""Make element publically readable"""
|
|
109
|
-
self.j_access = "read_only"
|
|
110
|
-
self.save()
|
|
111
|
-
|
|
112
|
-
def make_private(self):
|
|
113
|
-
"""Make element private"""
|
|
114
|
-
self.j_access = "private"
|
|
115
|
-
self.save()
|
|
116
|
-
|
|
117
|
-
def is_public(self):
|
|
118
|
-
"""Check if element is publically accessible"""
|
|
119
|
-
return self.j_access == "public" or self.j_master == uuid.UUID(int=0).urn
|
|
120
|
-
|
|
121
|
-
def is_read_only(self):
|
|
122
|
-
"""Check if element is publically readable"""
|
|
123
|
-
return self.j_access == "read_only"
|
|
124
|
-
|
|
125
|
-
def is_readable(self):
|
|
126
|
-
"""Check if element is publically readable"""
|
|
127
|
-
return self.j_access == "read_only" or self.is_public()
|
|
128
|
-
|
|
129
|
-
def is_private(self):
|
|
130
|
-
"""Check if element is private"""
|
|
131
|
-
return self.j_access == "private"
|
|
132
|
-
|
|
133
|
-
def super_check(self, caller_id):
|
|
134
|
-
"""Quick check if caller is super master"""
|
|
135
|
-
if not hasattr(self, "_h"):
|
|
136
|
-
return False
|
|
137
|
-
user = self._h.get_obj(caller_id, caller_id, override=True)
|
|
138
|
-
if user.j_type == "super_master":
|
|
139
|
-
return True
|
|
140
|
-
return False
|
|
141
|
-
|
|
142
|
-
def check_read_access(self, caller_id, silent=False):
|
|
143
|
-
if (
|
|
144
|
-
caller_id == self._m_id
|
|
145
|
-
or self.is_readable()
|
|
146
|
-
or caller_id in self.j_r_acc_ids
|
|
147
|
-
or caller_id in self.j_rw_acc_ids
|
|
148
|
-
or self.super_check(caller_id)
|
|
149
|
-
):
|
|
150
|
-
return True
|
|
151
|
-
if not silent:
|
|
152
|
-
logger.error(str(f"{caller_id} does not have permission to access {self}"))
|
|
153
|
-
return False
|
|
154
|
-
|
|
155
|
-
def check_write_access(self, caller_id, silent=False):
|
|
156
|
-
if (
|
|
157
|
-
caller_id == self._m_id
|
|
158
|
-
or self.is_public()
|
|
159
|
-
or caller_id in self.j_rw_acc_ids
|
|
160
|
-
or self.super_check(caller_id)
|
|
161
|
-
):
|
|
162
|
-
return True
|
|
163
|
-
if not silent:
|
|
164
|
-
logger.error(str(f"{caller_id} does not have permission to access {self}"))
|
|
165
|
-
return False
|
|
166
|
-
|
|
167
|
-
def give_access(self, m, read_only=True):
|
|
168
|
-
"""Give access to a master (user)"""
|
|
169
|
-
if not m.is_master():
|
|
170
|
-
logger.error(f"{m} is not master!")
|
|
171
|
-
return False
|
|
172
|
-
if read_only and m.jid not in self.j_r_acc_ids:
|
|
173
|
-
self.j_r_acc_ids.add_obj(m)
|
|
174
|
-
elif m.jid not in self.j_rw_acc_ids:
|
|
175
|
-
self.j_rw_acc_ids.add_obj(m)
|
|
176
|
-
return True
|
|
177
|
-
|
|
178
|
-
def remove_access(self, m):
|
|
179
|
-
"""Remove access from a master (user)"""
|
|
180
|
-
ret = False
|
|
181
|
-
if m.jid in self.j_r_acc_ids:
|
|
182
|
-
self.j_r_acc_ids.remove_obj(m)
|
|
183
|
-
ret = True
|
|
184
|
-
if m.jid in self.j_rw_acc_ids:
|
|
185
|
-
self.j_rw_acc_ids.remove_obj(m)
|
|
186
|
-
ret = True
|
|
187
|
-
return ret
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
class Hookable(Sharable):
|
|
191
|
-
"""Utility class for objects that are savable to DBs and other stores"""
|
|
192
|
-
|
|
193
|
-
def __init__(self, h, persist: bool = True, parent=None, **kwargs):
|
|
194
|
-
self._h = h # hook for storing and loading to persistent store
|
|
195
|
-
self._persist = persist
|
|
196
|
-
self.j_parent = parent.jid if parent else None # member of
|
|
197
|
-
Sharable.__init__(self, **kwargs)
|
|
198
|
-
|
|
199
|
-
def check_hooks_match(self, target, silent=False):
|
|
200
|
-
"""Checks whether target object hook matches self's hook"""
|
|
201
|
-
if not self._m_id or not target._m_id:
|
|
202
|
-
return True
|
|
203
|
-
elif not silent and target._h != self._h:
|
|
204
|
-
logger.critical(
|
|
205
|
-
str(
|
|
206
|
-
"Hook for {} does not match {}, {} != {}".format(
|
|
207
|
-
target, self, target._h, self._h
|
|
208
|
-
)
|
|
209
|
-
)
|
|
210
|
-
)
|
|
211
|
-
return target._h == self._h
|
|
212
|
-
|
|
213
|
-
def make_persistent(self):
|
|
214
|
-
"""Make element persistent"""
|
|
215
|
-
self._persist = True
|
|
216
|
-
self.save()
|
|
217
|
-
|
|
218
|
-
def save(self):
|
|
219
|
-
"""
|
|
220
|
-
Write self through hook to persistent storage
|
|
221
|
-
"""
|
|
222
|
-
self._h.save_obj(self._m_id, self)
|
|
223
|
-
|
|
224
|
-
def destroy(self):
|
|
225
|
-
"""
|
|
226
|
-
Destroys self from persistent storage
|
|
227
|
-
|
|
228
|
-
Note that the object will still exist in python until GC'd
|
|
229
|
-
"""
|
|
230
|
-
self._h.destroy_obj(self._m_id, self)
|
|
231
|
-
del self
|
|
232
|
-
|
|
233
|
-
def parent(self):
|
|
234
|
-
"""
|
|
235
|
-
Returns the objects for list of owners of this element
|
|
236
|
-
"""
|
|
237
|
-
if self.j_parent:
|
|
238
|
-
return self._h.get_obj(self._m_id, self.j_parent)
|
jaseci/prim/sentinel.py
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Sentinel class for Jaseci
|
|
3
|
-
|
|
4
|
-
Each sentinel has an id, name, timestamp and it's set of walkers.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from jaseci.prim.element import Element
|
|
8
|
-
from jaseci.prim.obj_mixins import Anchored
|
|
9
|
-
from jaseci.utils.utils import (
|
|
10
|
-
logger,
|
|
11
|
-
ColCodes as Cc,
|
|
12
|
-
is_true,
|
|
13
|
-
perf_test_start,
|
|
14
|
-
perf_test_stop,
|
|
15
|
-
)
|
|
16
|
-
from jaseci.utils.id_list import IdList
|
|
17
|
-
from jaseci.jac.ir.jac_code import JacCode, jac_ir_to_ast
|
|
18
|
-
from jaseci.jac.interpreter.sentinel_interp import SentinelInterp
|
|
19
|
-
from jaseci.prim.walker import Walker
|
|
20
|
-
from jaseci.prim.architype import Architype
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Sentinel(Element, JacCode, SentinelInterp):
|
|
24
|
-
"""
|
|
25
|
-
Sentinel class for Jaseci
|
|
26
|
-
|
|
27
|
-
is_active is used to signify whether sentinel is ready to run walkers, i.e,
|
|
28
|
-
register_code succeeded
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
def __init__(self, *args, **kwargs):
|
|
32
|
-
self.version = None
|
|
33
|
-
self.arch_ids = IdList(self)
|
|
34
|
-
self.global_vars = {}
|
|
35
|
-
self.testcases = []
|
|
36
|
-
Element.__init__(self, *args, **kwargs)
|
|
37
|
-
JacCode.__init__(self, code_ir=None)
|
|
38
|
-
SentinelInterp.__init__(self)
|
|
39
|
-
|
|
40
|
-
def reset(self):
|
|
41
|
-
"""Resets state of sentinel and unregister's code"""
|
|
42
|
-
self.version = None
|
|
43
|
-
self.global_vars = {}
|
|
44
|
-
self.testcases = []
|
|
45
|
-
self.arch_ids.destroy_all()
|
|
46
|
-
JacCode.reset(self)
|
|
47
|
-
SentinelInterp.reset(self)
|
|
48
|
-
Anchored.flush_cache()
|
|
49
|
-
|
|
50
|
-
def refresh(self):
|
|
51
|
-
super().refresh()
|
|
52
|
-
self.ir_load()
|
|
53
|
-
|
|
54
|
-
def register_code(self, text, dir="./", mode="default", opt_level=4):
|
|
55
|
-
"""
|
|
56
|
-
Registers a program (set of walkers and architypes) written in Jac
|
|
57
|
-
"""
|
|
58
|
-
self.reset()
|
|
59
|
-
if mode == "ir":
|
|
60
|
-
self.apply_ir(text)
|
|
61
|
-
else:
|
|
62
|
-
self.register(text, dir, opt_level=opt_level)
|
|
63
|
-
if self.is_active:
|
|
64
|
-
self.ir_load()
|
|
65
|
-
return self.is_active
|
|
66
|
-
|
|
67
|
-
def load_arch_defaults(self):
|
|
68
|
-
self.arch_ids.add_obj(
|
|
69
|
-
Architype(m_id=self._m_id, h=self._h, name="root", kind="node", parent=self)
|
|
70
|
-
)
|
|
71
|
-
self.arch_ids.add_obj(
|
|
72
|
-
Architype(
|
|
73
|
-
m_id=self._m_id, h=self._h, name="generic", kind="node", parent=self
|
|
74
|
-
)
|
|
75
|
-
)
|
|
76
|
-
self.arch_ids.add_obj(
|
|
77
|
-
Architype(
|
|
78
|
-
m_id=self._m_id, h=self._h, name="generic", kind="edge", parent=self
|
|
79
|
-
)
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
def ir_load(self):
|
|
83
|
-
"""
|
|
84
|
-
Load walkers and architypes from IR
|
|
85
|
-
"""
|
|
86
|
-
self.load_arch_defaults()
|
|
87
|
-
self.run_start(self._jac_ast)
|
|
88
|
-
|
|
89
|
-
if self.runtime_errors:
|
|
90
|
-
logger.error(str(f"{self.name}: Runtime problem processing sentinel!"))
|
|
91
|
-
self.is_active = False
|
|
92
|
-
elif not self.arch_ids:
|
|
93
|
-
logger.error(str(f"{self.name}: No walkers nor architypes created!"))
|
|
94
|
-
self.is_active = False
|
|
95
|
-
return self.is_active
|
|
96
|
-
|
|
97
|
-
def register_architype(self, code, opt_level=4):
|
|
98
|
-
"""Adds an architype based on jac code"""
|
|
99
|
-
tree = self.compile_jac(
|
|
100
|
-
code, dir="./", start_rule="architype", opt_level=opt_level
|
|
101
|
-
)
|
|
102
|
-
if not tree:
|
|
103
|
-
return None
|
|
104
|
-
return self.load_architype(tree)
|
|
105
|
-
|
|
106
|
-
def spawn_architype(self, name, kind=None, caller=None, is_async=None):
|
|
107
|
-
"""
|
|
108
|
-
Spawns a new architype from registered architypes and adds to
|
|
109
|
-
live walkers
|
|
110
|
-
"""
|
|
111
|
-
src_arch = self.arch_ids.get_obj_by_name(name, kind=kind, silent=True)
|
|
112
|
-
if not src_arch:
|
|
113
|
-
logger.error(str(f"{self.name}: Unable to spawn {kind} architype {name}!"))
|
|
114
|
-
return None
|
|
115
|
-
src_arch.is_async = src_arch.is_async if is_async is None else is_true(is_async)
|
|
116
|
-
if caller and caller._m_id != src_arch._m_id:
|
|
117
|
-
new_arch = src_arch.duplicate()
|
|
118
|
-
new_arch.set_master(caller._m_id)
|
|
119
|
-
new_arch._jac_ast = src_arch._jac_ast
|
|
120
|
-
if new_arch._jac_ast is None:
|
|
121
|
-
new_arch.refresh()
|
|
122
|
-
return new_arch
|
|
123
|
-
else:
|
|
124
|
-
return src_arch
|
|
125
|
-
|
|
126
|
-
def run_architype(self, name, kind=None, caller=None, is_async=None):
|
|
127
|
-
"""
|
|
128
|
-
Spawn, run, then destroy architype if m_id's are different
|
|
129
|
-
"""
|
|
130
|
-
if caller is None:
|
|
131
|
-
caller = self
|
|
132
|
-
arch = self.spawn_architype(name, kind, caller, is_async)
|
|
133
|
-
if arch is None:
|
|
134
|
-
logger.error(
|
|
135
|
-
str(f"{self.name}: Unable to spawn architype " f"{[name, kind]}!")
|
|
136
|
-
)
|
|
137
|
-
return None
|
|
138
|
-
if arch.jid in self.arch_ids:
|
|
139
|
-
return arch.run()
|
|
140
|
-
else:
|
|
141
|
-
ret = arch.run()
|
|
142
|
-
Element.destroy(arch)
|
|
143
|
-
return ret
|
|
144
|
-
|
|
145
|
-
def get_arch_for(self, obj):
|
|
146
|
-
"""Returns the architype that matches object"""
|
|
147
|
-
ret = self.arch_ids.get_obj_by_name(name=obj.name, kind=obj.kind)
|
|
148
|
-
if ret is None:
|
|
149
|
-
self.rt_subtle_error(
|
|
150
|
-
f"Unable to find architype for {obj.name}, {obj.kind}",
|
|
151
|
-
self._cur_jac_ast,
|
|
152
|
-
)
|
|
153
|
-
return ret
|
|
154
|
-
|
|
155
|
-
def run_tests(self, specific=None, profiling=False, detailed=False, silent=False):
|
|
156
|
-
"""
|
|
157
|
-
Testcase schema
|
|
158
|
-
testcase = {
|
|
159
|
-
"name": kid[1].token_text() if kid[1].name == "NAME" else "",
|
|
160
|
-
"title": kid[2].token_text()
|
|
161
|
-
if kid[1].name == "NAME"
|
|
162
|
-
else kid[1].token_text(),
|
|
163
|
-
"graph_ref": None,
|
|
164
|
-
"graph_block": None,
|
|
165
|
-
"walker_ref": None,
|
|
166
|
-
"spawn_ctx": None,
|
|
167
|
-
"assert_block": None,
|
|
168
|
-
"walker_block": None,
|
|
169
|
-
"outcome": None,
|
|
170
|
-
}
|
|
171
|
-
"""
|
|
172
|
-
from pprint import pformat
|
|
173
|
-
from time import time
|
|
174
|
-
import sys
|
|
175
|
-
import io
|
|
176
|
-
|
|
177
|
-
num_failed = 0
|
|
178
|
-
num_tests = 0
|
|
179
|
-
for i in self.testcases:
|
|
180
|
-
if specific is not None and i["name"] != specific:
|
|
181
|
-
continue
|
|
182
|
-
num_tests += 1
|
|
183
|
-
screen_out = [sys.stdout, sys.stderr]
|
|
184
|
-
buff_out = [io.StringIO(), io.StringIO()]
|
|
185
|
-
destroy_set = []
|
|
186
|
-
title = i["title"]
|
|
187
|
-
if i["graph_ref"]:
|
|
188
|
-
gph = self.run_architype(i["graph_ref"], kind="graph", caller=self)
|
|
189
|
-
else:
|
|
190
|
-
gph = Architype(
|
|
191
|
-
m_id=self._m_id,
|
|
192
|
-
h=self._h,
|
|
193
|
-
parent=self,
|
|
194
|
-
code_ir=jac_ir_to_ast(i["graph_block"]),
|
|
195
|
-
)
|
|
196
|
-
destroy_set.append(gph)
|
|
197
|
-
gph = gph.run()
|
|
198
|
-
if i["walker_ref"]:
|
|
199
|
-
wlk = self.run_architype(
|
|
200
|
-
name=i["walker_ref"], kind="walker", caller=self
|
|
201
|
-
)
|
|
202
|
-
else:
|
|
203
|
-
wlk = Walker(
|
|
204
|
-
m_id=self._m_id,
|
|
205
|
-
h=self._h,
|
|
206
|
-
parent=self,
|
|
207
|
-
code_ir=jac_ir_to_ast(i["walker_block"]),
|
|
208
|
-
)
|
|
209
|
-
destroy_set.append(wlk)
|
|
210
|
-
wlk.prime(gph)
|
|
211
|
-
if i["spawn_ctx"]:
|
|
212
|
-
self.run_spawn_ctx(jac_ir_to_ast(i["spawn_ctx"]), wlk)
|
|
213
|
-
|
|
214
|
-
stime = time()
|
|
215
|
-
if profiling:
|
|
216
|
-
pr = perf_test_start()
|
|
217
|
-
try:
|
|
218
|
-
if not silent:
|
|
219
|
-
print(f"Testing {title}: ", end="")
|
|
220
|
-
sys.stdout, sys.stderr = buff_out[0], buff_out[1]
|
|
221
|
-
wlk.run()
|
|
222
|
-
sys.stdout, sys.stderr = screen_out[0], screen_out[1]
|
|
223
|
-
if i["assert_block"]:
|
|
224
|
-
wlk._loop_ctrl = None
|
|
225
|
-
wlk._jac_try_mode += 1
|
|
226
|
-
wlk.scope_and_run(
|
|
227
|
-
jac_ir_to_ast(i["assert_block"]),
|
|
228
|
-
run_func=wlk.run_code_block,
|
|
229
|
-
scope_name="assert_block",
|
|
230
|
-
)
|
|
231
|
-
wlk._jac_try_mode -= 1
|
|
232
|
-
i["passed"] = True
|
|
233
|
-
if not silent:
|
|
234
|
-
print(
|
|
235
|
-
f"[{Cc.TG}PASSED{Cc.EC} in {Cc.TY}{time()-stime:.2f}s{Cc.EC}]"
|
|
236
|
-
)
|
|
237
|
-
if detailed and not silent:
|
|
238
|
-
print("REPORT: " + pformat(wlk.report))
|
|
239
|
-
except Exception as e:
|
|
240
|
-
sys.stdout, sys.stderr = screen_out[0], screen_out[1]
|
|
241
|
-
i["passed"] = False
|
|
242
|
-
num_failed += 1
|
|
243
|
-
if not silent:
|
|
244
|
-
print(
|
|
245
|
-
f"[{Cc.TR}FAILED{Cc.EC} in {Cc.TY}{time()-stime:.2f}s{Cc.EC}]"
|
|
246
|
-
)
|
|
247
|
-
print(f"{e}")
|
|
248
|
-
for i in destroy_set: # FIXME: destroy set not complete
|
|
249
|
-
i.destroy()
|
|
250
|
-
if profiling:
|
|
251
|
-
print(perf_test_stop(pr))
|
|
252
|
-
|
|
253
|
-
summary = {
|
|
254
|
-
"tests": num_tests,
|
|
255
|
-
"passed": num_tests - num_failed,
|
|
256
|
-
"failed": num_failed,
|
|
257
|
-
"success": num_tests and not num_failed,
|
|
258
|
-
}
|
|
259
|
-
if detailed:
|
|
260
|
-
details = []
|
|
261
|
-
for i in self.testcases:
|
|
262
|
-
if specific is not None and i["name"] != specific:
|
|
263
|
-
continue
|
|
264
|
-
details.append(
|
|
265
|
-
{
|
|
266
|
-
"test": i["title"],
|
|
267
|
-
"passed": i["passed"],
|
|
268
|
-
"stdout": buff_out[0].getvalue(),
|
|
269
|
-
"stderr": buff_out[1].getvalue(),
|
|
270
|
-
}
|
|
271
|
-
)
|
|
272
|
-
summary["details"] = details
|
|
273
|
-
return summary
|
|
274
|
-
|
|
275
|
-
def destroy(self):
|
|
276
|
-
"""
|
|
277
|
-
Destroys self from memory and persistent storage
|
|
278
|
-
"""
|
|
279
|
-
Anchored.flush_cache()
|
|
280
|
-
for i in self.arch_ids.obj_list():
|
|
281
|
-
i.destroy()
|
|
282
|
-
super().destroy()
|
jaseci/prim/super_master.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Super master handler for each user of Jaseci, serves as main interface between
|
|
3
|
-
between user and Jaseci
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from jaseci.extens.api.jsorc_api import JsOrcApi
|
|
7
|
-
from jaseci.prim.master import Master
|
|
8
|
-
from jaseci.extens.api.logger_api import LoggerApi
|
|
9
|
-
from jaseci.extens.api.config_api import ConfigApi
|
|
10
|
-
from jaseci.extens.api.global_api import GlobalApi
|
|
11
|
-
from jaseci.extens.api.super_api import SuperApi
|
|
12
|
-
from jaseci.extens.api.actions_api import ActionsApi
|
|
13
|
-
from jaseci.extens.api.prometheus_api import PrometheusApi
|
|
14
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@JsOrc.context(name="super_master")
|
|
18
|
-
class SuperMaster(
|
|
19
|
-
Master,
|
|
20
|
-
LoggerApi,
|
|
21
|
-
ActionsApi,
|
|
22
|
-
ConfigApi,
|
|
23
|
-
GlobalApi,
|
|
24
|
-
SuperApi,
|
|
25
|
-
JsOrcApi,
|
|
26
|
-
PrometheusApi,
|
|
27
|
-
):
|
|
28
|
-
"""Master with admin APIs"""
|
|
29
|
-
|
|
30
|
-
def __init__(self, *args, **kwargs):
|
|
31
|
-
Master.__init__(self, *args, **kwargs)
|