lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -29,31 +29,37 @@ class BRN:
|
|||
def from_str(cls, string: str) -> BRN:
|
||||
parts = string.split(":")
|
||||
if len(parts) != 6 or parts[0].lower() != "brn" or not is_integer(parts[2]):
|
||||
raise TypeError(f"Expected a valid BRN but got {repr(string)} (invalid parts).")
|
||||
raise TypeError(
|
||||
f"Expected a valid BRN but got {repr(string)} (invalid parts)."
|
||||
)
|
||||
resource_parts = parts[5].split("/")
|
||||
if len(resource_parts) != 2:
|
||||
raise TypeError(f"Expected a valid BRN but got {repr(string)} (invalid resource parts).")
|
||||
raise TypeError(
|
||||
f"Expected a valid BRN but got {repr(string)} (invalid resource parts)."
|
||||
)
|
||||
return cls(
|
||||
global_namespace=parts[1],
|
||||
group_id=int(parts[2]),
|
||||
product=parts[3],
|
||||
provider=parts[4],
|
||||
resource_type=resource_parts[0],
|
||||
resource_id=resource_parts[1]
|
||||
resource_id=resource_parts[1],
|
||||
)
|
||||
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
return str(self) == str(other)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return ":".join([
|
||||
"brn",
|
||||
self.global_namespace,
|
||||
str(self.group_id),
|
||||
self.product,
|
||||
self.provider,
|
||||
f"{self.resource_type}/{self.resource_id}"
|
||||
])
|
||||
return ":".join(
|
||||
[
|
||||
"brn",
|
||||
self.global_namespace,
|
||||
str(self.group_id),
|
||||
self.product,
|
||||
self.provider,
|
||||
f"{self.resource_type}/{self.resource_id}",
|
||||
]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<BRN {str(self)}>"
|
||||
|
|
|
@ -9,18 +9,18 @@ from app.models.mirrors import StaticOrigin
|
|||
|
||||
|
||||
def create_static_origin(
|
||||
description: str,
|
||||
group_id: int,
|
||||
storage_cloud_account_id: int,
|
||||
source_cloud_account_id: int,
|
||||
source_project: str,
|
||||
auto_rotate: bool,
|
||||
matrix_homeserver: Optional[str],
|
||||
keanu_convene_path: Optional[str],
|
||||
keanu_convene_logo: Optional[FileStorage],
|
||||
keanu_convene_color: Optional[str],
|
||||
clean_insights_backend: Optional[Union[str, bool]],
|
||||
db_session_commit: bool = False,
|
||||
description: str,
|
||||
group_id: int,
|
||||
storage_cloud_account_id: int,
|
||||
source_cloud_account_id: int,
|
||||
source_project: str,
|
||||
auto_rotate: bool,
|
||||
matrix_homeserver: Optional[str],
|
||||
keanu_convene_path: Optional[str],
|
||||
keanu_convene_logo: Optional[FileStorage],
|
||||
keanu_convene_color: Optional[str],
|
||||
clean_insights_backend: Optional[Union[str, bool]],
|
||||
db_session_commit: bool = False,
|
||||
) -> StaticOrigin:
|
||||
"""
|
||||
Create a new static origin.
|
||||
|
@ -47,14 +47,18 @@ def create_static_origin(
|
|||
else:
|
||||
raise ValueError("group_id must be an int")
|
||||
if isinstance(storage_cloud_account_id, int):
|
||||
cloud_account = CloudAccount.query.filter(CloudAccount.id == storage_cloud_account_id).first()
|
||||
cloud_account = CloudAccount.query.filter(
|
||||
CloudAccount.id == storage_cloud_account_id
|
||||
).first()
|
||||
if cloud_account is None:
|
||||
raise ValueError("storage_cloud_account_id must match an existing provider")
|
||||
static_origin.storage_cloud_account_id = storage_cloud_account_id
|
||||
else:
|
||||
raise ValueError("storage_cloud_account_id must be an int")
|
||||
if isinstance(source_cloud_account_id, int):
|
||||
cloud_account = CloudAccount.query.filter(CloudAccount.id == source_cloud_account_id).first()
|
||||
cloud_account = CloudAccount.query.filter(
|
||||
CloudAccount.id == source_cloud_account_id
|
||||
).first()
|
||||
if cloud_account is None:
|
||||
raise ValueError("source_cloud_account_id must match an existing provider")
|
||||
static_origin.source_cloud_account_id = source_cloud_account_id
|
||||
|
@ -69,7 +73,7 @@ def create_static_origin(
|
|||
keanu_convene_logo,
|
||||
keanu_convene_color,
|
||||
clean_insights_backend,
|
||||
False
|
||||
False,
|
||||
)
|
||||
if db_session_commit:
|
||||
db.session.add(static_origin)
|
||||
|
|
|
@ -26,7 +26,9 @@ def is_integer(contender: Any) -> bool:
|
|||
return float(contender).is_integer()
|
||||
|
||||
|
||||
def thumbnail_uploaded_image(file: FileStorage, max_size: Tuple[int, int] = (256, 256)) -> bytes:
|
||||
def thumbnail_uploaded_image(
|
||||
file: FileStorage, max_size: Tuple[int, int] = (256, 256)
|
||||
) -> bytes:
|
||||
"""
|
||||
Process an uploaded image file into a resized image of a specific size.
|
||||
|
||||
|
@ -39,7 +41,9 @@ def thumbnail_uploaded_image(file: FileStorage, max_size: Tuple[int, int] = (256
|
|||
img = Image.open(file)
|
||||
img.thumbnail(max_size)
|
||||
byte_arr = BytesIO()
|
||||
img.save(byte_arr, format='PNG' if file.filename.lower().endswith('.png') else 'JPEG')
|
||||
img.save(
|
||||
byte_arr, format="PNG" if file.filename.lower().endswith(".png") else "JPEG"
|
||||
)
|
||||
return byte_arr.getvalue()
|
||||
|
||||
|
||||
|
@ -52,9 +56,11 @@ def create_data_uri(bytes_data: bytes, file_extension: str) -> str:
|
|||
:return: A data URI representing the image.
|
||||
"""
|
||||
# base64 encode
|
||||
encoded = base64.b64encode(bytes_data).decode('ascii')
|
||||
encoded = base64.b64encode(bytes_data).decode("ascii")
|
||||
# create data URI
|
||||
data_uri = "data:image/{};base64,{}".format('jpeg' if file_extension == 'jpg' else file_extension, encoded)
|
||||
data_uri = "data:image/{};base64,{}".format(
|
||||
"jpeg" if file_extension == "jpg" else file_extension, encoded
|
||||
)
|
||||
return data_uri
|
||||
|
||||
|
||||
|
@ -80,7 +86,7 @@ def normalize_color(color: str) -> str:
|
|||
return webcolors.name_to_hex(color) # type: ignore[no-any-return]
|
||||
except ValueError:
|
||||
pass
|
||||
if color.startswith('#'):
|
||||
if color.startswith("#"):
|
||||
color = color[1:].lower()
|
||||
if len(color) in [3, 6]:
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue