Skip to content

Commit d29bd20

Browse files
Refactor application tag references to name
- Updated `clear_test_apps.py` to check for '_test' in app name instead of tag. - Fixed import order in `squarecloud/__init__.py`. - Modified `squarecloud/app.py` to replace 'tag' with 'name' and removed 'isWebsite'. - Updated CLI tables in `squarecloud/cli/app.py` and `squarecloud/cli/main.py` to display app name. - Adjusted `Client` class in `squarecloud/client.py` for consistency in handling 'lang' and 'name' fields. - Revised data classes in `squarecloud/data.py` to use 'name' instead of 'tag' and removed 'isWebsite'. - Corrected file info class in `squarecloud/data.py` to set a default size of 0.0. - Updated listener manager in `squarecloud/listeners/capture_listener.py` to reference app name.
1 parent a8a8cc4 commit d29bd20

File tree

8 files changed

+60
-50
lines changed

8 files changed

+60
-50
lines changed

scripts/clear_test_apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
@run_async_script
1313
async def delete_test_apps():
1414
for app in await client.all_apps():
15-
if '_test' in app.tag:
15+
if '_test' in app.name:
1616
await app.delete()
17-
print(f'\U0001F5D1 Deleted app {app.tag}, with id {app.id}...')
17+
print(f'\U0001F5D1 Deleted app {app.name}, with id {app.id}...')
1818

1919

2020
if __name__ == '__main__':

squarecloud/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
from . import errors, utils
4-
from .client import Client
54
from .app import Application
5+
from .client import Client
66
from .data import (
77
AppData,
88
BackupData,

squarecloud/app.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ class Application(CaptureListenerManager):
152152
'_data',
153153
'cache',
154154
'_id',
155-
'_tag',
155+
'_name',
156156
'_desc',
157+
'_domain',
158+
'_custom',
157159
'_ram',
158160
'_lang',
159161
'_cluster',
160-
'_isWebsite',
161162
'always_avoid_listeners',
162163
]
163164

@@ -166,11 +167,12 @@ def __init__(
166167
client: 'Client',
167168
http: HTTPClient,
168169
id: str,
169-
tag: str,
170+
name: str,
170171
ram: PositiveInt,
171172
lang: str,
172173
cluster: str,
173-
isWebsite: bool,
174+
domain: str | None,
175+
custom: str | None,
174176
desc: str | None = None,
175177
) -> None:
176178
"""
@@ -184,22 +186,24 @@ def __init__(
184186
this app.
185187
:param http: Store a reference to the HTTPClient
186188
:param id: The application id
187-
:param tag: The tag of the app
189+
:param name: The tag of the app
188190
:param ram: The amount of ram that is allocated
189191
:param lang: The programming language of the app
190192
:param cluster: The cluster that the app is hosted on
191-
:param isWebsite: Whether if the app is a website
192193
:param desc: Define the description of the app
194+
:param domain: Define the domain of the app
195+
:param custom: Define the custom domain of the app
193196
194197
:return: None
195198
"""
196199
self._id: str = id
197-
self._tag: str = tag
200+
self._name: str = name
201+
self._domain: str | None = domain
202+
self._custom: str | None = custom
198203
self._desc: str | None = desc
199204
self._ram: PositiveInt = ram
200205
self._lang: str = lang
201206
self._cluster: str = cluster
202-
self._isWebsite: bool = isWebsite
203207
self._client: 'Client' = client
204208
self._http: HTTPClient = http
205209
self._listener: CaptureListenerManager = CaptureListenerManager()
@@ -243,14 +247,14 @@ def id(self) -> str:
243247
return self._id
244248

245249
@property
246-
def tag(self) -> str:
250+
def name(self) -> str:
247251
"""
248252
The tag function is a property that returns the application tag.
249253
250254
:return: The tag of the application
251255
:rtype: str
252256
"""
253-
return self._tag
257+
return self._name
254258

255259
@property
256260
def desc(self) -> str | None:
@@ -275,9 +279,7 @@ def ram(self) -> int:
275279
return self._ram
276280

277281
@property
278-
def lang(
279-
self,
280-
) -> str:
282+
def lang(self) -> str:
281283
"""
282284
The lang function is a property that returns the application's
283285
programing language.
@@ -288,9 +290,7 @@ def lang(
288290
return self._lang
289291

290292
@property
291-
def cluster(
292-
self,
293-
) -> str:
293+
def cluster(self) -> str:
294294
"""
295295
The cluster function is a property that returns the
296296
cluster that the application is
@@ -303,15 +303,28 @@ def cluster(
303303
return self._cluster
304304

305305
@property
306-
def is_website(self) -> bool:
306+
def domain(self) -> str | None:
307+
"""
308+
The domain function is a property that returns the
309+
application's domain.
310+
311+
312+
:return: The application's domain
313+
:rtype: str | None
307314
"""
308-
The is_website function is a property that returns a boolean value
309-
indicating whether th application is a website.
315+
return self._domain
310316

311-
:return: A boolean value, true or false
312-
:rtype: bool
317+
@property
318+
def custom(self) -> str | None:
319+
"""
320+
The custom function is a property that returns the
321+
application's custom domain.
322+
323+
324+
:return: The application's domain
325+
:rtype: str | None
313326
"""
314-
return self._isWebsite
327+
return self._custom
315328

316329
@staticmethod
317330
def _notify_listener(endpoint: Endpoint):

squarecloud/cli/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ async def app_group(ctx: Context, app_id: str, token: str):
5353
with Console().status('loading'):
5454
app = await client.app(app_id)
5555
table = Table(title=app.tag, header_style='purple')
56-
table.add_column('Tag', justify='center')
56+
table.add_column('Name', justify='center')
5757
table.add_column('ID', justify='center')
5858
table.add_column('RAM', justify='center')
5959
table.add_column('Language', justify='center')
6060
table.add_column('Description', justify='center')
61-
table.add_column('Is Website', justify='center')
6261
table.add_column('Cluster', justify='center')
6362

6463
table.add_row(
@@ -128,7 +127,7 @@ async def app_list(ctx: Context, token: str):
128127
return
129128
table = Table(title='App List', header_style='purple')
130129

131-
table.add_column('Tag', justify='center')
130+
table.add_column('Name', justify='center')
132131
table.add_column('ID', justify='center')
133132
table.add_column('RAM', justify='center')
134133
table.add_column('Language', justify='center')

squarecloud/cli/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def create_config(
127127
default='Y',
128128
)
129129
if r:
130-
path = prompt(
131-
'where do you want to save the file', default='.'
132-
)
130+
path = prompt('where do you want to save the file', default='.')
133131
config_file.save(path)
134132
print(
135133
Panel(

squarecloud/client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ async def app(self, app_id: str, **_kwargs) -> Application:
412412
if not app_data:
413413
raise ApplicationNotFound(app_id=app_id)
414414
app_data = app_data.pop()
415+
app_data['language'] = app_data.pop('lang')
416+
app_data = AppData(**app_data).to_dict()
417+
app_data['lang'] = app_data.pop('language')
415418
return Application(client=self, http=self._http, **app_data)
416419

417420
@_notify_listener(Endpoint.user())
@@ -433,10 +436,12 @@ async def all_apps(self, **_kwargs) -> list[Application]:
433436
response: Response = await self._http.fetch_user_info()
434437
payload = response.response
435438
apps_data: list = payload['applications']
436-
apps: list[Application] = [
437-
Application(client=self, http=self._http, **data)
438-
for data in apps_data
439-
]
439+
apps: list[Application] = []
440+
for data in apps_data:
441+
data['language'] = data.pop('lang')
442+
data = AppData(**data).to_dict()
443+
data['lang'] = data.pop('language')
444+
apps.append(Application(client=self, http=self._http, **data))
440445
return apps
441446

442447
@_notify_listener(Endpoint.upload())

squarecloud/data.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from datetime import datetime
4-
from typing import Any, Dict, Literal
4+
from typing import Any, Dict, Literal, Optional
55

66
from pydantic import confloat, conint
77
from pydantic.dataclasses import dataclass
@@ -88,15 +88,12 @@ class AppData:
8888
:ivar cluster: The cluster that the app is hosted on
8989
:ivar ram: The amount of RAM that application is using
9090
:ivar language The programming language of the app.:
91-
:ivar isWebsite: Whether if the app is a website
9291
9392
:type id: str
9493
:type name: str
9594
:type cluster: str
9695
:type ram: confloat(ge=0);
9796
:type language: Language
98-
:type isWebsite: bool
99-
:type gitIntegration: bool
10097
:type domain: str | None = None
10198
:type custom: str | None = None
10299
:type desc: str | None = None
@@ -106,10 +103,8 @@ class AppData:
106103
name: str
107104
cluster: str
108105
ram: confloat(ge=0)
109-
language: str
106+
language: Optional[str]
110107
cluster: str
111-
isWebsite: bool
112-
gitIntegration: bool
113108
domain: str | None = None
114109
custom: str | None = None
115110
desc: str | None = None
@@ -124,18 +119,18 @@ class UserData:
124119
User data class
125120
126121
:ivar id: User ID;
127-
:ivar tag: Username
122+
:ivar name: Username
128123
:ivar plan: User plan
129124
:ivar email: User email
130125
131126
:type id: conint(ge=0)
132-
:type tag: str
127+
:type name: str
133128
:type plan: PlanData
134129
:type email: str | None = None
135130
"""
136131

137132
id: conint(ge=0)
138-
tag: str
133+
name: str
139134
plan: PlanData
140135
email: str | None = None
141136

@@ -223,15 +218,15 @@ class UploadData:
223218
Upload data class
224219
225220
:ivar id: ID of the uploaded application
226-
:ivar tag: Tag of the uploaded application
221+
:ivar name: Tag of the uploaded application
227222
:ivar language: Programming language of the uploaded application
228223
:ivar ram: Ram allocated for the uploaded application
229224
:ivar cpu: Cpu of the uploaded application
230225
:ivar description: Description of the uploaded application
231226
:ivar subdomain: Subdomain of the uploaded application (only in websites)
232227
233228
:type id: str
234-
:type tag: str
229+
:type name: str
235230
:type language: Language
236231
:type ram: confloat(ge=0)
237232
:type cpu: confloat(ge=0)
@@ -240,7 +235,7 @@ class UploadData:
240235
"""
241236

242237
id: str
243-
tag: str
238+
name: str
244239
language: Language
245240
ram: confloat(ge=0)
246241
cpu: confloat(ge=0)
@@ -272,9 +267,9 @@ class FileInfo:
272267
app_id: str
273268
type: Literal['file', 'directory']
274269
name: str
275-
size: confloat(ge=0)
276270
lastModified: conint(ge=0) | float
277271
path: str
272+
size: confloat(ge=0.0) = 0.0
278273

279274
def to_dict(self):
280275
return self.__dict__.copy()

squarecloud/listeners/capture_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def filter_annotations(annotations: list[Any]) -> Any:
9494
kwargs['extra'] = extra
9595
info_msg: str = (
9696
f'ENDPOINT: {listener.endpoint}\n'
97-
f'APP-TAG: {listener.app.tag}\n'
97+
f'APP-TAG: {listener.app.name}\n'
9898
f'APP-ID: {listener.app.id}'
9999
)
100100
if extra:

0 commit comments

Comments
 (0)