autonomous-app 0.3.1__py3-none-any.whl → 0.3.2__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 CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.3.01"
1
+ __version__ = "0.3.2"
2
2
 
3
3
  from dotenv import load_dotenv
4
4
 
@@ -103,7 +103,7 @@ class DictAttr(DictField):
103
103
  def __get__(self, instance, owner):
104
104
  # log(instance, owner)
105
105
  results = super().__get__(instance, owner) or {}
106
- log(self.name, self.field, owner, results)
106
+ # log(self.name, self.field, owner, results)
107
107
  for key, lazy_obj in results.items():
108
108
  try:
109
109
  if hasattr(lazy_obj, "fetch"):
@@ -137,7 +137,14 @@ class AutoModel(Document):
137
137
  Returns:
138
138
  list: A list of AutoModel instances that match the search criteria.
139
139
  """
140
- results = cls.objects(**kwargs)
140
+ new_kwargs = {}
141
+ for k, v in kwargs.items():
142
+ if isinstance(v, str):
143
+ new_k = f"{k}__icontains"
144
+ new_kwargs[new_k] = v
145
+ else:
146
+ new_kwargs[k] = v
147
+ results = cls.objects(**new_kwargs)
141
148
  if _order_by:
142
149
  results = results.order_by(*_order_by)
143
150
  if _limit:
@@ -1,3 +1,4 @@
1
+ import glob
1
2
  import io
2
3
  import os
3
4
  import shutil
@@ -14,6 +15,12 @@ class ImageStorage:
14
15
  def __init__(self, path="static/images"):
15
16
  self.base_path = path
16
17
 
18
+ def scan_storage(self, path=None):
19
+ for root, dirs, files in os.walk(path or self.base_path):
20
+ for file in files:
21
+ if file == "orig.webp":
22
+ yield os.path.join(root, file)
23
+
17
24
  @classmethod
18
25
  def _get_key(cls, folder="", pkey=None):
19
26
  if folder and not folder.endswith("/"):
@@ -68,10 +75,10 @@ class ImageStorage:
68
75
  if not asset_id:
69
76
  return ""
70
77
  original_path = f"{self.get_path(asset_id)}"
71
- # log(f"Getting image: {asset_id}.{size}", original_path)
78
+ # log(f"Getting image: {asset_id}", original_path)
72
79
  if not os.path.exists(original_path):
73
80
  log(f"Original image not found: {original_path}")
74
- return ""
81
+ return None
75
82
  file_path = f"{original_path}/{size}.webp"
76
83
  # log(file_path)
77
84
  result_url = f"/{file_path}"
@@ -104,10 +111,7 @@ class ImageStorage:
104
111
 
105
112
  def get_path(self, asset_id):
106
113
  if asset_id:
107
- asset_path = asset_id.replace(".", "/")
108
- if asset_path.endswith("/"):
109
- asset_path = asset_path[:-1]
110
- return os.path.join(self.base_path, f"{asset_path}")
114
+ return os.path.join(self.base_path, f"{asset_id}")
111
115
  else:
112
116
  return self.base_path
113
117
 
@@ -124,8 +128,45 @@ class ImageStorage:
124
128
  return imgs
125
129
 
126
130
  def remove(self, asset_id):
131
+ if not asset_id:
132
+ return False
133
+ file_path = self.get_path(asset_id)
134
+ if os.path.isdir(file_path):
135
+ print(f"Removing {file_path}")
136
+ # return shutil.rmtree(file_path, ignore_errors=True)
137
+ return False
138
+
139
+ def clear_cached(self, asset_id):
127
140
  file_path = self.get_path(asset_id)
128
141
  if os.path.isdir(file_path):
129
- shutil.rmtree(file_path)
130
- return True
142
+ for file in glob.glob(os.path.join(file_path, "*")):
143
+ if os.path.basename(file) != "orig.webp":
144
+ os.remove(file)
145
+ return False
146
+
147
+ def rotate(self, asset_id, amount=-90):
148
+ file_path = self.get_path(asset_id)
149
+ log(asset_id)
150
+ with Image.open(f"{file_path}/orig.webp") as img:
151
+ # Rotate the image 90 degrees
152
+ rotated_img = img.rotate(amount, expand=True)
153
+ # Save the rotated image
154
+ log(img, rotated_img)
155
+ # img = img.copy()
156
+ # img_byte_arr = io.BytesIO()
157
+ # img.save(img_byte_arr, )
158
+ self.clear_cached(asset_id)
159
+ rotated_img.save(f"{file_path}/orig.webp", format="WEBP")
160
+ return False
161
+
162
+ def flip(self, asset_id, flipx=True, flipy=True):
163
+ file_path = self.get_path(asset_id)
164
+ with Image.open(f"{file_path}/orig.webp") as img:
165
+ if flipx:
166
+ rotated_img = img.transpose(Image.FLIP_LEFT_RIGHT)
167
+ if flipy:
168
+ rotated_img = img.transpose(Image.FLIP_TOP_BOTTOM)
169
+ # Save the rotated image
170
+ rotated_img.save(f"{file_path}/orig.webp", format="WEBP")
171
+ self.clear_cached(asset_id)
131
172
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: autonomous-app
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Containerized application framework built on Flask with additional libraries and tools for rapid development of web applications.
5
5
  Author-email: Steven A Moore <samoore@binghamton.edu>
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- autonomous/__init__.py,sha256=4zG57y3yMritw2TPxGgITZCNAcpJp2ZELW1iO8Wrlp0,95
1
+ autonomous/__init__.py,sha256=TJNTgPMD07Z3ltWNePwHW4fyQJYMVB3rRHSozAPzp3M,94
2
2
  autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
3
3
  autonomous/logger.py,sha256=NQtgEaTWNAWfLSgqSP7ksXj1GpOuCgoUV711kSMm-WA,2022
4
4
  autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -45,16 +45,16 @@ autonomous/db/queryset/queryset.py,sha256=Xvt1q7Olij9STbJkHm6dKrUIrgyJeY_uwJOYE9
45
45
  autonomous/db/queryset/transform.py,sha256=UhBdDxYR_bWH0ECnaSw9g9YMwgWRZtsRl_q6PkqO9eY,19615
46
46
  autonomous/db/queryset/visitor.py,sha256=AN09lR6hWYUlKJC7G1sktvnWy5hrFnpoQhi58bOXbA4,5470
47
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
48
+ autonomous/model/autoattr.py,sha256=7yLhkohTxGseOYhOJ_oDT1QD56UWhHEVdXP5yEsBJZE,2822
49
+ autonomous/model/automodel.py,sha256=M1--MKjhVtRgfHt3cn9Xoi02LDclvwuzrqFmEIFK_jw,6727
50
50
  autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
- autonomous/storage/imagestorage.py,sha256=xxMu9gXZ3nGU9xsXNmHtk_9RtrALZ2QlX5XsR4SL7xc,4589
51
+ autonomous/storage/imagestorage.py,sha256=SmBjBNBlP1ZEjxdOnGVzCHZhbEhMKTUQC2TbpWbejDE,6168
52
52
  autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
53
53
  autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
54
54
  autonomous/tasks/autotask.py,sha256=aK5iapDhgcAic3F5ZYMAhNKJkOepj8yWwbMizKDzUwQ,4153
55
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,,
56
+ autonomous_app-0.3.2.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
57
+ autonomous_app-0.3.2.dist-info/METADATA,sha256=TF6N9I7lN931iI9Q0nnNvADd0eMRgy36IVSu97NVntg,4188
58
+ autonomous_app-0.3.2.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
59
+ autonomous_app-0.3.2.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
60
+ autonomous_app-0.3.2.dist-info/RECORD,,