mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[CI] Format code with Black
This commit is contained in:
parent
cddfafaa55
commit
9bf2b0b546
7 changed files with 63 additions and 23 deletions
|
@ -862,7 +862,9 @@ def app_manifest(app, with_screenshot=False):
|
||||||
if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp", "gif"):
|
if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp", "gif"):
|
||||||
with open(entry.path, "rb") as img_file:
|
with open(entry.path, "rb") as img_file:
|
||||||
data = base64.b64encode(img_file.read()).decode("utf-8")
|
data = base64.b64encode(img_file.read()).decode("utf-8")
|
||||||
manifest["screenshot"] = f"data:image/{ext};charset=utf-8;base64,{data}"
|
manifest[
|
||||||
|
"screenshot"
|
||||||
|
] = f"data:image/{ext};charset=utf-8;base64,{data}"
|
||||||
break
|
break
|
||||||
|
|
||||||
shutil.rmtree(extracted_app_folder)
|
shutil.rmtree(extracted_app_folder)
|
||||||
|
@ -2932,7 +2934,6 @@ def _notification_is_dismissed(name, settings):
|
||||||
|
|
||||||
|
|
||||||
def _filter_and_hydrate_notifications(notifications, current_version=None, data={}):
|
def _filter_and_hydrate_notifications(notifications, current_version=None, data={}):
|
||||||
|
|
||||||
def is_version_more_recent_than_current_version(name):
|
def is_version_more_recent_than_current_version(name):
|
||||||
# Boring code to handle the fact that "0.1 < 9999~ynh1" is False
|
# Boring code to handle the fact that "0.1 < 9999~ynh1" is False
|
||||||
|
|
||||||
|
|
|
@ -226,17 +226,26 @@ def _update_apps_catalog():
|
||||||
logos_to_download.append(logo_hash)
|
logos_to_download.append(logo_hash)
|
||||||
|
|
||||||
if len(logos_to_download) > 20:
|
if len(logos_to_download) > 20:
|
||||||
logger.info(f"(Will fetch {len(logos_to_download)} logos, this may take a couple minutes)")
|
logger.info(
|
||||||
|
f"(Will fetch {len(logos_to_download)} logos, this may take a couple minutes)"
|
||||||
|
)
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
|
|
||||||
def fetch_logo(logo_hash):
|
def fetch_logo(logo_hash):
|
||||||
try:
|
try:
|
||||||
r = requests.get(f"{apps_catalog['url']}/v{APPS_CATALOG_API_VERSION}/logos/{logo_hash}.png", timeout=10)
|
r = requests.get(
|
||||||
assert r.status_code == 200, f"Got status code {r.status_code}, expected 200"
|
f"{apps_catalog['url']}/v{APPS_CATALOG_API_VERSION}/logos/{logo_hash}.png",
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
r.status_code == 200
|
||||||
|
), f"Got status code {r.status_code}, expected 200"
|
||||||
if hashlib.sha256(r.content).hexdigest() != logo_hash:
|
if hashlib.sha256(r.content).hexdigest() != logo_hash:
|
||||||
raise Exception(f"Found inconsistent hash while downloading logo {logo_hash}")
|
raise Exception(
|
||||||
|
f"Found inconsistent hash while downloading logo {logo_hash}"
|
||||||
|
)
|
||||||
open(f"{APPS_CATALOG_LOGOS}/{logo_hash}.png", "wb").write(r.content)
|
open(f"{APPS_CATALOG_LOGOS}/{logo_hash}.png", "wb").write(r.content)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -1518,9 +1518,10 @@ class RestoreManager:
|
||||||
if manifest["packaging_format"] >= 2:
|
if manifest["packaging_format"] >= 2:
|
||||||
from yunohost.utils.resources import AppResourceManager
|
from yunohost.utils.resources import AppResourceManager
|
||||||
|
|
||||||
AppResourceManager(
|
AppResourceManager(app_instance_name, wanted=manifest, current={}).apply(
|
||||||
app_instance_name, wanted=manifest, current={}
|
rollback_and_raise_exception_if_failure=True,
|
||||||
).apply(rollback_and_raise_exception_if_failure=True, operation_logger=operation_logger)
|
operation_logger=operation_logger,
|
||||||
|
)
|
||||||
|
|
||||||
# Execute the app install script
|
# Execute the app install script
|
||||||
restore_failed = True
|
restore_failed = True
|
||||||
|
|
|
@ -32,7 +32,13 @@ logger = getActionLogger("yunohost.firewall")
|
||||||
|
|
||||||
|
|
||||||
def firewall_allow(
|
def firewall_allow(
|
||||||
protocol, port, ipv4_only=False, ipv6_only=False, no_upnp=False, no_reload=False, reload_only_if_change=False
|
protocol,
|
||||||
|
port,
|
||||||
|
ipv4_only=False,
|
||||||
|
ipv6_only=False,
|
||||||
|
no_upnp=False,
|
||||||
|
no_reload=False,
|
||||||
|
reload_only_if_change=False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Allow connections on a port
|
Allow connections on a port
|
||||||
|
@ -81,7 +87,9 @@ def firewall_allow(
|
||||||
else:
|
else:
|
||||||
ipv = "IPv%s" % i[3]
|
ipv = "IPv%s" % i[3]
|
||||||
if not reload_only_if_change:
|
if not reload_only_if_change:
|
||||||
logger.warning(m18n.n("port_already_opened", port=port, ip_version=ipv))
|
logger.warning(
|
||||||
|
m18n.n("port_already_opened", port=port, ip_version=ipv)
|
||||||
|
)
|
||||||
# Add port forwarding with UPnP
|
# Add port forwarding with UPnP
|
||||||
if not no_upnp and port not in firewall["uPnP"][p]:
|
if not no_upnp and port not in firewall["uPnP"][p]:
|
||||||
firewall["uPnP"][p].append(port)
|
firewall["uPnP"][p].append(port)
|
||||||
|
@ -98,7 +106,13 @@ def firewall_allow(
|
||||||
|
|
||||||
|
|
||||||
def firewall_disallow(
|
def firewall_disallow(
|
||||||
protocol, port, ipv4_only=False, ipv6_only=False, upnp_only=False, no_reload=False, reload_only_if_change=False
|
protocol,
|
||||||
|
port,
|
||||||
|
ipv4_only=False,
|
||||||
|
ipv6_only=False,
|
||||||
|
upnp_only=False,
|
||||||
|
no_reload=False,
|
||||||
|
reload_only_if_change=False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Disallow connections on a port
|
Disallow connections on a port
|
||||||
|
@ -154,7 +168,9 @@ def firewall_disallow(
|
||||||
else:
|
else:
|
||||||
ipv = "IPv%s" % i[3]
|
ipv = "IPv%s" % i[3]
|
||||||
if not reload_only_if_change:
|
if not reload_only_if_change:
|
||||||
logger.warning(m18n.n("port_already_closed", port=port, ip_version=ipv))
|
logger.warning(
|
||||||
|
m18n.n("port_already_closed", port=port, ip_version=ipv)
|
||||||
|
)
|
||||||
# Remove port forwarding with UPnP
|
# Remove port forwarding with UPnP
|
||||||
if upnp and port in firewall["uPnP"][p]:
|
if upnp and port in firewall["uPnP"][p]:
|
||||||
firewall["uPnP"][p].remove(port)
|
firewall["uPnP"][p].remove(port)
|
||||||
|
|
|
@ -1246,7 +1246,9 @@ def user_group_update(
|
||||||
new_attr_dict["objectClass"] = group["objectClass"] + ["mailGroup"]
|
new_attr_dict["objectClass"] = group["objectClass"] + ["mailGroup"]
|
||||||
if not new_attr_dict["mail"] and "mailGroup" in group["objectClass"]:
|
if not new_attr_dict["mail"] and "mailGroup" in group["objectClass"]:
|
||||||
new_attr_dict["objectClass"] = [
|
new_attr_dict["objectClass"] = [
|
||||||
c for c in group["objectClass"] if c != "mailGroup" and c != "mailAccount"
|
c
|
||||||
|
for c in group["objectClass"]
|
||||||
|
if c != "mailGroup" and c != "mailAccount"
|
||||||
]
|
]
|
||||||
|
|
||||||
if new_attr_dict:
|
if new_attr_dict:
|
||||||
|
|
|
@ -36,7 +36,6 @@ logger = getActionLogger("yunohost.app_resources")
|
||||||
|
|
||||||
|
|
||||||
class AppResourceManager:
|
class AppResourceManager:
|
||||||
|
|
||||||
def __init__(self, app: str, current: Dict, wanted: Dict):
|
def __init__(self, app: str, current: Dict, wanted: Dict):
|
||||||
|
|
||||||
self.app = app
|
self.app = app
|
||||||
|
@ -48,7 +47,9 @@ class AppResourceManager:
|
||||||
if "resources" not in self.wanted:
|
if "resources" not in self.wanted:
|
||||||
self.wanted["resources"] = {}
|
self.wanted["resources"] = {}
|
||||||
|
|
||||||
def apply(self, rollback_and_raise_exception_if_failure, operation_logger=None, **context):
|
def apply(
|
||||||
|
self, rollback_and_raise_exception_if_failure, operation_logger=None, **context
|
||||||
|
):
|
||||||
|
|
||||||
todos = list(self.compute_todos())
|
todos = list(self.compute_todos())
|
||||||
completed = []
|
completed = []
|
||||||
|
@ -104,9 +105,13 @@ class AppResourceManager:
|
||||||
|
|
||||||
if exception:
|
if exception:
|
||||||
if rollback_and_raise_exception_if_failure:
|
if rollback_and_raise_exception_if_failure:
|
||||||
logger.error(m18n.n("app_resource_failed", app=self.app, error=exception))
|
logger.error(
|
||||||
|
m18n.n("app_resource_failed", app=self.app, error=exception)
|
||||||
|
)
|
||||||
if operation_logger:
|
if operation_logger:
|
||||||
failure_message_with_debug_instructions = operation_logger.error(str(exception))
|
failure_message_with_debug_instructions = operation_logger.error(
|
||||||
|
str(exception)
|
||||||
|
)
|
||||||
raise YunohostError(
|
raise YunohostError(
|
||||||
failure_message_with_debug_instructions, raw_msg=True
|
failure_message_with_debug_instructions, raw_msg=True
|
||||||
)
|
)
|
||||||
|
@ -859,7 +864,9 @@ class PortsResource(AppResource):
|
||||||
|
|
||||||
if infos["fixed"]:
|
if infos["fixed"]:
|
||||||
if self._port_is_used(port_value):
|
if self._port_is_used(port_value):
|
||||||
raise YunohostValidationError(f"Port {port_value} is already used by another process or app.")
|
raise YunohostValidationError(
|
||||||
|
f"Port {port_value} is already used by another process or app."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
while self._port_is_used(port_value):
|
while self._port_is_used(port_value):
|
||||||
port_value += 1
|
port_value += 1
|
||||||
|
@ -869,7 +876,9 @@ class PortsResource(AppResource):
|
||||||
if infos["exposed"]:
|
if infos["exposed"]:
|
||||||
firewall_allow(infos["exposed"], port_value, reload_only_if_change=True)
|
firewall_allow(infos["exposed"], port_value, reload_only_if_change=True)
|
||||||
else:
|
else:
|
||||||
firewall_disallow(infos["exposed"], port_value, reload_only_if_change=True)
|
firewall_disallow(
|
||||||
|
infos["exposed"], port_value, reload_only_if_change=True
|
||||||
|
)
|
||||||
|
|
||||||
def deprovision(self, context: Dict = {}):
|
def deprovision(self, context: Dict = {}):
|
||||||
|
|
||||||
|
@ -880,7 +889,9 @@ class PortsResource(AppResource):
|
||||||
value = self.get_setting(setting_name)
|
value = self.get_setting(setting_name)
|
||||||
self.delete_setting(setting_name)
|
self.delete_setting(setting_name)
|
||||||
if value and str(value).strip():
|
if value and str(value).strip():
|
||||||
firewall_disallow(infos["exposed"], int(value), reload_only_if_change=True)
|
firewall_disallow(
|
||||||
|
infos["exposed"], int(value), reload_only_if_change=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DatabaseAppResource(AppResource):
|
class DatabaseAppResource(AppResource):
|
||||||
|
@ -934,7 +945,7 @@ class DatabaseAppResource(AppResource):
|
||||||
]:
|
]:
|
||||||
raise YunohostError(
|
raise YunohostError(
|
||||||
"Specifying the type of db ('mysql' or 'postgresql') is mandatory for db resources",
|
"Specifying the type of db ('mysql' or 'postgresql') is mandatory for db resources",
|
||||||
raw_msg=True
|
raw_msg=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Hack so that people can write type = "mysql/postgresql" in toml but it's loaded as dbtype
|
# Hack so that people can write type = "mysql/postgresql" in toml but it's loaded as dbtype
|
||||||
|
|
Loading…
Add table
Reference in a new issue