gibson-cli 0.1.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.
- api/BaseApi.py +45 -0
- api/Cli.py +248 -0
- bin/gibson.py +16 -0
- command/Api.py +31 -0
- command/Base.py +28 -0
- command/BaseCommand.py +26 -0
- command/Build.py +69 -0
- command/Code.py +198 -0
- command/Conf.py +74 -0
- command/Count.py +35 -0
- command/Dev.py +121 -0
- command/Forget.py +34 -0
- command/Import.py +109 -0
- command/List.py +61 -0
- command/Merge.py +35 -0
- command/Model.py +42 -0
- command/Models.py +31 -0
- command/Modify.py +43 -0
- command/Module.py +42 -0
- command/New.py +38 -0
- command/OpenApi.py +141 -0
- command/Question.py +105 -0
- command/Remove.py +80 -0
- command/Rename.py +71 -0
- command/Rewrite.py +107 -0
- command/Schema.py +42 -0
- command/Schemas.py +31 -0
- command/Show.py +37 -0
- command/Test.py +42 -0
- command/Tests.py +31 -0
- command/Tree.py +92 -0
- command/WarGames.py +35 -0
- command/auth/Auth.py +25 -0
- command/auth/Login.py +17 -0
- command/auth/Logout.py +7 -0
- command/tests/test_command_BaseCommand.py +10 -0
- command/tests/test_command_Conf.py +19 -0
- conf/Api.py +3 -0
- conf/Code.py +9 -0
- conf/Custom.py +4 -0
- conf/Datastore.py +4 -0
- conf/Dependencies.py +24 -0
- conf/Dev.py +15 -0
- conf/Frameworks.py +7 -0
- conf/Modeler.py +3 -0
- conf/Paths.py +10 -0
- conf/Platform.py +16 -0
- conf/Project.py +18 -0
- conf/Version.py +2 -0
- conf/dev/Api.py +5 -0
- conf/dev/Base.py +3 -0
- conf/dev/Model.py +3 -0
- conf/dev/Schema.py +3 -0
- conf/tests/test_conf_Dependencies.py +5 -0
- conf/tests/test_conf_Platform.py +7 -0
- core/CommandRouter.py +249 -0
- core/Configuration.py +418 -0
- core/Conversation.py +270 -0
- core/Env.py +12 -0
- core/Memory.py +148 -0
- core/TimeKeeper.py +12 -0
- core/utils.py +19 -0
- data/default-ref-table.tmpl +4 -0
- data/default-table.tmpl +6 -0
- db/TableExceptions.py +6 -0
- db/tests/test_db_TableExceptions.py +9 -0
- dev/Dev.py +92 -0
- display/Header.py +6 -0
- display/WorkspaceFooter.py +10 -0
- display/WorkspaceHeader.py +8 -0
- display/tests/test_display_Header.py +9 -0
- display/tests/test_display_WorkspaceFooter.py +9 -0
- display/tests/test_display_WorkspaceHeader.py +8 -0
- gibson_cli-0.1.0.dist-info/METADATA +306 -0
- gibson_cli-0.1.0.dist-info/RECORD +102 -0
- gibson_cli-0.1.0.dist-info/WHEEL +5 -0
- gibson_cli-0.1.0.dist-info/entry_points.txt +2 -0
- gibson_cli-0.1.0.dist-info/top_level.txt +12 -0
- lang/Python.py +57 -0
- lang/tests/test_lang_Python.py +70 -0
- services/auth/Server.py +75 -0
- services/code/context/schema/DataDictionary.py +12 -0
- services/code/context/schema/EntityKeys.py +49 -0
- services/code/context/schema/Manager.py +28 -0
- services/code/context/schema/tests/test_code_context_schema_DataDictionary.py +8 -0
- services/code/context/schema/tests/test_code_context_schema_EntityKeys.py +52 -0
- services/code/context/schema/tests/test_code_context_schema_Manager.py +34 -0
- services/code/customization/Authenticator.py +51 -0
- services/code/customization/BaseCustomization.py +12 -0
- services/code/customization/CustomizationManager.py +20 -0
- services/code/customization/tests/test_code_customization_Authenticator.py +53 -0
- services/code/customization/tests/test_code_customization_BaseCustomization.py +14 -0
- structure/Entity.py +115 -0
- structure/constraints/ReferenceConstraint.py +36 -0
- structure/keys/ForeignKey.py +41 -0
- structure/keys/Index.py +64 -0
- structure/keys/IndexAttribute.py +14 -0
- structure/keys/tests/test_ForeignKey.py +80 -0
- structure/keys/tests/test_Index.py +98 -0
- structure/keys/tests/test_IndexAttribute.py +17 -0
- structure/testing.py +194 -0
- structure/tests/test_Entity.py +107 -0
core/Configuration.py
ADDED
@@ -0,0 +1,418 @@
|
|
1
|
+
import errno
|
2
|
+
import json
|
3
|
+
import os
|
4
|
+
import shutil
|
5
|
+
import sys
|
6
|
+
import time
|
7
|
+
|
8
|
+
from conf.Dependencies import Dependencies
|
9
|
+
from conf.dev.Api import Api
|
10
|
+
from conf.dev.Base import Base
|
11
|
+
from conf.dev.Model import Model
|
12
|
+
from conf.dev.Schema import Schema
|
13
|
+
from conf.Platform import Platform
|
14
|
+
from conf.Project import Project
|
15
|
+
from conf.Paths import ConfigPaths
|
16
|
+
from .Conversation import Conversation
|
17
|
+
|
18
|
+
|
19
|
+
class Configuration:
|
20
|
+
VERSION = 2
|
21
|
+
API_ENV = os.environ.get("GIBSONAI_API_ENV", "staging")
|
22
|
+
|
23
|
+
def __init__(self):
|
24
|
+
self.command = None
|
25
|
+
if len(sys.argv) >= 1:
|
26
|
+
self.command = sys.argv[0].split("/")[-1]
|
27
|
+
|
28
|
+
self.conversation = Conversation()
|
29
|
+
self.platform = Platform()
|
30
|
+
self.project = Project()
|
31
|
+
self.paths = ConfigPaths()
|
32
|
+
self.settings = None
|
33
|
+
|
34
|
+
self.__check_configuration_path()
|
35
|
+
|
36
|
+
self.set_config_paths()
|
37
|
+
self.__check_for_configuration_migration()
|
38
|
+
|
39
|
+
self.read_config()
|
40
|
+
|
41
|
+
def append_project_to_conf(self, project_name, project_description):
|
42
|
+
self.project.api.key = "FIXME"
|
43
|
+
self.project.name = project_name
|
44
|
+
self.project.datastore.type = "mysql"
|
45
|
+
self.project.datastore.uri = "mysql+pymysql://user:password@host/database_name"
|
46
|
+
self.project.description = project_description
|
47
|
+
|
48
|
+
dependencies = Dependencies().compute()
|
49
|
+
|
50
|
+
section = f""""{self.project.name}": {{
|
51
|
+
"api": {{
|
52
|
+
"key": "{self.project.api.key}"
|
53
|
+
}},
|
54
|
+
"code": {{
|
55
|
+
"custom": {{
|
56
|
+
"model": {{
|
57
|
+
"class": None,
|
58
|
+
"path": None
|
59
|
+
}}
|
60
|
+
}},
|
61
|
+
"frameworks": {{
|
62
|
+
"api": "{dependencies.api}",
|
63
|
+
"model": "{dependencies.model}",
|
64
|
+
"revision": "{dependencies.revision}",
|
65
|
+
"schema": "{dependencies.schema}",
|
66
|
+
"test": "{dependencies.test}",
|
67
|
+
}},
|
68
|
+
"language": "python"
|
69
|
+
}},
|
70
|
+
"datastore": {{
|
71
|
+
"type": "{self.project.datastore.type}",
|
72
|
+
"uri": "{self.project.datastore.uri}"
|
73
|
+
}},
|
74
|
+
"dev": {{
|
75
|
+
"active": False,
|
76
|
+
"api": {{
|
77
|
+
"path": None,
|
78
|
+
"prefix": "-",
|
79
|
+
"version": "v1"
|
80
|
+
}},
|
81
|
+
"base": {{
|
82
|
+
"path": None
|
83
|
+
}},
|
84
|
+
"model": {{
|
85
|
+
"path": None
|
86
|
+
}},
|
87
|
+
"schema": {{
|
88
|
+
"path": None
|
89
|
+
}}
|
90
|
+
}},
|
91
|
+
"meta": {{
|
92
|
+
"project": {{
|
93
|
+
"description": "{self.project.description}"
|
94
|
+
}},
|
95
|
+
"version": {self.VERSION}
|
96
|
+
}},
|
97
|
+
"modeler": {{
|
98
|
+
"version": "generic-v7"
|
99
|
+
}}
|
100
|
+
}}"""
|
101
|
+
|
102
|
+
if self.settings is None:
|
103
|
+
self.settings = {}
|
104
|
+
|
105
|
+
self.settings[self.project.name] = {
|
106
|
+
"api": {"key": self.project.api.key},
|
107
|
+
"code": {
|
108
|
+
"custom": {"model": {"class": None, "path": None}},
|
109
|
+
"frameworks": {
|
110
|
+
"api": dependencies.api,
|
111
|
+
"model": dependencies.model,
|
112
|
+
"revision": dependencies.revision,
|
113
|
+
"schema": dependencies.schema,
|
114
|
+
"test": dependencies.test,
|
115
|
+
},
|
116
|
+
"language": "python",
|
117
|
+
},
|
118
|
+
"datastore": {
|
119
|
+
"type": self.project.datastore.type,
|
120
|
+
"uri": self.project.datastore.uri,
|
121
|
+
},
|
122
|
+
"dev": {
|
123
|
+
"active": False,
|
124
|
+
"api": {"path": None, "prefix": "-", "version": "v1"},
|
125
|
+
"base": {"path": None},
|
126
|
+
"model": {
|
127
|
+
"path": None,
|
128
|
+
},
|
129
|
+
"schema": {"path": None},
|
130
|
+
},
|
131
|
+
"meta": {
|
132
|
+
"project": {"description": self.project.description},
|
133
|
+
"version": self.VERSION,
|
134
|
+
},
|
135
|
+
"modeler": {"version": "generic-v7"},
|
136
|
+
}
|
137
|
+
|
138
|
+
self.write_config()
|
139
|
+
|
140
|
+
return section
|
141
|
+
|
142
|
+
def ask_for_path(self, current_value):
|
143
|
+
while True:
|
144
|
+
path = input(f" [{current_value}]: > ")
|
145
|
+
if path in [None, ""]:
|
146
|
+
if current_value not in [None, ""]:
|
147
|
+
path = current_value
|
148
|
+
|
149
|
+
test_file = f"{os.path.expandvars(path)}/gibsonai-test-file"
|
150
|
+
|
151
|
+
try:
|
152
|
+
with open(test_file, "w") as f:
|
153
|
+
pass
|
154
|
+
|
155
|
+
os.remove(test_file)
|
156
|
+
|
157
|
+
return path
|
158
|
+
except:
|
159
|
+
self.conversation.newline()
|
160
|
+
self.conversation.type(
|
161
|
+
" Well this is embarrassing. I cannot write to that path.\n"
|
162
|
+
)
|
163
|
+
self.conversation.newline()
|
164
|
+
|
165
|
+
raise RuntimeError
|
166
|
+
|
167
|
+
def ask_for_value(self, name, current_value):
|
168
|
+
value = input(f"{name} [{current_value}]: > ")
|
169
|
+
if value in [None, ""]:
|
170
|
+
return current_value
|
171
|
+
|
172
|
+
return value
|
173
|
+
|
174
|
+
def __check_configuration_path(self):
|
175
|
+
config_path = os.environ.get("GIBSONAI_CONFIG_PATH", None)
|
176
|
+
if config_path is None:
|
177
|
+
return self
|
178
|
+
|
179
|
+
if not os.path.isfile(f"{config_path}/config"):
|
180
|
+
self.conversation.newline()
|
181
|
+
self.conversation.type(
|
182
|
+
"[MIGRATION] environment variable detected; moving configuration to\n"
|
183
|
+
+ f" {config_path}\n\n"
|
184
|
+
)
|
185
|
+
|
186
|
+
self.set_config_paths(ignore_env_vars=True)
|
187
|
+
self.read_config()
|
188
|
+
|
189
|
+
old_memory_path = self.project.paths.memory
|
190
|
+
|
191
|
+
self.set_config_paths()
|
192
|
+
self.create_project_memory()
|
193
|
+
self.write_config()
|
194
|
+
|
195
|
+
shutil.copytree(
|
196
|
+
f"{old_memory_path}/{self.project.name}",
|
197
|
+
f"{self.project.paths.memory}/{self.project.name}",
|
198
|
+
)
|
199
|
+
|
200
|
+
return self
|
201
|
+
|
202
|
+
def __check_for_configuration_migration(self):
|
203
|
+
try:
|
204
|
+
with open(self.project.paths.config, "r") as f:
|
205
|
+
contents = f.read()
|
206
|
+
except FileNotFoundError:
|
207
|
+
return self
|
208
|
+
|
209
|
+
self.settings = json.loads(contents)
|
210
|
+
if self.settings is None:
|
211
|
+
return self
|
212
|
+
|
213
|
+
for project_name, conf in self.settings.items():
|
214
|
+
if "version" not in conf["meta"]:
|
215
|
+
# -- Migrate from version 0 -> 1
|
216
|
+
self.conversation.newline()
|
217
|
+
self.conversation.type(
|
218
|
+
f"[MIGRATION] {project_name} configuration: 0 -> 1"
|
219
|
+
)
|
220
|
+
|
221
|
+
conf["meta"]["version"] = 1
|
222
|
+
conf["dev"] = conf["copilot"]
|
223
|
+
del conf["copilot"]
|
224
|
+
|
225
|
+
self.settings[project_name] = conf
|
226
|
+
|
227
|
+
if conf["meta"]["version"] == 1:
|
228
|
+
# -- Migrate from version 1 -> 2
|
229
|
+
self.conversation.newline()
|
230
|
+
self.conversation.type(
|
231
|
+
f"[MIGRATION] {project_name} configuration: 1 -> 2\n"
|
232
|
+
)
|
233
|
+
self.conversation.type(
|
234
|
+
" We advise that you execute the following command to "
|
235
|
+
+ "configure new features:\n"
|
236
|
+
+ " gibson dev on\n"
|
237
|
+
)
|
238
|
+
self.conversation.wait()
|
239
|
+
|
240
|
+
conf["meta"]["version"] = self.VERSION
|
241
|
+
conf["dev"]["api"] = {"path": None, "prefix": "-", "version": "v1"}
|
242
|
+
conf["dev"]["base"] = {"path": conf["dev"]["path"]["base"]}
|
243
|
+
conf["dev"]["model"] = {"path": conf["dev"]["path"]["model"]}
|
244
|
+
conf["dev"]["schema"] = {"path": conf["dev"]["path"]["schema"]}
|
245
|
+
|
246
|
+
del conf["dev"]["path"]
|
247
|
+
|
248
|
+
self.settings[project_name] = conf
|
249
|
+
|
250
|
+
self.write_config()
|
251
|
+
|
252
|
+
return self
|
253
|
+
|
254
|
+
def create_project_memory(self):
|
255
|
+
try:
|
256
|
+
os.makedirs(self.project.paths.memory)
|
257
|
+
except OSError as e:
|
258
|
+
if e.errno != errno.EEXIST:
|
259
|
+
raise
|
260
|
+
|
261
|
+
def get_access_token(self):
|
262
|
+
try:
|
263
|
+
with open(f"{self.paths.auth}/{self.API_ENV}", "r") as f:
|
264
|
+
contents = f.read()
|
265
|
+
except FileNotFoundError:
|
266
|
+
return None
|
267
|
+
|
268
|
+
token = json.loads(contents)
|
269
|
+
return token["access_token"]
|
270
|
+
|
271
|
+
def get_my_settings(self):
|
272
|
+
return self.settings[self.project.name]
|
273
|
+
|
274
|
+
def initialize(self):
|
275
|
+
self.conversation.message_welcome()
|
276
|
+
print("")
|
277
|
+
project_name = self.conversation.prompt_project()
|
278
|
+
project_description = self.conversation.prompt_description(project_name)
|
279
|
+
|
280
|
+
self.conversation.message_new_project(project_name)
|
281
|
+
self.conversation.pause()
|
282
|
+
|
283
|
+
section = self.append_project_to_conf(project_name, project_description)
|
284
|
+
self.create_project_memory()
|
285
|
+
|
286
|
+
self.conversation.message_configuration_added(
|
287
|
+
self.project.paths.config, section
|
288
|
+
)
|
289
|
+
self.conversation.wait()
|
290
|
+
self.conversation.message_customize_settings()
|
291
|
+
|
292
|
+
self.conversation.wait()
|
293
|
+
self.conversation.message_environment()
|
294
|
+
|
295
|
+
self.conversation.wait()
|
296
|
+
self.conversation.message_explain_help()
|
297
|
+
self.conversation.pause()
|
298
|
+
print("")
|
299
|
+
|
300
|
+
return self
|
301
|
+
|
302
|
+
def read_config(self):
|
303
|
+
try:
|
304
|
+
with open(self.project.paths.config, "r") as f:
|
305
|
+
contents = f.read()
|
306
|
+
except FileNotFoundError:
|
307
|
+
return self
|
308
|
+
|
309
|
+
self.settings = json.loads(contents)
|
310
|
+
if self.settings is None:
|
311
|
+
return self
|
312
|
+
|
313
|
+
if len(self.settings.keys()) == 1:
|
314
|
+
config = list(self.settings.values())[0]
|
315
|
+
self.project.name = list(self.settings.keys())[0]
|
316
|
+
else:
|
317
|
+
gibsonai_project = os.environ.get("GIBSONAI_PROJECT")
|
318
|
+
if gibsonai_project is None:
|
319
|
+
self.conversation.gibsonai_project_not_set(self)
|
320
|
+
exit(1)
|
321
|
+
|
322
|
+
if gibsonai_project not in self.settings:
|
323
|
+
self.conversation.unrecognized_project(self, gibsonai_project)
|
324
|
+
exit(1)
|
325
|
+
|
326
|
+
config = self.settings[gibsonai_project]
|
327
|
+
self.project.name = gibsonai_project
|
328
|
+
|
329
|
+
self.project.api.key = config["api"]["key"]
|
330
|
+
self.project.code.custom.model_class = config["code"]["custom"]["model"][
|
331
|
+
"class"
|
332
|
+
]
|
333
|
+
self.project.code.custom.model_path = config["code"]["custom"]["model"]["path"]
|
334
|
+
self.project.code.frameworks.api = config["code"]["frameworks"]["api"]
|
335
|
+
self.project.code.frameworks.model = config["code"]["frameworks"]["model"]
|
336
|
+
self.project.code.frameworks.revision = config["code"]["frameworks"]["revision"]
|
337
|
+
self.project.code.frameworks.schema = config["code"]["frameworks"]["schema"]
|
338
|
+
self.project.code.frameworks.test = config["code"]["frameworks"]["test"]
|
339
|
+
self.project.code.language = config["code"]["language"]
|
340
|
+
self.project.dev.active = config["dev"]["active"]
|
341
|
+
self.project.dev.api.path = config["dev"]["api"]["path"]
|
342
|
+
self.project.dev.api.prefix = config["dev"]["api"]["prefix"]
|
343
|
+
self.project.dev.api.version = config["dev"]["api"]["version"]
|
344
|
+
self.project.dev.base.path = config["dev"]["base"]["path"]
|
345
|
+
self.project.dev.model.path = config["dev"]["model"]["path"]
|
346
|
+
self.project.dev.schema.path = config["dev"]["schema"]["path"]
|
347
|
+
self.project.datastore.type = config["datastore"]["type"]
|
348
|
+
self.project.datastore.uri = config["datastore"]["uri"]
|
349
|
+
self.project.description = config["meta"]["project"]["description"]
|
350
|
+
self.project.modeler.version = config["modeler"]["version"]
|
351
|
+
|
352
|
+
return self
|
353
|
+
|
354
|
+
def set_access_token(self, token):
|
355
|
+
try:
|
356
|
+
os.mkdir(self.paths.auth)
|
357
|
+
except FileExistsError:
|
358
|
+
pass
|
359
|
+
|
360
|
+
with open(f"{self.paths.auth}/{self.API_ENV}", "w") as f:
|
361
|
+
f.write(json.dumps({"access_token": token}))
|
362
|
+
|
363
|
+
def set_config_paths(self, ignore_env_vars=False):
|
364
|
+
user_home = os.environ.get("HOME")
|
365
|
+
gibson_config_dir = ".gibsonai"
|
366
|
+
self.paths.auth = f"{user_home}/{gibson_config_dir}/auth"
|
367
|
+
|
368
|
+
project_config_path = None
|
369
|
+
if ignore_env_vars is False:
|
370
|
+
project_config_path = os.environ.get("GIBSONAI_CONFIG_PATH", None)
|
371
|
+
|
372
|
+
if project_config_path is None:
|
373
|
+
project_config_path = user_home
|
374
|
+
if project_config_path is None:
|
375
|
+
raise RuntimeError(
|
376
|
+
"Gibson here. Please set your HOME environment variable."
|
377
|
+
)
|
378
|
+
|
379
|
+
project_config_path += f"/{gibson_config_dir}"
|
380
|
+
|
381
|
+
self.project.paths.top = project_config_path
|
382
|
+
self.project.paths.config = f"{self.project.paths.top}/config"
|
383
|
+
self.project.paths.memory = f"{self.project.paths.top}/memory"
|
384
|
+
|
385
|
+
def set_project_env(self, project_name):
|
386
|
+
os.environ["GIBSONAI_PROJECT"] = project_name
|
387
|
+
return self
|
388
|
+
|
389
|
+
def turn_dev_off(self):
|
390
|
+
self.settings[self.project.name]["dev"]["active"] = False
|
391
|
+
self.write_config()
|
392
|
+
return self
|
393
|
+
|
394
|
+
def turn_dev_on(
|
395
|
+
self, api_path, api_prefix, api_version, base_path, model_path, schema_path
|
396
|
+
):
|
397
|
+
self.settings[self.project.name]["dev"]["active"] = True
|
398
|
+
self.settings[self.project.name]["dev"]["api"]["path"] = api_path
|
399
|
+
self.settings[self.project.name]["dev"]["api"]["prefix"] = api_prefix
|
400
|
+
self.settings[self.project.name]["dev"]["api"]["version"] = api_version
|
401
|
+
self.settings[self.project.name]["dev"]["base"]["path"] = base_path
|
402
|
+
self.settings[self.project.name]["dev"]["model"]["path"] = model_path
|
403
|
+
self.settings[self.project.name]["dev"]["schema"]["path"] = schema_path
|
404
|
+
self.write_config()
|
405
|
+
return self
|
406
|
+
|
407
|
+
def write_config(self):
|
408
|
+
try:
|
409
|
+
os.mkdir("/".join(self.project.paths.config.split("/")[0:-1]))
|
410
|
+
except FileExistsError:
|
411
|
+
pass
|
412
|
+
|
413
|
+
with open(self.project.paths.config, "w") as f:
|
414
|
+
f.write(json.dumps(self.settings))
|
415
|
+
|
416
|
+
self.read_config()
|
417
|
+
|
418
|
+
return self
|
core/Conversation.py
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
import re
|
2
|
+
import sys
|
3
|
+
import threading
|
4
|
+
import time
|
5
|
+
|
6
|
+
import pyfiglet
|
7
|
+
|
8
|
+
from conf.Version import Version
|
9
|
+
|
10
|
+
|
11
|
+
class Conversation:
|
12
|
+
DEFAULT_DELAY = 0.01
|
13
|
+
|
14
|
+
def __init__(self):
|
15
|
+
self.__delay = self.DEFAULT_DELAY
|
16
|
+
self.__mute = False
|
17
|
+
|
18
|
+
def c64_boot_loading(self):
|
19
|
+
self.type("LOADING\n")
|
20
|
+
return self
|
21
|
+
|
22
|
+
def c64_ready_run(self):
|
23
|
+
self.type("READY.\n")
|
24
|
+
self.type("RUN")
|
25
|
+
return self
|
26
|
+
|
27
|
+
def c64_boot_search(self):
|
28
|
+
self.type(" **** COMMODORE 64 BASIC V2 ****\n")
|
29
|
+
self.type(" 64K RAM SYSTEM 38911 BASIC BYTES FREE\n\n")
|
30
|
+
self.type("READY.\n")
|
31
|
+
self.type('LOAD "*",8,1\n\n')
|
32
|
+
self.type("SEARCHING FOR *\n")
|
33
|
+
return self
|
34
|
+
|
35
|
+
def cant_no_entities(self, project_name):
|
36
|
+
self.display_project(project_name)
|
37
|
+
self.type("I would love to but you have not defined any entities.\n\n")
|
38
|
+
return self
|
39
|
+
|
40
|
+
def clear_line(self):
|
41
|
+
if self.__mute is True:
|
42
|
+
return self
|
43
|
+
|
44
|
+
print("\033[1A\033[K", end="")
|
45
|
+
|
46
|
+
def configure_dev_mode(self):
|
47
|
+
self.type(
|
48
|
+
"I would love to do that for you but you have not configured "
|
49
|
+
+ "dev mode yet.\nExecute:\n\n gibson dev on"
|
50
|
+
)
|
51
|
+
self.newline()
|
52
|
+
|
53
|
+
def configure_new_project(self, configuration):
|
54
|
+
self.type(
|
55
|
+
"\nI am so excited that we're building something new together. "
|
56
|
+
+ "You probably need\nto execute:\n\n"
|
57
|
+
+ " gibson conf api::key [API key]\n"
|
58
|
+
+ " gibson conf datastore::uri [datastore URI]\n\n"
|
59
|
+
+ "To finish setting things up.\n"
|
60
|
+
)
|
61
|
+
self.newline()
|
62
|
+
|
63
|
+
if len(configuration.settings.keys()) > 1:
|
64
|
+
self.type(
|
65
|
+
"Now that you have more than one project configured, execute one "
|
66
|
+
+ "of the following:\n\n"
|
67
|
+
)
|
68
|
+
|
69
|
+
for key in configuration.settings.keys():
|
70
|
+
self.type(f" export GIBSONAI_PROJECT={key}\n")
|
71
|
+
|
72
|
+
self.newline()
|
73
|
+
|
74
|
+
def display_project(self, project_name):
|
75
|
+
self.type(f"<> Project {project_name}\n\n")
|
76
|
+
|
77
|
+
def entities_hijacked(self):
|
78
|
+
self.type(
|
79
|
+
"GibsonAI here, I hijacked a bunch of entities. They are in last memory."
|
80
|
+
)
|
81
|
+
return self
|
82
|
+
|
83
|
+
def gibsonai_project_not_set(self, configuration):
|
84
|
+
self.type(
|
85
|
+
"\nYou have to set the environment variable GIBSONAI_PROJECT "
|
86
|
+
+ "because you have\nmore than one project. Execute one of "
|
87
|
+
+ "the following statements:\n"
|
88
|
+
)
|
89
|
+
self.newline()
|
90
|
+
|
91
|
+
for key in configuration.settings.keys():
|
92
|
+
self.type(f" export GIBSONAI_PROJECT={key}\n")
|
93
|
+
|
94
|
+
self.newline()
|
95
|
+
|
96
|
+
def message_configuration_added(self, config_path, section):
|
97
|
+
self.type(f"I store my configuration in this file:\n\n{config_path}\n\n")
|
98
|
+
self.type("And I just added this section to the configuration:\n\n")
|
99
|
+
self.type(f"{section}\n", delay=0.002)
|
100
|
+
return self
|
101
|
+
|
102
|
+
def message_customize_settings(self):
|
103
|
+
self.type(
|
104
|
+
f"You can edit the configuration file directly or ask me to do it for you.\n"
|
105
|
+
)
|
106
|
+
self.type(
|
107
|
+
"I will not be able to do much until you modify api::key and "
|
108
|
+
+ "datastore::uri.\n"
|
109
|
+
)
|
110
|
+
return self
|
111
|
+
|
112
|
+
def message_environment(self):
|
113
|
+
self.type(
|
114
|
+
"If you set the environment variable GIBSONAI_PROJECT you can get straight\n"
|
115
|
+
)
|
116
|
+
self.type(
|
117
|
+
"to it. Or, if your configuration file only has one project, I will default\n"
|
118
|
+
)
|
119
|
+
self.type("to that.\n")
|
120
|
+
return self
|
121
|
+
|
122
|
+
def message_explain_help(self):
|
123
|
+
self.type('Last item of business, if you need help just type "gibson help".\n')
|
124
|
+
return self
|
125
|
+
|
126
|
+
def message_new_project(self, project_name):
|
127
|
+
self.type(
|
128
|
+
f"\n{project_name} is going to be huge! Congratulations on the new project.\n\n"
|
129
|
+
)
|
130
|
+
return self
|
131
|
+
|
132
|
+
def message_welcome(self):
|
133
|
+
self.newline()
|
134
|
+
print(pyfiglet.figlet_format("GibsonAI", font="big").rstrip(), end="")
|
135
|
+
print(f" ...CLI v{Version.NUM}...")
|
136
|
+
self.newline()
|
137
|
+
self.pause()
|
138
|
+
self.type("Welcome!\n\n")
|
139
|
+
self.pause()
|
140
|
+
self.type(
|
141
|
+
"Let's get you set up. Give me the name of the project you're working on.\n"
|
142
|
+
)
|
143
|
+
self.type(
|
144
|
+
"Don't worry, once we get to know each other you'll be able to modify this\n"
|
145
|
+
)
|
146
|
+
self.type("or add new projects on your own.\n")
|
147
|
+
return self
|
148
|
+
|
149
|
+
def mute(self):
|
150
|
+
self.__mute = True
|
151
|
+
return self
|
152
|
+
|
153
|
+
def muted(self):
|
154
|
+
return self.__mute is True
|
155
|
+
|
156
|
+
def newline(self):
|
157
|
+
if self.__mute is True:
|
158
|
+
return self
|
159
|
+
|
160
|
+
print("")
|
161
|
+
|
162
|
+
def new_project(self, configuration):
|
163
|
+
self.newline()
|
164
|
+
print(pyfiglet.figlet_format("GibsonAI", font="big").rstrip(), end="")
|
165
|
+
print(f" ...CLI v{Version.NUM}...")
|
166
|
+
self.newline()
|
167
|
+
|
168
|
+
if len(configuration.settings.keys()) <= 1:
|
169
|
+
self.type("Phew. You like me. Let's do this.\n\n")
|
170
|
+
else:
|
171
|
+
self.type("Back...again? You know what to do.\n\n")
|
172
|
+
|
173
|
+
def not_sure_no_entity(self, project_name, entity_name):
|
174
|
+
self.display_project(project_name)
|
175
|
+
self.type(f'Not sure what to do. "{entity_name}" does not exist.\n\n')
|
176
|
+
return self
|
177
|
+
|
178
|
+
def nothing_to_list(self, whats_being_listed):
|
179
|
+
self.type(
|
180
|
+
f"There is only so much I can do. No {whats_being_listed}, nothing to list."
|
181
|
+
)
|
182
|
+
self.newline()
|
183
|
+
|
184
|
+
def pause(self):
|
185
|
+
time.sleep(2)
|
186
|
+
|
187
|
+
def project_already_exists(self, project_name):
|
188
|
+
self.type(f'\nA project called "{project_name}" already exists.\n')
|
189
|
+
self.newline()
|
190
|
+
|
191
|
+
def prompt_description(self, project_name):
|
192
|
+
while True:
|
193
|
+
self.type(f"Tell me about {project_name}. Don't be shy > ")
|
194
|
+
user_prompt = input("")
|
195
|
+
if len(user_prompt) > 0:
|
196
|
+
return user_prompt
|
197
|
+
|
198
|
+
def prompt_project(self):
|
199
|
+
while True:
|
200
|
+
self.type("Project Name [A-Za-z0-9_-] > ")
|
201
|
+
user_prompt = input("")
|
202
|
+
if re.search("^[A-Za-z0-9_-]+$", user_prompt):
|
203
|
+
return user_prompt
|
204
|
+
|
205
|
+
def raw_llm_response(self):
|
206
|
+
print("\n+" + "-" * 75 + "+")
|
207
|
+
print("| Raw LLM Response" + " " * 58 + "|")
|
208
|
+
print("+" + "-" * 75 + "+\n")
|
209
|
+
return self
|
210
|
+
|
211
|
+
def set_delay(self, delay):
|
212
|
+
self.__delay = delay
|
213
|
+
return self
|
214
|
+
|
215
|
+
def spin(self, thread: threading.Thread):
|
216
|
+
animation = self.spinner()
|
217
|
+
while thread.is_alive():
|
218
|
+
sys.stdout.write(next(animation))
|
219
|
+
sys.stdout.flush()
|
220
|
+
time.sleep(0.1)
|
221
|
+
sys.stdout.write("\b")
|
222
|
+
|
223
|
+
def spinner(self):
|
224
|
+
while True:
|
225
|
+
for cursor in "|/-\\":
|
226
|
+
yield cursor
|
227
|
+
|
228
|
+
def type(self, message, delay=None):
|
229
|
+
if self.__mute is True:
|
230
|
+
return self
|
231
|
+
|
232
|
+
if delay is None:
|
233
|
+
delay = self.DEFAULT_DELAY
|
234
|
+
if self.__delay is not None:
|
235
|
+
delay = self.__delay
|
236
|
+
|
237
|
+
for char in message:
|
238
|
+
sys.stdout.write(char)
|
239
|
+
sys.stdout.flush()
|
240
|
+
time.sleep(delay)
|
241
|
+
|
242
|
+
def unmute(self):
|
243
|
+
self.__mute = False
|
244
|
+
return self
|
245
|
+
|
246
|
+
def unrecognized_project(self, configuration, project_name):
|
247
|
+
self.type(
|
248
|
+
f'\nYou have not configured a project called "{project_name}". There '
|
249
|
+
+ "are two paths forward:\n"
|
250
|
+
)
|
251
|
+
self.newline()
|
252
|
+
|
253
|
+
self.type(" gibson new project\n")
|
254
|
+
self.newline()
|
255
|
+
|
256
|
+
self.type(f'To create a project called "{project_name}", or:\n')
|
257
|
+
self.newline()
|
258
|
+
|
259
|
+
for key in configuration.settings.keys():
|
260
|
+
self.type(f" export GIBSONAI_PROJECT={key}\n")
|
261
|
+
|
262
|
+
self.newline()
|
263
|
+
self.type("To correctly set the environment variable.\n")
|
264
|
+
self.newline()
|
265
|
+
|
266
|
+
def wait(self):
|
267
|
+
self.newline()
|
268
|
+
self.type("<Press Enter>")
|
269
|
+
input("")
|
270
|
+
self.clear_line()
|
core/Env.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from .Configuration import Configuration
|
2
|
+
from lang.Python import Python
|
3
|
+
|
4
|
+
|
5
|
+
class Env:
|
6
|
+
def verify(self, configuration: Configuration):
|
7
|
+
if configuration.project.code.language == "python":
|
8
|
+
Python().make_import_path(configuration.project.dev.base.path)
|
9
|
+
else:
|
10
|
+
raise RuntimeError(
|
11
|
+
f'unrecognized language "{configuration.project.code.language}"'
|
12
|
+
)
|