jaseci 1.4.2.5__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 (186) 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.5.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 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  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 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  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 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
jaseci/cli_tools/jsctl.py DELETED
@@ -1,500 +0,0 @@
1
- """
2
- Command line tool for Jaseci
3
- """
4
-
5
- import functools
6
- import json
7
- import os
8
- import pickle
9
- import webbrowser
10
- import click
11
- import requests
12
- from click_shell import shell
13
- from click.testing import CliRunner
14
- from jaseci import __version__
15
- from jaseci.prim.super_master import SuperMaster
16
- from jaseci.utils.utils import copy_func
17
- from .book_tools import Book, modifiedBook
18
- from jaseci.utils.file_handler import FileHandler
19
- from jaseci.utils.utils import logger, perf_test_start, perf_test_stop, find_first_api
20
- from jaseci.jsorc.jsorc import JsOrc
21
- from prettytable import PrettyTable
22
-
23
- session = None
24
-
25
-
26
- def reset_state():
27
- global session
28
- session = {
29
- "filename": "js.session",
30
- "user": [JsOrc.super_master(name="admin")],
31
- "mem-only": session["mem-only"] if session is not None else False,
32
- "connection": {"url": None, "token": None, "headers": None},
33
- }
34
- session["master"] = session["user"][0]
35
-
36
-
37
- reset_state()
38
-
39
-
40
- def is_connected():
41
- return bool(session["connection"]["url"])
42
-
43
-
44
- def get_prompt():
45
- if is_connected():
46
- return "@jaseci > "
47
- else:
48
- return "jaseci > "
49
-
50
-
51
- def get_intro():
52
- return f"Jaseci {__version__}\n" + "Starting Shell..."
53
-
54
-
55
- @shell(prompt=get_prompt, intro=get_intro())
56
- @click.option(
57
- "--filename", "-f", default="js.session", help="Specify filename for session state."
58
- )
59
- @click.option(
60
- "--mem-only", "-m", is_flag=True, help="Set true to not save file for session."
61
- )
62
- def jsctl(filename, mem_only):
63
- """
64
- The Jaseci Command Line Interface
65
- """
66
- global session
67
- if not mem_only and os.path.isfile(filename):
68
- with open(filename, "rb") as f:
69
- session = pickle.load(f)
70
- session["mem-only"] = mem_only
71
- session["filename"] = filename if not mem_only else None
72
-
73
-
74
- @click.group()
75
- def jac():
76
- """
77
- Jac tool for building, running, and disassembling Jac programs
78
- """
79
- global session
80
- session["mem-only"] = True
81
-
82
-
83
- def remote_api_call(payload, api_name):
84
- """
85
- Constructs and issues call to remote server
86
- NOTE: Untested
87
- """
88
- path, api = find_first_api(
89
- api_name,
90
- js_public=SuperMaster._public_api,
91
- js=SuperMaster._private_api,
92
- js_admin=SuperMaster._admin_api,
93
- )
94
-
95
- method = requests.post
96
- if api["allowed_methods"] != None and "post" not in api["allowed_methods"]:
97
- method = requests.get
98
-
99
- ret = method(
100
- session["connection"]["url"] + f"/{path}/{api_name}",
101
- json=payload,
102
- headers=session["connection"]["headers"],
103
- )
104
- if ret.status_code > 205:
105
- ret = f"Status Code Error {ret.status_code}\n{ret.json()}"
106
- elif ret.headers.get("Content-Type", None) == "application/octet-stream":
107
- file_handler = FileHandler.fromRequest(
108
- ret.content, ret.headers.get("Content-Disposition")
109
- )
110
- session["master"]._h.add_file_handler(file_handler)
111
- ret = file_handler.attr()
112
- else:
113
- ret = ret.json()
114
- return ret
115
-
116
-
117
- def resolve_none_type(kwargs):
118
- for i in kwargs.keys():
119
- if kwargs[i] == "None":
120
- kwargs[i] = None
121
-
122
-
123
- def has_profile(output):
124
- if isinstance(output, dict):
125
- if "profile" in output.keys():
126
- if "jac" in output["profile"].keys() and "perf" in output["profile"].keys():
127
- return True
128
- return False
129
-
130
-
131
- def gen_pretty_table(csv_str):
132
- rows = csv_str.split("\n")
133
- row_width = len(rows[0].split(","))
134
- first_row = rows[0].split(",")
135
- if first_row[2] == "percall":
136
- first_row[2] = "percall_tot"
137
- try:
138
- table = PrettyTable(first_row)
139
- for i in rows[1:]:
140
- row = i.split(",")
141
- if len(row) != row_width:
142
- continue
143
- table.add_row(row)
144
- return table
145
- except Exception as e:
146
- click.echo(f"Something went wrong pretty printing profile: {e}")
147
-
148
-
149
- def pretty_profile(output):
150
- click.echo("Jac Code Profile:")
151
- click.echo(gen_pretty_table(output["profile"]["jac"]))
152
- click.echo("\nInternal Jaseci Profile:")
153
- click.echo(gen_pretty_table(output["profile"]["perf"]))
154
-
155
-
156
- def interface_api(api_name, is_public, is_cli_only, **kwargs):
157
- """
158
- Interfaces Master apis after processing arguments/parameters
159
- from cli
160
- """
161
- if "code" in kwargs and kwargs["code"]:
162
- if os.path.isfile(kwargs["code"]):
163
- with open(kwargs["code"], "r") as file:
164
- if (
165
- api_name == "sentinel_register"
166
- and "name" in kwargs
167
- and kwargs["name"] == "default"
168
- ):
169
- kwargs["name"] = kwargs["code"]
170
- kwargs["code"] = file.read()
171
- else:
172
- click.echo(f"Code file {kwargs['code']} not found!")
173
- return
174
- resolve_none_type(kwargs)
175
- if not is_cli_only and is_connected():
176
- out = remote_api_call(kwargs, api_name)
177
- elif is_public:
178
- out = session["master"].public_interface_to_api(kwargs, api_name)
179
- else:
180
- out = session["master"].general_interface_to_api(kwargs, api_name)
181
- d_out = out
182
- if isinstance(out, dict):
183
- if "report_custom" in out.keys() and out["report_custom"] is not None:
184
- out = out["report_custom"]
185
- elif "report_file" in out.keys() and out["report_file"] is not None:
186
- out = session["master"]._h.get_file_handler(out["report_file"]).attr()
187
-
188
- if isinstance(out, dict) or isinstance(out, list):
189
- out = json.dumps(out, indent=2)
190
- click.echo(out)
191
- if "output" in kwargs and kwargs["output"]:
192
- with open(kwargs["output"], "w") as f:
193
- f.write(out)
194
- click.echo(f'[saved to {kwargs["output"]}]')
195
- if not session["mem-only"]:
196
- with open(session["filename"], "wb") as f:
197
- pickle.dump(session, f)
198
- if has_profile(d_out):
199
- pretty_profile(d_out)
200
-
201
-
202
- def extract_api_tree():
203
- """
204
- Generates a tree of command group names and function
205
- signatures in leaves from API function names in Master
206
- """
207
- api_funcs = {}
208
- for i in session["master"].all_apis() + session["master"]._cli_api:
209
- # Build hierarchy of command groups
210
- api_root = api_funcs
211
- for j in i["groups"]:
212
- if j not in api_root.keys():
213
- api_root[j] = {}
214
- api_root = api_root[j]
215
- api_root["leaf"] = [
216
- "_".join(i["groups"]),
217
- i["sig"],
218
- i in session["master"]._public_api,
219
- i["doc"],
220
- i["cli_args"],
221
- i in session["master"]._cli_api,
222
- ]
223
- return api_funcs
224
-
225
-
226
- def build_cmd(group_func, func_name, leaf):
227
- """
228
- Generates Click function with options for each command
229
- group and leaf signatures
230
- leaf is format: [api_name, func_sig, is_public, func_doc]
231
- """
232
-
233
- f = functools.partial(
234
- copy_func(interface_api, func_name),
235
- api_name=leaf[0],
236
- is_public=leaf[2],
237
- is_cli_only=leaf[5],
238
- )
239
- f.__name__ = func_name
240
- f.__doc__ = leaf[3]
241
-
242
- func_sig = leaf[1]
243
- cli_args = leaf[4]
244
- for i in func_sig.parameters.keys():
245
- if i == "self":
246
- continue
247
- p_default = func_sig.parameters[i].default
248
- p_type = func_sig.parameters[i].annotation
249
- if p_type not in [int, bool, float]:
250
- p_type = str
251
- if i in cli_args:
252
- f = click.argument(f"{i}", type=p_type)(f)
253
- elif p_default is not func_sig.parameters[i].empty:
254
- f = click.option(
255
- f"-{i}",
256
- default=p_default if p_default is None else p_type(p_default),
257
- required=False,
258
- type=p_type,
259
- )(f)
260
- else:
261
- f = click.option(f"-{i}", required=True, type=p_type)(f)
262
- # to file option to dump response to a file
263
- f = click.option(
264
- "--output",
265
- "-o",
266
- default="",
267
- required=False,
268
- type=str,
269
- help="Filename to dump output of this command call.",
270
- )(f)
271
- return group_func.command()(f)
272
-
273
-
274
- def cmd_tree_builder(location, group_func=jsctl, cmd_str=""):
275
- """
276
- Generates Click command groups from API tree recursively
277
- """
278
- for i in location.keys():
279
- loc = location[i]
280
- if "leaf" in loc:
281
- build_cmd(group_func, i, loc["leaf"])
282
- continue
283
- else:
284
- f = copy_func(lambda: None, i)
285
- f.__doc__ = f'Group of `{(cmd_str + " " + i).lstrip()}` commands'
286
- new_func = group_func.group()(f)
287
- cmd_tree_builder(loc, new_func, cmd_str + " " + i)
288
-
289
-
290
- @click.command(help="Command to log into live Jaseci server")
291
- @click.argument("url", type=str, required=True)
292
- @click.option(
293
- "--username",
294
- "-u",
295
- required=True,
296
- prompt=True,
297
- help="Username to be used for login.",
298
- )
299
- @click.password_option(help="Password to be used for login.", confirmation_prompt=False)
300
- def login(url, username, password):
301
- url = url[:-1] if url[-1] == "/" else url
302
- payload = {"email": username, "password": password}
303
- try:
304
- r = requests.post(url + "/user/token/", data=payload).json()
305
- except Exception:
306
- r = {"error": "Invalid url, username, or password."}
307
- if "token" in r.keys():
308
- session["connection"]["token"] = r["token"]
309
- session["connection"]["url"] = url
310
- session["connection"]["headers"] = {"Authorization": "token " + r["token"]}
311
- click.echo(f"Token: {r['token']}\nLogin successful!")
312
- else:
313
- click.echo("Login failed!\n")
314
- if not session["mem-only"]:
315
- with open(session["filename"], "wb") as f:
316
- pickle.dump(session, f)
317
-
318
-
319
- @click.command(help="Launch Jaseci Studio")
320
- def studio():
321
- token = session["connection"]["token"]
322
-
323
- if not token:
324
- click.echo(
325
- click.style(
326
- "It doesn't look like you're logged in to a Jaseci instance. Please log in to a Jaseci instance to use this command.\n",
327
- fg="red",
328
- )
329
- )
330
- else:
331
- url = session["connection"]["url"] + "/studio/"
332
-
333
- if token == "PUBLIC":
334
- click.echo(
335
- click.style(
336
- "You are logged in as a public user. Please log in to a Jaseci instance to use this command.\n",
337
- fg="red",
338
- )
339
- )
340
-
341
- webbrowser.open(url)
342
- else:
343
- click.echo(click.style("Launching Jaseci Studio...", fg="green"))
344
- click.echo(click.style("URL: ", fg="green", bold=True) + url)
345
- click.echo(click.style(f"Token: {token}", fg="green"))
346
- webbrowser.open(url + "?token=" + token)
347
-
348
-
349
- @click.command(help="Command for unauthenticated log into live Jaseci server")
350
- @click.argument("url", type=str, required=True)
351
- def publogin(url):
352
- url = url[:-1] if url[-1] == "/" else url
353
- if requests.get(url).status_code <= 205:
354
- session["connection"]["token"] = "PUBLIC"
355
- session["connection"]["url"] = url
356
- session["connection"]["headers"] = {}
357
- click.echo("Login successful!")
358
- else:
359
- click.echo("Login failed!\n")
360
- if not session["mem-only"]:
361
- with open(session["filename"], "wb") as f:
362
- pickle.dump(session, f)
363
-
364
-
365
- @click.command(help="Command to log out of live Jaseci server")
366
- def logout():
367
- if session["connection"]["token"]:
368
- session["connection"]["token"] = None
369
- session["connection"]["url"] = None
370
- session["connection"]["headers"] = {}
371
- click.echo("Logout successful!")
372
- else:
373
- click.echo("You are not logged in!")
374
-
375
-
376
- @click.command(help="Edit a file")
377
- @click.argument("file", type=str, required=True)
378
- def edit(file):
379
- click.edit(filename=file)
380
-
381
-
382
- @click.command(help="List relevant files")
383
- @click.option(
384
- "--all",
385
- "-a",
386
- is_flag=True,
387
- help="Flag for listing all files, not just relevant files",
388
- )
389
- def ls(all):
390
- for i in os.listdir():
391
- if all:
392
- click.echo(f"{i}")
393
- else:
394
- click.echo(f"{i}") if i.endswith(".jac") or i.endswith(".dot") else False
395
-
396
-
397
- @click.command(help="Clear terminal")
398
- def clear():
399
- click.clear()
400
-
401
-
402
- @click.command(help="Reset jsctl (clears state)")
403
- def reset():
404
- reset_state()
405
- click.echo("Jaseci State Cleared!")
406
-
407
-
408
- @click.command(help="Run multiple commands sequentially from file")
409
- @click.argument("filename", type=str, required=True)
410
- @click.option("--profile", "-p", is_flag=True)
411
- @click.option(
412
- "--output",
413
- "-o",
414
- default="",
415
- required=False,
416
- type=str,
417
- help="Filename to dump output of this command call.",
418
- )
419
- def script(filename, profile, output):
420
- if profile:
421
- prof = perf_test_start()
422
- if not os.path.isfile(filename):
423
- click.echo("File not found!")
424
- return
425
- with open(filename) as file:
426
- cmds = [line.rstrip() for line in file]
427
- if output:
428
- with open(output, "w") as f:
429
- f.write("Multi Command Script Output:\n")
430
- for i in cmds:
431
- res = CliRunner(mix_stderr=False).invoke(jsctl, i)
432
- click.echo(res.stdout)
433
- if output:
434
- with open(output, "a") as f:
435
- f.write(f"Output for {i}:\n")
436
- f.write(res.stdout)
437
- if profile:
438
- perf, graph = perf_test_stop(prof)
439
- click.echo(perf)
440
- click.echo(graph)
441
- if output:
442
- with open(output, "a") as f:
443
- if profile:
444
- f.write(f"\nProfile:\n")
445
- f.write(perf)
446
- f.write(graph)
447
- click.echo(f"[saved to {output}]")
448
-
449
-
450
- @click.command(help="Internal book generation tools")
451
- @click.argument("op", type=str, default="cheatsheet", required=True)
452
- @click.option(
453
- "--output",
454
- "-o",
455
- default="",
456
- required=False,
457
- type=str,
458
- help="Filename to dump output of this command call.",
459
- )
460
- def booktool(op, output):
461
- out = ""
462
- if op == "cheatsheet":
463
- out = f"{Book().bookgen_api_cheatsheet(extract_api_tree())}"
464
- elif op == "stdlib":
465
- out = Book().bookgen_std_library()
466
- elif op == "mdcheatsheet":
467
- out = f"{modifiedBook().bookgen_api_cheatsheet(extract_api_tree())}"
468
- elif op == "mdstdlib":
469
- out = modifiedBook().bookgen_std_library()
470
- elif op == "classes":
471
- out = Book().bookgen_api_spec()
472
- elif op == "mdclasses":
473
- out = modifiedBook().bookgen_api_spec()
474
- click.echo(out)
475
- if output:
476
- with open(output, "w") as f:
477
- f.write(out)
478
- click.echo(f"[saved to {output}]")
479
-
480
-
481
- jsctl.add_command(login)
482
- jsctl.add_command(publogin)
483
- jsctl.add_command(logout)
484
- jsctl.add_command(edit)
485
- jsctl.add_command(ls)
486
- jsctl.add_command(clear)
487
- jsctl.add_command(reset)
488
- jsctl.add_command(script)
489
- jsctl.add_command(studio)
490
- jsctl.add_command(booktool)
491
- cmd_tree_builder(extract_api_tree())
492
- cmd_tree_builder(extract_api_tree()["jac"], group_func=jac)
493
-
494
-
495
- def main():
496
- jsctl()
497
-
498
-
499
- if __name__ == "__main__":
500
- main()
File without changes