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.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
jaseci/prim/ability.py DELETED
@@ -1,94 +0,0 @@
1
- """
2
- Action class for Jaseci
3
-
4
- Each action has an id, name, timestamp and it's set of edges.
5
- """
6
-
7
- from jaseci.prim.element import Element
8
- from jaseci.jsorc.live_actions import live_actions
9
- from jaseci.jac.jac_set import JacSet
10
- import inspect
11
- import time
12
-
13
- from jaseci.jsorc.jsorc import JsOrc
14
- from jaseci.utils.actions.actions_manager import ActionManager
15
- from jaseci.jac.ir.jac_code import JacCode
16
- from jaseci.jac.interpreter.interp import Interp
17
- from jaseci.jac.machine.jac_scope import JacScope
18
-
19
-
20
- class Ability(Element, JacCode, Interp):
21
- """
22
- Abilities class for Jaseci
23
- """
24
-
25
- def __init__(
26
- self, code_ir=None, preset_in_out=None, access_list=None, *args, **kwargs
27
- ):
28
- self.preset_in_out = preset_in_out # Not using _ids convention
29
- self.access_list = access_list
30
- Element.__init__(self, *args, **kwargs)
31
- JacCode.__init__(self, code_ir=code_ir)
32
- Interp.__init__(self)
33
-
34
- def run_ability(self, here, visitor):
35
- """
36
- Run ability
37
- """
38
- self.push_scope(
39
- JacScope(
40
- parent=self,
41
- name=f"a_run:{self.get_jac_ast().loc_str()}",
42
- has_obj=here,
43
- here=here,
44
- visitor=visitor,
45
- )
46
- )
47
- self.run_code_block(self.get_jac_ast())
48
- self.pop_scope()
49
-
50
- def run_action(self, param_list, scope, interp, jac_ast):
51
- """
52
- param_list should be passed as list of values to lib functions
53
- Also note that Jac stores preset_in_out as input/output list of hex
54
- ids since preset_in_out doesn't use _ids convention
55
- """
56
- action_name = self.name
57
- if not interp.check_builtin_action(action_name):
58
- interp.rt_error(f"Cannot execute {action_name} - Not Found", jac_ast)
59
- return None
60
- func = live_actions[action_name]
61
- args = inspect.getfullargspec(func)
62
- self.do_auto_conversions(args, param_list)
63
- args = args[0] + args[4]
64
-
65
- action_manager = JsOrc.get("action_manager", ActionManager)
66
- action_manager.pre_action_call_hook()
67
-
68
- ts = time.time()
69
- try:
70
- if "meta" in args:
71
- param_list["kwargs"]["meta"] = {
72
- "m_id": scope.parent._m_id,
73
- "h": scope.parent._h,
74
- "scope": scope,
75
- "interp": interp,
76
- }
77
- result = func(*param_list["args"], **param_list["kwargs"])
78
- except Exception as e:
79
- interp.rt_error(e, jac_ast, True)
80
- t = time.time() - ts
81
- action_manager.post_action_call_hook(action_name, t)
82
- return result
83
-
84
- def do_auto_conversions(self, args, params):
85
- """
86
- Automatically make conversions for jac to internal, e.g., list to jac_set
87
- """
88
- for i in args.annotations.keys():
89
- if args.annotations[i] == JacSet:
90
- idx = args.args.index(i)
91
- if idx < len(params["args"]):
92
- params["args"][idx] = JacSet(in_list=params["args"][idx])
93
- if i in params["kwargs"]:
94
- params["kwargs"][i] = JacSet(in_list=params["kwargs"][i])
jaseci/prim/architype.py DELETED
@@ -1,90 +0,0 @@
1
- """
2
- Architype class for Jaseci
3
-
4
- Each architype is a registered templatized version of instances of any Jaseci
5
- abstractions or collections of instances (e.g., subgraphs, etc)
6
- """
7
-
8
- from jaseci.prim.element import Element
9
- from jaseci.jac.interpreter.architype_interp import ArchitypeInterp
10
- from jaseci.jac.ir.jac_code import JacCode
11
- from jaseci.utils.id_list import IdList
12
-
13
-
14
- class Architype(Element, JacCode, ArchitypeInterp):
15
- """Architype class for Jaseci"""
16
-
17
- def __init__(self, code_ir=None, is_async=False, *args, **kwargs):
18
- self.super_archs = list()
19
- self.anchor_var = None
20
- self.private_vars = []
21
- self.has_vars = []
22
- self.entry_ability_ids = IdList(self)
23
- self.activity_ability_ids = IdList(self)
24
- self.exit_ability_ids = IdList(self)
25
-
26
- # async handling for walker
27
- self.is_async = is_async
28
-
29
- Element.__init__(self, *args, **kwargs)
30
- JacCode.__init__(self, code_ir)
31
- ArchitypeInterp.__init__(self)
32
-
33
- def run(self):
34
- """
35
- Create set of new object instances from architype if needed
36
- """
37
- return self.run_architype(jac_ast=self.get_jac_ast())
38
-
39
- def get_actions(self, action_types: list):
40
- actions = IdList(self, auto_save=False)
41
- for i in self.arch_with_supers():
42
- for j in action_types:
43
- actions += getattr(i, j)
44
- return actions
45
-
46
- def get_entry_abilities(self):
47
- return self.get_actions(["entry_ability_ids"])
48
-
49
- def get_activity_abilities(self):
50
- return self.get_actions(["activity_ability_ids"])
51
-
52
- def get_exit_abilities(self):
53
- return self.get_actions(["exit_ability_ids"])
54
-
55
- def get_all_abilities(self):
56
- return self.get_actions(
57
- ["entry_ability_ids", "activity_ability_ids", "exit_ability_ids"]
58
- )
59
-
60
- def arch_with_supers(self):
61
- archs = [self]
62
- for i in self.super_archs:
63
- obj = self.parent().arch_ids.get_obj_by_name(name=i, kind=self.kind)
64
- archs += obj.arch_with_supers()
65
- return archs
66
-
67
- def derived_types(self):
68
- names = []
69
- for i in self.arch_with_supers():
70
- names += i.super_archs + [i.name]
71
- return names
72
-
73
- def get_architype(self):
74
- return self
75
-
76
- def is_instance(self, name):
77
- return name in self.derived_types()
78
-
79
- def destroy(self):
80
- """
81
- Destroys self from memory and persistent storage
82
- """
83
- des = (
84
- self.activity_ability_ids.obj_list()
85
- + self.entry_ability_ids.obj_list()
86
- + self.exit_ability_ids.obj_list()
87
- )
88
- for i in des:
89
- i.destroy()
90
- super().destroy()
jaseci/prim/edge.py DELETED
@@ -1,173 +0,0 @@
1
- """
2
- Edge class for Jaseci
3
-
4
- Each edge has an id, name, timestamp, the from node at the element of the edge
5
- and the to node it is pointing to.
6
- """
7
-
8
- from jaseci.prim.element import Element
9
- from jaseci.prim.obj_mixins import Anchored
10
- from jaseci.utils.utils import logger
11
- import uuid
12
- import sys
13
-
14
-
15
- class Edge(Element, Anchored):
16
- """Edge class for Jaseci"""
17
-
18
- def __init__(self, **kwargs):
19
- self.from_node_id = None
20
- self.to_node_id = None
21
- self.bidirected: bool = False
22
- Anchored.__init__(self)
23
- Element.__init__(self, **kwargs)
24
-
25
- def from_node(self):
26
- """Returns node edge is pointing from"""
27
- ret = (
28
- self._h.get_obj(self._m_id, self.from_node_id)
29
- if self.from_node_id
30
- else None
31
- )
32
- if not ret:
33
- logger.critical(str(f"{self} disconnected from source node"))
34
- return None
35
- else:
36
- return ret
37
-
38
- def to_node(self):
39
- """Returns node edge is pointing to"""
40
- if not self.to_node_id:
41
- return None
42
- ret = self._h.get_obj(self._m_id, self.to_node_id) if self.to_node_id else None
43
- if not ret:
44
- logger.critical(str(f"{self} disconnected to target node"))
45
- return None
46
- else:
47
- return ret
48
-
49
- def nodes(self):
50
- """Returns both nodes connected to edge in a list"""
51
- return [self.to_node(), self.from_node()]
52
-
53
- def opposing_node(self, node_obj):
54
- """Returns opposite node edge is pointing from node_obj"""
55
- node_set = [self.to_node_id, self.from_node_id]
56
- try:
57
- node_set.remove(node_obj.jid)
58
- return self._h.get_obj(self._m_id, node_set[0])
59
- except ValueError:
60
- logger.critical(str(f"{self} disconnected to node {node_obj}"))
61
- return None
62
-
63
- def connect(self, source, target, bi_dir=False):
64
- """
65
- Connects both ends of the edge
66
- """
67
- self.from_node_id = source.jid
68
- self.to_node_id = target.jid
69
- source.smart_add_edge(self)
70
- target.smart_add_edge(self)
71
- self.set_bidirected(bi_dir)
72
- self.save()
73
- return True
74
-
75
- def set_bidirected(self, bidirected: bool):
76
- """Sets/unsets edge to be bidirected"""
77
- self.bidirected = bidirected
78
- self.save()
79
-
80
- def is_bidirected(self):
81
- """Check if edge is bidirected"""
82
- return self.bidirected
83
-
84
- def connects(self, source=None, target=None, ignore_direction=False):
85
- """Test if a node or nodes are connected by edge"""
86
- if not source and not target:
87
- return False
88
- if self.bidirected or ignore_direction:
89
- if source and source.jid not in [self.from_node_id, self.to_node_id]:
90
- return False
91
- if target and target.jid not in [self.from_node_id, self.to_node_id]:
92
- return False
93
- else:
94
- if source and source.jid != self.from_node_id:
95
- return False
96
- if target and target.jid != self.to_node_id:
97
- return False
98
- return True
99
-
100
- def is_fast(self):
101
- return sys.getsizeof(self.context) < 2000
102
-
103
- def save(self):
104
- """
105
- Write self through hook to persistent storage
106
- """
107
-
108
- if self.is_fast():
109
- self._persist = False
110
- if self.from_node_id:
111
- self.from_node().save()
112
- if self.to_node_id:
113
- self.to_node().save()
114
- super().save()
115
-
116
- def destroy(self):
117
- """
118
- Destroys self from memory and persistent storage
119
- """
120
- base = self.from_node()
121
- target = self.to_node()
122
- base.smart_remove_edge(self) if base else None
123
- target.smart_remove_edge(self) if target else None
124
- super().destroy()
125
-
126
- def dot_str(self, node_map=None, edge_map=None, detailed=False):
127
- """
128
- DOT representation
129
- from_node -> to_node [context_key=contect_value]
130
- """
131
-
132
- def handle_str(str):
133
- return str[:32].replace('"', '\\"')
134
-
135
- from_name = (
136
- uuid.UUID(self.from_node().jid).hex
137
- if node_map is None
138
- else node_map.index(self.from_node().jid)
139
- )
140
- to_name = (
141
- uuid.UUID(self.to_node().jid).hex
142
- if node_map is None
143
- else node_map.index(self.to_node().jid)
144
- )
145
- dstr = f'"n{from_name}" -> "n{to_name}" [ '
146
-
147
- if detailed:
148
- dstr += f'id="{uuid.UUID(self.jid).hex}", '
149
-
150
- label = ""
151
- if edge_map:
152
- label = f"e{edge_map.index(self.jid)}"
153
- if self.name != "generic":
154
- label += f":{self.name}"
155
-
156
- dstr += f'label="{label}"'
157
-
158
- if self.bidirected:
159
- dstr += ', dir="both"'
160
-
161
- edge_dict = self.context
162
- for i in self.private_values():
163
- edge_dict.pop(i)
164
-
165
- if edge_dict and detailed:
166
- for k, v in edge_dict.items():
167
- if not isinstance(v, str) or v == "":
168
- continue
169
- dstr += f', {k}="{handle_str(v)}"'
170
-
171
- dstr += " ]"
172
-
173
- return dstr + "\n"
jaseci/prim/element.py DELETED
@@ -1,233 +0,0 @@
1
- """
2
- Base Jaseci object class
3
-
4
- Naming conventions
5
- * '_ids', '_id' - appended to lists of ids as feilds of jaseci objects
6
- * 'obj' - used to represent a jaseci object
7
- * 'item' - Items are kv pairs derived from item class, dont use elsewhere
8
- * 'store' - refers to persistent store for hooks from engine, (dont use db)
9
- """
10
-
11
- import copy
12
- import json
13
- import uuid
14
- from datetime import datetime
15
-
16
- from jaseci.prim.obj_mixins import Hookable
17
- from jaseci.jsorc.memory import MemoryHook
18
- from jaseci.utils.id_list import IdList
19
- from jaseci.utils.json_handler import JaseciJsonEncoder, json_str_to_jsci_dict
20
- from jaseci.utils.utils import log_var_out, logger, camel_to_snake
21
-
22
- __version__ = "1.0.0"
23
- element_fields = None
24
-
25
-
26
- class Element(Hookable):
27
- """
28
- Base class for Jaseci for standard info shared across all objects types in
29
- Jaseci. This class also includes a method for dumping the non-general items
30
- as a single dictionary. The :meth:`jsci_payload` function automatically
31
- finds relevant non general fields and returns a dictionary of them.
32
-
33
- Keep in mind that when a valid hook is passed, the item writes itself on
34
- creation.
35
-
36
- Auto save should be faulse when loading from database so a new UUID is
37
- not randomly created and saved back to db on load
38
-
39
- TODO: Make below content a documentation variable and link in a few places
40
- Keep in mind the postfix of '_ids' on feilds of derived classes of element
41
- is a Jaseci convention for lists of uuids that are stored as hex and loaded
42
- as type UUID.
43
-
44
- NOTE: All fields of elements and it's derived classes are assumed to be
45
- json serializable types
46
- """
47
-
48
- def __init__(
49
- self,
50
- name="basic",
51
- kind="generic",
52
- auto_save=True,
53
- **kwargs,
54
- ):
55
- self.name = name
56
- self.kind = kind
57
- self.jid = uuid.uuid4().urn
58
- self.j_timestamp = datetime.utcnow().isoformat()
59
- self.j_type = camel_to_snake(type(self).__name__)
60
- Hookable.__init__(self, **kwargs)
61
- if self.is_master():
62
- self.set_master(self.jid)
63
- if auto_save:
64
- self.save()
65
-
66
- @property
67
- def id(self):
68
- return uuid.UUID(self.jid)
69
-
70
- @id.setter
71
- def id(self, obj):
72
- self.jid = obj.urn
73
-
74
- @property
75
- def timestamp(self):
76
- return datetime.fromisoformat(self.j_timestamp)
77
-
78
- @timestamp.setter
79
- def timestamp(self, obj):
80
- self.j_timestamp = obj.isoformat()
81
-
82
- def is_master(self, super_check=False, silent=True):
83
- """Check if self is a master"""
84
- ret = True
85
- if "master" not in self.j_type:
86
- ret = False
87
- if not silent:
88
- logger.error(f"{self} is not master")
89
- if super_check and "super" not in self.j_type:
90
- ret = False
91
- if not silent:
92
- logger.error(f"{self} does not have super master status")
93
- return ret
94
-
95
- def get_master(self):
96
- """Get the master of an element"""
97
- return self._h.get_obj(self._m_id, self.j_master)
98
-
99
- def duplicate(self, persist_dup: bool = False):
100
- """
101
- Duplicates elements by creating copy with new id
102
- Hook override to duplicate into mem / another store
103
- """
104
- kwargs = {"m_id": self._m_id, "h": self._h, "persist": persist_dup}
105
- dup = type(self)(**kwargs)
106
- id_save = dup.id
107
- for i in dup.__dict__.keys():
108
- if type(dup.__dict__[i]) == IdList:
109
- setattr(dup, i, IdList(parent_obj=dup, in_list=self.__dict__[i]))
110
- else:
111
- setattr(dup, i, self.__dict__[i])
112
- dup.id = id_save
113
- dup.timestamp = datetime.utcnow()
114
- dup.save()
115
- return dup
116
-
117
- def is_equivalent(self, obj):
118
- """
119
- Duplicates elements by creating copy with new id
120
- """
121
- if self.j_type != obj.j_type:
122
- return False
123
- for i in vars(self).keys():
124
- if not i.startswith("_") and not callable(getattr(self, i)):
125
- if i != "jid" and i != "j_timestamp":
126
- if getattr(self, i) != getattr(obj, i):
127
- return False
128
- return True
129
-
130
- def jsci_payload(self):
131
- """
132
- Returns all data fields and values of jaseci object as json string.
133
- This grabs any fields that are added into inherited objects. Useful for
134
- saving and loading item.
135
- """
136
- global element_fields
137
- if element_fields is None:
138
- element_fields = dir(Element(m_id=0, h=MemoryHook()))
139
- obj_fields = []
140
- for i in vars(self).keys():
141
- if not i.startswith("_") and i not in element_fields:
142
- obj_fields.append(i)
143
- obj_dict = {}
144
- for i in obj_fields:
145
- obj_dict[i] = getattr(self, i)
146
- return json.dumps(obj_dict, cls=JaseciJsonEncoder)
147
-
148
- def serialize(self, deep=0, detailed=False):
149
- """
150
- Serialize Jaseci object
151
- """
152
- jdict = {}
153
- key_fields = [
154
- "name",
155
- "kind",
156
- "jid",
157
- "j_type",
158
- "context",
159
- "code_sig",
160
- "j_timestamp",
161
- "version",
162
- "to_node_id",
163
- "from_node_id",
164
- ]
165
- for i in vars(self).keys():
166
- if not i.startswith("_"):
167
- if not detailed and i not in key_fields:
168
- continue
169
- jdict[i] = copy.copy(vars(self)[i])
170
- if not detailed and i == "context":
171
- for j in self.private_values():
172
- del jdict[i][j]
173
- if deep > 0 and isinstance(jdict[i], IdList):
174
- for j in range(len(jdict[i])):
175
- jdict[i][j] = copy.copy(
176
- self._h.get_obj(self._m_id, jdict[i][j]).serialize(deep - 1)
177
- )
178
- return jdict
179
-
180
- def json(self, deep=0, detailed=False):
181
- """
182
- Returns entire self object as Json string
183
-
184
- deep indicates number of levels to unwind uuids
185
- """
186
- return json.dumps(
187
- self.serialize(deep, detailed=detailed), indent=4, cls=JaseciJsonEncoder
188
- )
189
-
190
- def json_load(self, blob):
191
- """Loads self from json blob"""
192
- jdict = json_str_to_jsci_dict(blob, parent_obj=self)
193
- self.dict_load(jdict=jdict)
194
-
195
- def dict_load(self, jdict):
196
- """Loads self from dict"""
197
- for i in jdict.keys():
198
- if i in vars(self).keys():
199
- setattr(self, i, jdict[i])
200
-
201
- def get_deep_obj_list(self, objs=None):
202
- """Recursively get all contained Jaseci objects and return id_list"""
203
- if objs is None:
204
- objs = []
205
- objs.append(self)
206
- for i in self.__dict__.keys():
207
- if str(i).endswith("_ids") and isinstance(self.__dict__[i], IdList):
208
- for j in self.__dict__[i].obj_list():
209
- if j not in objs:
210
- j.get_deep_obj_list(objs=objs)
211
- return objs
212
-
213
- def propagate_access(self, set_access=None):
214
- """Propagate permission through id_lists hierarchy"""
215
- if set_access is None:
216
- set_access = self.j_access
217
- for i in self.get_deep_obj_list():
218
- i.j_access = set_access
219
-
220
- def log_output(self, val):
221
- """
222
- Utility to log out variable in pretty format
223
- """
224
- log_var_out(val)
225
-
226
- def __str__(self):
227
- """
228
- String representation is of the form type:name:kind
229
- """
230
- return self.j_type + ":" + self.kind + ":" + self.name + ":" + self.jid
231
-
232
- def __repr__(self):
233
- return self.__str__()
jaseci/prim/graph.py DELETED
@@ -1,27 +0,0 @@
1
- """
2
- Graph class for Jaseci
3
-
4
- """
5
-
6
- from jaseci.prim.node import Node
7
- from jaseci.utils.id_list import IdList
8
-
9
-
10
- class Graph(Node):
11
- """Graph class for Jaseci"""
12
-
13
- def __init__(self, **kwargs):
14
- self.hd_node_ids = IdList(self)
15
- Node.__init__(self, **kwargs)
16
- self.name = "root"
17
- self.kind = "node"
18
-
19
- # Node.__init__(self, name="root", kind="node", **kwargs)
20
-
21
- def destroy(self):
22
- """
23
- Destroys self from memory and persistent storage
24
- """
25
- for i in self.hd_node_ids.obj_list():
26
- i.destroy()
27
- super().destroy()
jaseci/prim/master.py DELETED
@@ -1,67 +0,0 @@
1
- """
2
- Main master handler for each user of Jaseci, serves as main interface between
3
- between user and Jaseci
4
- """
5
-
6
- from jaseci.prim.element import Element
7
- from jaseci.extens.api.alias_api import AliasAPI
8
- from jaseci.extens.api.object_api import ObjectApi
9
- from jaseci.extens.api.graph_api import GraphApi
10
- from jaseci.extens.api.sentinel_api import SentinelApi
11
- from jaseci.extens.api.walker_api import WalkerApi
12
- from jaseci.extens.api.architype_api import ArchitypeApi
13
- from jaseci.extens.api.config_api import ConfigApi
14
- from jaseci.extens.api.interface import Interface
15
- from jaseci.extens.api.master_api import MasterApi
16
- from jaseci.extens.api.jac_api import JacApi
17
- from jaseci.extens.api.user_api import UserApi
18
- from jaseci.extens.api.queue_api import QueueApi
19
- from jaseci.extens.api.webhook_api import WebhookApi
20
- from jaseci.extens.api.share_api import ShareApi
21
- from jaseci.extens.api.health_api import HealthApi
22
- from jaseci.jsorc.jsorc import JsOrc
23
-
24
-
25
- @JsOrc.context(name="master")
26
- class Master(
27
- Element,
28
- Interface,
29
- MasterApi,
30
- AliasAPI,
31
- GraphApi,
32
- ObjectApi,
33
- SentinelApi,
34
- WalkerApi,
35
- ArchitypeApi,
36
- JacApi,
37
- UserApi,
38
- QueueApi,
39
- WebhookApi,
40
- ShareApi,
41
- HealthApi,
42
- ):
43
- """Main class for master functions for user"""
44
-
45
- def __init__(self, head_master=None, *args, **kwargs):
46
- kwargs["m_id"] = None
47
-
48
- Element.__init__(self, kind="Jaseci Master", *args, **kwargs)
49
- MasterApi.__init__(self, head_master)
50
- AliasAPI.__init__(self)
51
- ConfigApi.__init__(self)
52
- ObjectApi.__init__(self)
53
- GraphApi.__init__(self)
54
- WalkerApi.__init__(self)
55
- SentinelApi.__init__(self)
56
- ShareApi.__init__(self)
57
- Interface.__init__(self)
58
-
59
- def destroy(self):
60
- """
61
- Destroys self from memory and persistent storage
62
- """
63
- GraphApi.destroy(self)
64
- SentinelApi.destroy(self)
65
- MasterApi.destroy(self)
66
- WalkerApi.destroy(self)
67
- super().destroy()