autonomous-app 0.2.25__py3-none-any.whl → 0.3.1__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.
- autonomous/__init__.py +5 -2
- autonomous/ai/audioagent.py +32 -0
- autonomous/ai/imageagent.py +31 -0
- autonomous/ai/jsonagent.py +40 -0
- autonomous/ai/models/__init__.py +0 -0
- autonomous/ai/models/openai.py +308 -0
- autonomous/ai/oaiagent.py +20 -194
- autonomous/ai/textagent.py +35 -0
- autonomous/auth/autoauth.py +11 -11
- autonomous/auth/user.py +24 -11
- autonomous/db/__init__.py +41 -0
- autonomous/db/base/__init__.py +33 -0
- autonomous/db/base/common.py +62 -0
- autonomous/db/base/datastructures.py +476 -0
- autonomous/db/base/document.py +1230 -0
- autonomous/db/base/fields.py +767 -0
- autonomous/db/base/metaclasses.py +468 -0
- autonomous/db/base/utils.py +22 -0
- autonomous/db/common.py +79 -0
- autonomous/db/connection.py +472 -0
- autonomous/db/context_managers.py +313 -0
- autonomous/db/dereference.py +291 -0
- autonomous/db/document.py +1141 -0
- autonomous/db/errors.py +165 -0
- autonomous/db/fields.py +2732 -0
- autonomous/db/mongodb_support.py +24 -0
- autonomous/db/pymongo_support.py +80 -0
- autonomous/db/queryset/__init__.py +28 -0
- autonomous/db/queryset/base.py +2033 -0
- autonomous/db/queryset/field_list.py +88 -0
- autonomous/db/queryset/manager.py +58 -0
- autonomous/db/queryset/queryset.py +189 -0
- autonomous/db/queryset/transform.py +527 -0
- autonomous/db/queryset/visitor.py +189 -0
- autonomous/db/signals.py +59 -0
- autonomous/logger.py +3 -0
- autonomous/model/autoattr.py +120 -0
- autonomous/model/automodel.py +121 -308
- autonomous/storage/imagestorage.py +9 -54
- autonomous/tasks/autotask.py +0 -25
- {autonomous_app-0.2.25.dist-info → autonomous_app-0.3.1.dist-info}/METADATA +7 -8
- autonomous_app-0.3.1.dist-info/RECORD +60 -0
- {autonomous_app-0.2.25.dist-info → autonomous_app-0.3.1.dist-info}/WHEEL +1 -1
- autonomous/db/autodb.py +0 -86
- autonomous/db/table.py +0 -156
- autonomous/errors/__init__.py +0 -1
- autonomous/errors/danglingreferenceerror.py +0 -8
- autonomous/model/autoattribute.py +0 -20
- autonomous/model/orm.py +0 -86
- autonomous/model/serializer.py +0 -110
- autonomous_app-0.2.25.dist-info/RECORD +0 -36
- /autonomous/{storage → apis}/version_control/GHCallbacks.py +0 -0
- /autonomous/{storage → apis}/version_control/GHOrganization.py +0 -0
- /autonomous/{storage → apis}/version_control/GHRepo.py +0 -0
- /autonomous/{storage → apis}/version_control/GHVersionControl.py +0 -0
- /autonomous/{storage → apis}/version_control/__init__.py +0 -0
- /autonomous/{storage → utils}/markdown.py +0 -0
- {autonomous_app-0.2.25.dist-info → autonomous_app-0.3.1.dist-info}/LICENSE +0 -0
- {autonomous_app-0.2.25.dist-info → autonomous_app-0.3.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
autonomous/__init__.py,sha256=4zG57y3yMritw2TPxGgITZCNAcpJp2ZELW1iO8Wrlp0,95
|
|
2
|
+
autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
|
|
3
|
+
autonomous/logger.py,sha256=NQtgEaTWNAWfLSgqSP7ksXj1GpOuCgoUV711kSMm-WA,2022
|
|
4
|
+
autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
autonomous/ai/audioagent.py,sha256=uZEhJ8_ctEvzshxJewaGdw-gh2Ts8lIcEysh0rlL62w,1040
|
|
6
|
+
autonomous/ai/imageagent.py,sha256=Y3n4OFD-UC9lSg1j-U9wRnyLLaRl0LjibHbriJwYF2c,981
|
|
7
|
+
autonomous/ai/jsonagent.py,sha256=P5HGuN7r7whgryZ2oCvSRY7jQlq0FdDK3-DtdnUG_N0,1321
|
|
8
|
+
autonomous/ai/oaiagent.py,sha256=Zrd4iijGfkFsF1Dbhhj0SeHoezec3kae8CrFrZQeqXQ,1346
|
|
9
|
+
autonomous/ai/textagent.py,sha256=pYzuoE7ENsxXjTSoVRMGvy7KQK0cS50SlWpY-1r7PiY,1220
|
|
10
|
+
autonomous/ai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
autonomous/ai/models/openai.py,sha256=npavtBRWaxZuO3EtdFK1pm64wporJcTb_JDdxhMyhPI,11732
|
|
12
|
+
autonomous/apis/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
|
|
13
|
+
autonomous/apis/version_control/GHOrganization.py,sha256=mi2livdsGurKiifbvuLwiFbdDzL77IlEfhwEa-tG77I,1155
|
|
14
|
+
autonomous/apis/version_control/GHRepo.py,sha256=hTFHMkxSbSlVELfh8S6mq6ijkIKPRQO-Q5775ZjRKD4,4622
|
|
15
|
+
autonomous/apis/version_control/GHVersionControl.py,sha256=VIhVRxe6gJgozFWyhyKIu4spgSJI-GChiVJudnSyggI,196
|
|
16
|
+
autonomous/apis/version_control/__init__.py,sha256=tP0bAWYl1RwBRi62HsIidmgyqHuSlCUqwGuKUKKRugc,117
|
|
17
|
+
autonomous/auth/__init__.py,sha256=IW5tQ8VYwHIbDfMYA0wYgx4PprwcjUWV4EoIJ8HTlMU,161
|
|
18
|
+
autonomous/auth/autoauth.py,sha256=6GFs8xikCvPYXZ29bbc5baf603QvnE8tZQIIrAfTziY,3624
|
|
19
|
+
autonomous/auth/github.py,sha256=dHf84bJdV9rXGcvRLzWCPW9CvuA-VEmqYi_QQFwd2kY,886
|
|
20
|
+
autonomous/auth/google.py,sha256=cHmqbyNEPTKipc3WkYcD1XPOyqcWEFW0Ks4qJYmGvPw,1049
|
|
21
|
+
autonomous/auth/user.py,sha256=t8R7KsHp-QK3B_OS5ERSnQ4P8Tnhjehhmdqp5gcKxuU,2702
|
|
22
|
+
autonomous/db/__init__.py,sha256=9frkXJrl_OUemUQteXCTPqC8ECyxjE91Gi2mgTq26Fw,1159
|
|
23
|
+
autonomous/db/common.py,sha256=BUN2x_XuQBRFcq54TGPx4yLMLJdgytdbIt07QWr4CSM,2551
|
|
24
|
+
autonomous/db/connection.py,sha256=IhfJ8H5SZ44z7ptEez3T8QUPk88en9s3y9eKIpnIfg4,17747
|
|
25
|
+
autonomous/db/context_managers.py,sha256=_nH2ajCL8Xy90AuB2rKaryR4iF8Q8ksU3Nei_mZj-DE,9918
|
|
26
|
+
autonomous/db/dereference.py,sha256=Q_LkFwG5Be8XFKuwgvOIMb87R1DpavFbCOV2HdJV56Q,12573
|
|
27
|
+
autonomous/db/document.py,sha256=PGbCbkx3Los4zOj0Da6YcLCv_rR-xXp_7X6qivjAsL4,44429
|
|
28
|
+
autonomous/db/errors.py,sha256=_QeCotid1kmr7_W0QyH6NUrwwYN9eced_yyyiop0Xlw,4108
|
|
29
|
+
autonomous/db/fields.py,sha256=S79EaZCD5WZM-z7Fo3u4LsK-Rx3J5t4wDJorSanJ2qQ,93727
|
|
30
|
+
autonomous/db/mongodb_support.py,sha256=u0X-zpqTIZZP8o2-IDyKRKHL8ALLhvW1VSGtK3fLyos,626
|
|
31
|
+
autonomous/db/pymongo_support.py,sha256=UEZ4RHAGb_t1nuMUAJXMNs0vdH3dutxAH5mwFCmG6jI,2951
|
|
32
|
+
autonomous/db/signals.py,sha256=BM-M4hh4SrTbV9bZVIEWTG8mxgKn9Lo2rC7owLJz4yQ,1791
|
|
33
|
+
autonomous/db/base/__init__.py,sha256=qbVw-SlbJxlWu8UoPLQcwyRQ7Oso0r3aUit6Jqpoz40,1026
|
|
34
|
+
autonomous/db/base/common.py,sha256=YjvDGwmn-QoRplL9Xx2q3eUXEetgo3YureIGxbR36Y8,1540
|
|
35
|
+
autonomous/db/base/datastructures.py,sha256=fcgWe2JsfzTK3jbku3Teh0Iwvn5U5EhCpyeh9xr8bZ0,15850
|
|
36
|
+
autonomous/db/base/document.py,sha256=OM7CeJFZbxha6yKMiMCrHOlTELfOXusqJ8i6FjdFd0c,46652
|
|
37
|
+
autonomous/db/base/fields.py,sha256=c_FO9mryhdqzv4NdM1TnEl4WDoopy46I9UF1L8MVFFw,29146
|
|
38
|
+
autonomous/db/base/metaclasses.py,sha256=GVvJYcCxaW1ltEqyH4oNvT_srckEXDSHOtHVU_TAN70,18138
|
|
39
|
+
autonomous/db/base/utils.py,sha256=MH4FuEwh-5IcIinwNTkyTs-PqQLyyiMctcYMsNP85qk,617
|
|
40
|
+
autonomous/db/queryset/__init__.py,sha256=XT3__0BJCvQIQj3S_Mp7mPxNBkfdvXkdw56cg2gc86o,756
|
|
41
|
+
autonomous/db/queryset/base.py,sha256=aTq4C3K_YP8H6eE_HHn82C8I81l8uw1w0EPmCzcS7HM,76077
|
|
42
|
+
autonomous/db/queryset/field_list.py,sha256=qY50kgMYzloZXrOXnWT0PS_fBJCoThSioRvW9-HmhYA,2964
|
|
43
|
+
autonomous/db/queryset/manager.py,sha256=fXu95TlGChdJWTRA4OnY_Ik25JzezJ2_qPqmH78xJsY,2238
|
|
44
|
+
autonomous/db/queryset/queryset.py,sha256=Xvt1q7Olij9STbJkHm6dKrUIrgyJeY_uwJOYE9WUZvk,5942
|
|
45
|
+
autonomous/db/queryset/transform.py,sha256=UhBdDxYR_bWH0ECnaSw9g9YMwgWRZtsRl_q6PkqO9eY,19615
|
|
46
|
+
autonomous/db/queryset/visitor.py,sha256=AN09lR6hWYUlKJC7G1sktvnWy5hrFnpoQhi58bOXbA4,5470
|
|
47
|
+
autonomous/model/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
48
|
+
autonomous/model/autoattr.py,sha256=JvPpENa-bSaRSk0s1I1y5eqrKEYX8MzZUUybZD6Guhs,2820
|
|
49
|
+
autonomous/model/automodel.py,sha256=UYaXkl27y6nuS9tS22OXiHfQRg7OFmoYjP5HK47cU3Q,6496
|
|
50
|
+
autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
|
+
autonomous/storage/imagestorage.py,sha256=xxMu9gXZ3nGU9xsXNmHtk_9RtrALZ2QlX5XsR4SL7xc,4589
|
|
52
|
+
autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
|
|
53
|
+
autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
|
|
54
|
+
autonomous/tasks/autotask.py,sha256=aK5iapDhgcAic3F5ZYMAhNKJkOepj8yWwbMizKDzUwQ,4153
|
|
55
|
+
autonomous/utils/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
|
|
56
|
+
autonomous_app-0.3.1.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
|
|
57
|
+
autonomous_app-0.3.1.dist-info/METADATA,sha256=ri137pRjUmGCpW_jZvwWycCQOb6wS5hzs7pZGnopCH8,4188
|
|
58
|
+
autonomous_app-0.3.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
|
59
|
+
autonomous_app-0.3.1.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
|
|
60
|
+
autonomous_app-0.3.1.dist-info/RECORD,,
|
autonomous/db/autodb.py
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
_summary_
|
|
3
|
-
|
|
4
|
-
_extended_summary_
|
|
5
|
-
|
|
6
|
-
:return: _description_
|
|
7
|
-
:rtype: _type_
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import glob
|
|
11
|
-
import os
|
|
12
|
-
import subprocess
|
|
13
|
-
import urllib.parse
|
|
14
|
-
from datetime import datetime
|
|
15
|
-
|
|
16
|
-
import pymongo
|
|
17
|
-
|
|
18
|
-
from autonomous import log
|
|
19
|
-
|
|
20
|
-
from .table import Table
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Database:
|
|
24
|
-
"""
|
|
25
|
-
_summary_
|
|
26
|
-
|
|
27
|
-
_extended_summary_
|
|
28
|
-
|
|
29
|
-
:return: _description_
|
|
30
|
-
:rtype: _type_
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
def __init__(
|
|
34
|
-
self,
|
|
35
|
-
host=os.getenv("DB_HOST", "db"),
|
|
36
|
-
port=os.getenv("DB_PORT", 27017),
|
|
37
|
-
password=os.getenv("DB_PASSWORD"),
|
|
38
|
-
username=os.getenv("DB_USERNAME"),
|
|
39
|
-
db=os.getenv("DB_DB"),
|
|
40
|
-
):
|
|
41
|
-
"""
|
|
42
|
-
create an interface for your database
|
|
43
|
-
"""
|
|
44
|
-
# log(self.username, self.password)
|
|
45
|
-
username = urllib.parse.quote_plus(str(username))
|
|
46
|
-
password = urllib.parse.quote_plus(str(password))
|
|
47
|
-
self.connect_str = f"mongodb://{username}:{password}@{host}:{port}"
|
|
48
|
-
# log(f"mongodb://{username}:{password}@{host}", port=int(port))
|
|
49
|
-
self.db = pymongo.MongoClient(
|
|
50
|
-
f"mongodb://{username}:{password}@{host}", port=int(port)
|
|
51
|
-
)[db]
|
|
52
|
-
self.tables = {}
|
|
53
|
-
|
|
54
|
-
def get_table(self, table="default", schema=None):
|
|
55
|
-
"""
|
|
56
|
-
opens the table from the file, which clears any changed data
|
|
57
|
-
"""
|
|
58
|
-
if not self.tables.get(table):
|
|
59
|
-
self.tables[table] = Table(table, schema, self.db)
|
|
60
|
-
return self.tables[table]
|
|
61
|
-
|
|
62
|
-
def dbdump(self, directory):
|
|
63
|
-
"""
|
|
64
|
-
dumps the database to a json file
|
|
65
|
-
"""
|
|
66
|
-
datetime_string = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
|
67
|
-
command_str = f'mongodump --uri="{self.connect_str}" --archive="{directory}/dbbackup-{datetime_string}.archive"'
|
|
68
|
-
result = subprocess.Popen(command_str, shell=True).wait()
|
|
69
|
-
log(result, command_str)
|
|
70
|
-
|
|
71
|
-
def dbload(self, directory):
|
|
72
|
-
"""
|
|
73
|
-
loads the database from a json file
|
|
74
|
-
"""
|
|
75
|
-
files = glob.glob(
|
|
76
|
-
f"{directory}/dbbackup-*.archive"
|
|
77
|
-
) # replace with your directory path
|
|
78
|
-
|
|
79
|
-
# Find the file with the most recent timestamp
|
|
80
|
-
latest_file = max(files, key=os.path.getctime)
|
|
81
|
-
log(latest_file)
|
|
82
|
-
command_str = (
|
|
83
|
-
f'mongorestore --uri="{self.connect_str}" --archive="{latest_file}"'
|
|
84
|
-
)
|
|
85
|
-
result = subprocess.Popen(command_str, shell=True).wait()
|
|
86
|
-
log(result, command_str)
|
autonomous/db/table.py
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
_summary_
|
|
3
|
-
|
|
4
|
-
_extended_summary_
|
|
5
|
-
|
|
6
|
-
:return: _description_
|
|
7
|
-
:rtype: _type_
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import json
|
|
11
|
-
import random
|
|
12
|
-
|
|
13
|
-
from bson.objectid import ObjectId
|
|
14
|
-
|
|
15
|
-
from autonomous import log
|
|
16
|
-
from autonomous.model.autoattribute import AutoAttribute
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class Table:
|
|
20
|
-
def __init__(self, name, attributes, db):
|
|
21
|
-
self._db = db[name]
|
|
22
|
-
self.name = name
|
|
23
|
-
# log(attributes)
|
|
24
|
-
self._rules = {}
|
|
25
|
-
|
|
26
|
-
for k, v in attributes.items():
|
|
27
|
-
if isinstance(v, AutoAttribute):
|
|
28
|
-
self._rules[k] = v
|
|
29
|
-
elif isinstance(v, str):
|
|
30
|
-
self._rules[k] = AutoAttribute("TEXT", default=v)
|
|
31
|
-
elif isinstance(v, (int, float)):
|
|
32
|
-
self._rules[k] = AutoAttribute("NUMERIC", default=v)
|
|
33
|
-
else:
|
|
34
|
-
self._rules[k] = None
|
|
35
|
-
self._index = self._get_index(f"idx:{name}")
|
|
36
|
-
|
|
37
|
-
def __str__(self):
|
|
38
|
-
return json.dumps(self.all(), indent=4)
|
|
39
|
-
|
|
40
|
-
def _get_index(self, name):
|
|
41
|
-
pass
|
|
42
|
-
|
|
43
|
-
def _validate(self, k, v):
|
|
44
|
-
# log(k, v, self._rules)
|
|
45
|
-
if rule := self._rules.get(k):
|
|
46
|
-
if rule.type == "NUMERIC":
|
|
47
|
-
if v:
|
|
48
|
-
try:
|
|
49
|
-
float(v)
|
|
50
|
-
except TypeError:
|
|
51
|
-
raise Exception(
|
|
52
|
-
f"VALIDATION ERROR: Invalid attribute value. Must be a number: {k}:{v}"
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
if rule.required:
|
|
56
|
-
try:
|
|
57
|
-
assert v is not None
|
|
58
|
-
except AssertionError:
|
|
59
|
-
raise Exception(
|
|
60
|
-
f"VALIDATION ERROR: Attribute Required. Must not be 'None': {k}:{v}"
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
def save(self, obj):
|
|
64
|
-
for k, v in obj.items():
|
|
65
|
-
try:
|
|
66
|
-
self._validate(k, v)
|
|
67
|
-
except Exception as e:
|
|
68
|
-
# log(e)
|
|
69
|
-
raise e
|
|
70
|
-
|
|
71
|
-
if obj_id := obj.get("_id"):
|
|
72
|
-
obj["_id"] = ObjectId(obj_id)
|
|
73
|
-
self._db.replace_one({"_id": obj["_id"]}, obj, True)
|
|
74
|
-
else:
|
|
75
|
-
obj.pop("_id", None)
|
|
76
|
-
obj["_id"] = self._db.insert_one(obj).inserted_id
|
|
77
|
-
return str(obj["_id"])
|
|
78
|
-
|
|
79
|
-
def count(self):
|
|
80
|
-
return self._db.count_documents({})
|
|
81
|
-
|
|
82
|
-
def delete(self, _id):
|
|
83
|
-
try:
|
|
84
|
-
return self._db.delete_one({"_id": ObjectId(_id)}).acknowledged
|
|
85
|
-
except Exception as e:
|
|
86
|
-
log(e)
|
|
87
|
-
|
|
88
|
-
def _convert_to_dot_notation(self, search_terms, fuzzy_search=False, prefix=""):
|
|
89
|
-
dot_notation = {}
|
|
90
|
-
for key, value in search_terms.items():
|
|
91
|
-
if isinstance(value, dict):
|
|
92
|
-
dot_notation.update(
|
|
93
|
-
self._convert_to_dot_notation(
|
|
94
|
-
value, fuzzy_search=fuzzy_search, prefix=f"{prefix}{key}."
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
else:
|
|
98
|
-
if fuzzy_search and isinstance(value, str):
|
|
99
|
-
dot_notation[f"{prefix}{key}"] = {"$regex": value, "$options": "i"}
|
|
100
|
-
else:
|
|
101
|
-
dot_notation[f"{prefix}{key}"] = value
|
|
102
|
-
return dot_notation
|
|
103
|
-
|
|
104
|
-
def find(self, **search_terms):
|
|
105
|
-
search_terms = self._convert_to_dot_notation(search_terms)
|
|
106
|
-
result = self._db.find_one(search_terms)
|
|
107
|
-
if result:
|
|
108
|
-
result["_id"] = str(result["_id"])
|
|
109
|
-
return result
|
|
110
|
-
|
|
111
|
-
def search(self, **search_terms):
|
|
112
|
-
fuzzy_search = search_terms.pop("_FUZZY_SEARCH", False)
|
|
113
|
-
search_terms = self._convert_to_dot_notation(
|
|
114
|
-
search_terms, fuzzy_search=fuzzy_search
|
|
115
|
-
)
|
|
116
|
-
result = self._db.find(search_terms) or []
|
|
117
|
-
|
|
118
|
-
objs = []
|
|
119
|
-
for o in result:
|
|
120
|
-
o["_id"] = str(o["_id"])
|
|
121
|
-
objs.append(o)
|
|
122
|
-
# log(search_terms, fuzzy_search, objs)
|
|
123
|
-
return objs
|
|
124
|
-
|
|
125
|
-
def get(self, _id):
|
|
126
|
-
try:
|
|
127
|
-
if o := self._db.find_one({"_id": ObjectId(_id)}):
|
|
128
|
-
o["_id"] = str(o["_id"])
|
|
129
|
-
except Exception as e:
|
|
130
|
-
return None
|
|
131
|
-
# log(e, f"Object '{_id}' not found in '{self.name}'")
|
|
132
|
-
return o
|
|
133
|
-
|
|
134
|
-
def all(self):
|
|
135
|
-
objs = []
|
|
136
|
-
for o in self._db.find():
|
|
137
|
-
o["_id"] = str(o["_id"])
|
|
138
|
-
objs.append(o)
|
|
139
|
-
return objs
|
|
140
|
-
|
|
141
|
-
def random(self):
|
|
142
|
-
keys = [o for o in self._db.find({}, projection=["_id"])]
|
|
143
|
-
# log(keys)
|
|
144
|
-
try:
|
|
145
|
-
key = random.choice(keys)
|
|
146
|
-
except Exception as e:
|
|
147
|
-
# log(e, f"Table '{self.name}' is empty.")
|
|
148
|
-
return None
|
|
149
|
-
else:
|
|
150
|
-
result = self.get(str(key["_id"]))
|
|
151
|
-
# log(result)
|
|
152
|
-
return result
|
|
153
|
-
|
|
154
|
-
def clear(self):
|
|
155
|
-
# breakpoint()
|
|
156
|
-
return self._db.drop()
|
autonomous/errors/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .danglingreferenceerror import DanglingReferenceError
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class AutoAttribute:
|
|
2
|
-
def __init__(
|
|
3
|
-
self, type, default=None, required=False, unique=False, primary_key=False
|
|
4
|
-
):
|
|
5
|
-
if type in [
|
|
6
|
-
"TEXT",
|
|
7
|
-
"NUMERIC",
|
|
8
|
-
"MODEL",
|
|
9
|
-
]:
|
|
10
|
-
self.type = type
|
|
11
|
-
else:
|
|
12
|
-
raise ValueError(f"Invalid type {type}")
|
|
13
|
-
|
|
14
|
-
self.default = default
|
|
15
|
-
self.required = required
|
|
16
|
-
self.unique = unique
|
|
17
|
-
self.primary_key = primary_key
|
|
18
|
-
|
|
19
|
-
def __repr__(self):
|
|
20
|
-
return f"<AutoAttribute {self.type} {self.default} {self.required} {self.unique} {self.primary_key}>"
|
autonomous/model/orm.py
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
from autonomous import log
|
|
4
|
-
from autonomous.db.autodb import Database
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ORM:
|
|
8
|
-
_database = Database()
|
|
9
|
-
|
|
10
|
-
def __init__(self, name, attributes):
|
|
11
|
-
self.table = self._database.get_table(table=name, schema=attributes)
|
|
12
|
-
self.name = name
|
|
13
|
-
|
|
14
|
-
def _replace_pk_with_id(self, data):
|
|
15
|
-
if isinstance(data, dict):
|
|
16
|
-
for key in list(data.keys()):
|
|
17
|
-
if key == "pk":
|
|
18
|
-
data["_id"] = data.pop("pk")
|
|
19
|
-
else:
|
|
20
|
-
self._replace_pk_with_id(data[key])
|
|
21
|
-
# breakpoint()
|
|
22
|
-
elif isinstance(data, list):
|
|
23
|
-
for item in data:
|
|
24
|
-
self._replace_pk_with_id(item)
|
|
25
|
-
|
|
26
|
-
def _replace_id_with_pk(self, data):
|
|
27
|
-
if isinstance(data, dict):
|
|
28
|
-
for key in list(data.keys()):
|
|
29
|
-
if key == "_id":
|
|
30
|
-
data["pk"] = data.pop("_id")
|
|
31
|
-
else:
|
|
32
|
-
self._replace_id_with_pk(data[key])
|
|
33
|
-
# breakpoint()
|
|
34
|
-
elif isinstance(data, list):
|
|
35
|
-
for item in data:
|
|
36
|
-
self._replace_id_with_pk(item)
|
|
37
|
-
|
|
38
|
-
def save(self, data):
|
|
39
|
-
self._replace_pk_with_id(data)
|
|
40
|
-
if result := self.table.save(data):
|
|
41
|
-
self._replace_id_with_pk(result)
|
|
42
|
-
return result
|
|
43
|
-
|
|
44
|
-
def get(self, pk):
|
|
45
|
-
pk = str(pk)
|
|
46
|
-
if result := self.table.get(pk):
|
|
47
|
-
self._replace_id_with_pk(result)
|
|
48
|
-
return result
|
|
49
|
-
|
|
50
|
-
def all(self):
|
|
51
|
-
if results := self.table.all():
|
|
52
|
-
self._replace_id_with_pk(results)
|
|
53
|
-
return results
|
|
54
|
-
|
|
55
|
-
def search(self, **kwargs):
|
|
56
|
-
self._replace_pk_with_id(kwargs)
|
|
57
|
-
if results := self.table.search(**kwargs):
|
|
58
|
-
self._replace_id_with_pk(results)
|
|
59
|
-
return results
|
|
60
|
-
|
|
61
|
-
def find(self, **kwargs):
|
|
62
|
-
# log(kwargs)
|
|
63
|
-
self._replace_pk_with_id(kwargs)
|
|
64
|
-
# log(kwargs)
|
|
65
|
-
if result := self.table.find(**kwargs):
|
|
66
|
-
self._replace_id_with_pk(result)
|
|
67
|
-
# log(result)
|
|
68
|
-
return result
|
|
69
|
-
|
|
70
|
-
def random(self):
|
|
71
|
-
if result := self.table.random():
|
|
72
|
-
self._replace_id_with_pk(result)
|
|
73
|
-
return result
|
|
74
|
-
|
|
75
|
-
def delete(self, pk):
|
|
76
|
-
pk = str(pk)
|
|
77
|
-
return self.table.delete(_id=pk)
|
|
78
|
-
|
|
79
|
-
def flush_table(self):
|
|
80
|
-
return self.table.clear()
|
|
81
|
-
|
|
82
|
-
def dbdump(self, directory="./dbbackups"):
|
|
83
|
-
return self._database.dbdump(directory)
|
|
84
|
-
|
|
85
|
-
def dbload(self, directory="./dbbackups"):
|
|
86
|
-
return self._database.dbload(directory)
|
autonomous/model/serializer.py
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# import traceback
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
|
|
4
|
-
from autonomous import log
|
|
5
|
-
from autonomous.errors import DanglingReferenceError
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class AutoEncoder:
|
|
9
|
-
@classmethod
|
|
10
|
-
def encode(cls, objs):
|
|
11
|
-
try:
|
|
12
|
-
if isinstance(objs, dict):
|
|
13
|
-
obj_copy = {k: cls.encode(v) for k, v in objs.items()}
|
|
14
|
-
elif isinstance(objs, list):
|
|
15
|
-
obj_copy = [cls.encode(v) for v in objs]
|
|
16
|
-
else:
|
|
17
|
-
obj_copy = cls().default(objs)
|
|
18
|
-
return obj_copy
|
|
19
|
-
except DanglingReferenceError as e:
|
|
20
|
-
log(e)
|
|
21
|
-
return None
|
|
22
|
-
|
|
23
|
-
def default(self, o):
|
|
24
|
-
from autonomous.model.automodel import AutoModel, DelayedModel
|
|
25
|
-
|
|
26
|
-
if issubclass(type(o), (AutoModel, DelayedModel)):
|
|
27
|
-
name = "AutoModel"
|
|
28
|
-
else:
|
|
29
|
-
name = type(o).__name__
|
|
30
|
-
|
|
31
|
-
encoder_name = f"encode_{name}"
|
|
32
|
-
|
|
33
|
-
try:
|
|
34
|
-
encoder = getattr(self, encoder_name)
|
|
35
|
-
except AttributeError:
|
|
36
|
-
return o
|
|
37
|
-
else:
|
|
38
|
-
encoded = {"__extended_json_type__": name, "value": encoder(o)}
|
|
39
|
-
|
|
40
|
-
return encoded
|
|
41
|
-
|
|
42
|
-
def encode_datetime(self, o):
|
|
43
|
-
return o.isoformat()
|
|
44
|
-
|
|
45
|
-
def encode_AutoModel(self, o):
|
|
46
|
-
if o.pk:
|
|
47
|
-
return {
|
|
48
|
-
"pk": o.pk,
|
|
49
|
-
"_automodel": o.model_name(qualified=True),
|
|
50
|
-
}
|
|
51
|
-
else:
|
|
52
|
-
log(
|
|
53
|
-
o,
|
|
54
|
-
"The above object was not been saved. You must save subobjects if you want them to persist.",
|
|
55
|
-
)
|
|
56
|
-
raise ValueError(f"Cannot encode unsaved {o.model_name(qualified=True)}")
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
class AutoDecoder:
|
|
60
|
-
@classmethod
|
|
61
|
-
def decode(cls, objs):
|
|
62
|
-
decoder = cls()
|
|
63
|
-
if isinstance(objs, dict):
|
|
64
|
-
if "__extended_json_type__" in objs:
|
|
65
|
-
objs = decoder.default(objs)
|
|
66
|
-
else:
|
|
67
|
-
for k, v in objs.items():
|
|
68
|
-
objs[k] = cls.decode(v)
|
|
69
|
-
elif isinstance(objs, list):
|
|
70
|
-
for i, v in enumerate(objs):
|
|
71
|
-
objs[i] = cls.decode(v)
|
|
72
|
-
return objs
|
|
73
|
-
|
|
74
|
-
def default(self, obj):
|
|
75
|
-
try:
|
|
76
|
-
name = obj["__extended_json_type__"]
|
|
77
|
-
decoder_name = f"decode_{name}"
|
|
78
|
-
decoder = getattr(self, decoder_name)
|
|
79
|
-
except (KeyError, AttributeError, TypeError) as e:
|
|
80
|
-
log(e)
|
|
81
|
-
return obj
|
|
82
|
-
else:
|
|
83
|
-
return decoder(obj)
|
|
84
|
-
|
|
85
|
-
def decode_datetime(self, o):
|
|
86
|
-
return datetime.fromisoformat(o["value"])
|
|
87
|
-
|
|
88
|
-
def decode_AutoModel(self, o):
|
|
89
|
-
obj = o["value"]
|
|
90
|
-
try:
|
|
91
|
-
from autonomous.model.automodel import DelayedModel
|
|
92
|
-
|
|
93
|
-
if not obj["pk"]:
|
|
94
|
-
raise KeyError
|
|
95
|
-
return DelayedModel(obj["_automodel"], obj["pk"])
|
|
96
|
-
except DanglingReferenceError as e:
|
|
97
|
-
# stack = traceback.extract_stack()
|
|
98
|
-
# function_names = [
|
|
99
|
-
# f"{frame.filename}:{frame.lineno} - {frame.name} "
|
|
100
|
-
# for frame in stack[:-1]
|
|
101
|
-
# if "__" not in frame.filename
|
|
102
|
-
# ]
|
|
103
|
-
# log(e, *function_names)
|
|
104
|
-
return None
|
|
105
|
-
except KeyError:
|
|
106
|
-
log(
|
|
107
|
-
"AutoModel",
|
|
108
|
-
"The above object was not been saved. You must save subobjects if you want them to persist.",
|
|
109
|
-
)
|
|
110
|
-
raise ValueError("Cannot decode unsaved AutoModel")
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
autonomous/__init__.py,sha256=Pa14MsIwcZt2j4Yx8BZsCMkrdkksmvUGFatPIZZ-Yuw,87
|
|
2
|
-
autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
|
|
3
|
-
autonomous/logger.py,sha256=jePQ4kTtECTwGtIcDmpLSE6rSwhaUEiQe2vK06h5XIg,1915
|
|
4
|
-
autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
autonomous/ai/oaiagent.py,sha256=orMbB9EaL84gdVkRdVaCY4Q1ybDS-FOisVEoa0KCNYI,7684
|
|
6
|
-
autonomous/auth/__init__.py,sha256=IW5tQ8VYwHIbDfMYA0wYgx4PprwcjUWV4EoIJ8HTlMU,161
|
|
7
|
-
autonomous/auth/autoauth.py,sha256=Q2DfcWjh0vTSSpf5SqyK4SElVDcxu8435GhLSPqTYco,3724
|
|
8
|
-
autonomous/auth/github.py,sha256=dHf84bJdV9rXGcvRLzWCPW9CvuA-VEmqYi_QQFwd2kY,886
|
|
9
|
-
autonomous/auth/google.py,sha256=cHmqbyNEPTKipc3WkYcD1XPOyqcWEFW0Ks4qJYmGvPw,1049
|
|
10
|
-
autonomous/auth/user.py,sha256=eDOIhGuWjzhyAxlZkt6lw74Ykxt2TluDanW17D-eZmc,2389
|
|
11
|
-
autonomous/db/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
12
|
-
autonomous/db/autodb.py,sha256=GifrahGJ2dAi8jQOiMIh0pgktcbuKt_1kAXIjKlKVZY,2376
|
|
13
|
-
autonomous/db/table.py,sha256=eigar6_jxAZxYoh3mzHH1__QNyuh11LFAzOTEzCBHzo,4660
|
|
14
|
-
autonomous/errors/__init__.py,sha256=OruWG9IkAF4LN-OAo5c2K9Dnds4oZFJJQHKaXbQaWnA,59
|
|
15
|
-
autonomous/errors/danglingreferenceerror.py,sha256=obfNjpn2vsyK4ak-UuuwFTMVzecs1SaeFPshOvnukS8,275
|
|
16
|
-
autonomous/model/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
17
|
-
autonomous/model/autoattribute.py,sha256=q09cORKC6-LpoZ3Ez-lRkd5kxuSFQrB2nA2f9_8k2c8,588
|
|
18
|
-
autonomous/model/automodel.py,sha256=k8S-083N1FEcBx578rEoMqBSlKg3lRrCbCxxNRbtqfY,12918
|
|
19
|
-
autonomous/model/orm.py,sha256=IJrbp15RmBgF61vLsqcS_VdnAnw9736sLW75_xFYE9Y,2521
|
|
20
|
-
autonomous/model/serializer.py,sha256=DBJMQRmNKQk5kQzh94anNMZYVajRCnFv7ATrZWp7vdg,3366
|
|
21
|
-
autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
-
autonomous/storage/imagestorage.py,sha256=azV594Z_v-wf3W8lUtgLIb5q5O5VrAtqE2kxGtSIUKA,6250
|
|
23
|
-
autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
|
|
24
|
-
autonomous/storage/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
|
|
25
|
-
autonomous/storage/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
|
|
26
|
-
autonomous/storage/version_control/GHOrganization.py,sha256=mi2livdsGurKiifbvuLwiFbdDzL77IlEfhwEa-tG77I,1155
|
|
27
|
-
autonomous/storage/version_control/GHRepo.py,sha256=hTFHMkxSbSlVELfh8S6mq6ijkIKPRQO-Q5775ZjRKD4,4622
|
|
28
|
-
autonomous/storage/version_control/GHVersionControl.py,sha256=VIhVRxe6gJgozFWyhyKIu4spgSJI-GChiVJudnSyggI,196
|
|
29
|
-
autonomous/storage/version_control/__init__.py,sha256=tP0bAWYl1RwBRi62HsIidmgyqHuSlCUqwGuKUKKRugc,117
|
|
30
|
-
autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
|
|
31
|
-
autonomous/tasks/autotask.py,sha256=_WQ8w1LyV2FVJ0Ct0FoF9q1W8ClXfS57-omnBb0LNWE,4910
|
|
32
|
-
autonomous_app-0.2.25.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
|
|
33
|
-
autonomous_app-0.2.25.dist-info/METADATA,sha256=1SQ3jDCcHQA7EEcXPAM7Az9QtuALhMxo80ghvkJGqJk,4228
|
|
34
|
-
autonomous_app-0.2.25.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
|
35
|
-
autonomous_app-0.2.25.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
|
|
36
|
-
autonomous_app-0.2.25.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|