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"):
|
||||
with open(entry.path, "rb") as img_file:
|
||||
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
|
||||
|
||||
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 is_version_more_recent_than_current_version(name):
|
||||
# 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)
|
||||
|
||||
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
|
||||
from multiprocessing.pool import ThreadPool
|
||||
|
||||
def fetch_logo(logo_hash):
|
||||
try:
|
||||
r = requests.get(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"
|
||||
r = requests.get(
|
||||
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:
|
||||
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)
|
||||
return True
|
||||
except Exception as e:
|
||||
|
|
|
@ -1518,9 +1518,10 @@ class RestoreManager:
|
|||
if manifest["packaging_format"] >= 2:
|
||||
from yunohost.utils.resources import AppResourceManager
|
||||
|
||||
AppResourceManager(
|
||||
app_instance_name, wanted=manifest, current={}
|
||||
).apply(rollback_and_raise_exception_if_failure=True, operation_logger=operation_logger)
|
||||
AppResourceManager(app_instance_name, wanted=manifest, current={}).apply(
|
||||
rollback_and_raise_exception_if_failure=True,
|
||||
operation_logger=operation_logger,
|
||||
)
|
||||
|
||||
# Execute the app install script
|
||||
restore_failed = True
|
||||
|
|
|
@ -32,7 +32,13 @@ logger = getActionLogger("yunohost.firewall")
|
|||
|
||||
|
||||
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
|
||||
|
@ -81,7 +87,9 @@ def firewall_allow(
|
|||
else:
|
||||
ipv = "IPv%s" % i[3]
|
||||
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
|
||||
if not no_upnp and port not in firewall["uPnP"][p]:
|
||||
firewall["uPnP"][p].append(port)
|
||||
|
@ -98,7 +106,13 @@ def firewall_allow(
|
|||
|
||||
|
||||
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
|
||||
|
@ -154,7 +168,9 @@ def firewall_disallow(
|
|||
else:
|
||||
ipv = "IPv%s" % i[3]
|
||||
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
|
||||
if upnp and port in firewall["uPnP"][p]:
|
||||
firewall["uPnP"][p].remove(port)
|
||||
|
|
|
@ -173,7 +173,7 @@ def test_app_config_bind_on_file(config_app):
|
|||
assert app_setting(config_app, "arg5") == "Foo Bar"
|
||||
|
||||
|
||||
#def test_app_config_custom_get(config_app):
|
||||
# def test_app_config_custom_get(config_app):
|
||||
#
|
||||
# assert app_setting(config_app, "arg9") is None
|
||||
# assert (
|
||||
|
|
|
@ -1246,7 +1246,9 @@ def user_group_update(
|
|||
new_attr_dict["objectClass"] = group["objectClass"] + ["mailGroup"]
|
||||
if not new_attr_dict["mail"] and "mailGroup" in group["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:
|
||||
|
|
|
@ -36,7 +36,6 @@ logger = getActionLogger("yunohost.app_resources")
|
|||
|
||||
|
||||
class AppResourceManager:
|
||||
|
||||
def __init__(self, app: str, current: Dict, wanted: Dict):
|
||||
|
||||
self.app = app
|
||||
|
@ -48,7 +47,9 @@ class AppResourceManager:
|
|||
if "resources" not in self.wanted:
|
||||
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())
|
||||
completed = []
|
||||
|
@ -104,9 +105,13 @@ class AppResourceManager:
|
|||
|
||||
if exception:
|
||||
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:
|
||||
failure_message_with_debug_instructions = operation_logger.error(str(exception))
|
||||
failure_message_with_debug_instructions = operation_logger.error(
|
||||
str(exception)
|
||||
)
|
||||
raise YunohostError(
|
||||
failure_message_with_debug_instructions, raw_msg=True
|
||||
)
|
||||
|
@ -859,7 +864,9 @@ class PortsResource(AppResource):
|
|||
|
||||
if infos["fixed"]:
|
||||
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:
|
||||
while self._port_is_used(port_value):
|
||||
port_value += 1
|
||||
|
@ -869,7 +876,9 @@ class PortsResource(AppResource):
|
|||
if infos["exposed"]:
|
||||
firewall_allow(infos["exposed"], port_value, reload_only_if_change=True)
|
||||
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 = {}):
|
||||
|
||||
|
@ -880,7 +889,9 @@ class PortsResource(AppResource):
|
|||
value = self.get_setting(setting_name)
|
||||
self.delete_setting(setting_name)
|
||||
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):
|
||||
|
@ -934,7 +945,7 @@ class DatabaseAppResource(AppResource):
|
|||
]:
|
||||
raise YunohostError(
|
||||
"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
|
||||
|
|
Loading…
Add table
Reference in a new issue