autonomous-app 0.2.21__py3-none-any.whl → 0.2.23__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.2.21"
1
+ __version__ = "0.2.23"
2
2
 
3
3
  from .logger import log
4
4
  from .model.automodel import AutoModel
@@ -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}"
@@ -108,10 +115,7 @@ class ImageStorage:
108
115
 
109
116
  def get_path(self, asset_id):
110
117
  if asset_id:
111
- asset_path = asset_id.replace(".", "/")
112
- if asset_path.endswith("/"):
113
- asset_path = asset_path[:-1]
114
- return os.path.join(self.base_path, f"{asset_path}")
118
+ return os.path.join(self.base_path, f"{asset_id}")
115
119
  else:
116
120
  return self.base_path
117
121
 
@@ -128,8 +132,45 @@ class ImageStorage:
128
132
  return imgs
129
133
 
130
134
  def remove(self, asset_id):
135
+ if not asset_id:
136
+ return False
137
+ file_path = self.get_path(asset_id)
138
+ if os.path.isdir(file_path):
139
+ print(f"Removing {file_path}")
140
+ # return shutil.rmtree(file_path, ignore_errors=True)
141
+ return False
142
+
143
+ def clear_cached(self, asset_id):
131
144
  file_path = self.get_path(asset_id)
132
145
  if os.path.isdir(file_path):
133
- shutil.rmtree(file_path)
134
- return True
146
+ for file in glob.glob(os.path.join(file_path, "*")):
147
+ if os.path.basename(file) != "orig.webp":
148
+ os.remove(file)
149
+ return False
150
+
151
+ def rotate(self, asset_id, amount=-90):
152
+ file_path = self.get_path(asset_id)
153
+ log(asset_id)
154
+ with Image.open(f"{file_path}/orig.webp") as img:
155
+ # Rotate the image 90 degrees
156
+ rotated_img = img.rotate(amount, expand=True)
157
+ # Save the rotated image
158
+ log(img, rotated_img)
159
+ # img = img.copy()
160
+ # img_byte_arr = io.BytesIO()
161
+ # img.save(img_byte_arr, )
162
+ self.clear_cached(asset_id)
163
+ rotated_img.save(f"{file_path}/orig.webp", format="WEBP")
164
+ return False
165
+
166
+ def flip(self, asset_id, flipx=True, flipy=True):
167
+ file_path = self.get_path(asset_id)
168
+ with Image.open(f"{file_path}/orig.webp") as img:
169
+ if flipx:
170
+ rotated_img = img.transpose(Image.FLIP_LEFT_RIGHT)
171
+ if flipy:
172
+ rotated_img = img.transpose(Image.FLIP_TOP_BOTTOM)
173
+ # Save the rotated image
174
+ rotated_img.save(f"{file_path}/orig.webp", format="WEBP")
175
+ self.clear_cached(asset_id)
135
176
  return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: autonomous-app
3
- Version: 0.2.21
3
+ Version: 0.2.23
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=LLciXStkOmC-MKc4bzVRr5CPdgPu0631mN7x2v30Z08,87
1
+ autonomous/__init__.py,sha256=ye9QZlO6j8ZNUNYXFl1tzzfFxNQpCCa3i527pQF1FrY,87
2
2
  autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
3
3
  autonomous/logger.py,sha256=jePQ4kTtECTwGtIcDmpLSE6rSwhaUEiQe2vK06h5XIg,1915
4
4
  autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -19,7 +19,7 @@ autonomous/model/automodel.py,sha256=-YXzE6Pacxao3bu6_ItivRxryd-YLbd-F9_TRaStIwk
19
19
  autonomous/model/orm.py,sha256=IJrbp15RmBgF61vLsqcS_VdnAnw9736sLW75_xFYE9Y,2521
20
20
  autonomous/model/serializer.py,sha256=ixJ5LZ0sicv49WIaPKSzNX0IFy0InlHYv9X-uG8Pi5Y,3048
21
21
  autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- autonomous/storage/imagestorage.py,sha256=RlZ6F4s7FGpcyzJq8IstN-CDhhSigEQjJL5L7OVCxUM,4671
22
+ autonomous/storage/imagestorage.py,sha256=azV594Z_v-wf3W8lUtgLIb5q5O5VrAtqE2kxGtSIUKA,6250
23
23
  autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
24
24
  autonomous/storage/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
25
25
  autonomous/storage/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
@@ -29,8 +29,8 @@ autonomous/storage/version_control/GHVersionControl.py,sha256=VIhVRxe6gJgozFWyhy
29
29
  autonomous/storage/version_control/__init__.py,sha256=tP0bAWYl1RwBRi62HsIidmgyqHuSlCUqwGuKUKKRugc,117
30
30
  autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
31
31
  autonomous/tasks/autotask.py,sha256=_WQ8w1LyV2FVJ0Ct0FoF9q1W8ClXfS57-omnBb0LNWE,4910
32
- autonomous_app-0.2.21.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
33
- autonomous_app-0.2.21.dist-info/METADATA,sha256=B6VcONmSN89dxeNtTnHxgNS-BgFHIjQ4W5GnvEbuhho,4229
34
- autonomous_app-0.2.21.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
35
- autonomous_app-0.2.21.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
36
- autonomous_app-0.2.21.dist-info/RECORD,,
32
+ autonomous_app-0.2.23.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
33
+ autonomous_app-0.2.23.dist-info/METADATA,sha256=d6iKy7LcXIZ_wNRczRNHY_aw2rE5zZBBQSDR6skBW0w,4229
34
+ autonomous_app-0.2.23.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
35
+ autonomous_app-0.2.23.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
36
+ autonomous_app-0.2.23.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5