Change CI to GitHub actions

Use copier template from oca/oca-addons-repo-template

Apply linting
This commit is contained in:
Yannick Payot
2023-05-24 18:22:55 +02:00
parent 05d111f7c1
commit d17d229b13
86 changed files with 1441 additions and 634 deletions
-1
View File
@@ -1,2 +1 @@
from . import models
+1 -1
View File
@@ -15,7 +15,7 @@
"logging_json",
"server_environment", # OCA/server-tools
],
"website": "https://www.camptocamp.com",
"website": "https://github.com/camptocamp/odoo-cloud-platform",
"data": [],
"installable": True,
}
-1
View File
@@ -1,2 +1 @@
from . import cloud_platform
+33 -42
View File
@@ -4,46 +4,39 @@
import logging
import os
import re
from collections import namedtuple
from .strtobool import strtobool
from odoo import api, models
from odoo.tools.config import config
from .strtobool import strtobool
_logger = logging.getLogger(__name__)
def is_true(strval):
return bool(strtobool(strval or '0'))
return bool(strtobool(strval or "0"))
PlatformConfig = namedtuple(
'PlatformConfig',
'filestore'
)
PlatformConfig = namedtuple("PlatformConfig", "filestore")
FilestoreKind = namedtuple(
'FilestoreKind',
['name', 'location']
)
FilestoreKind = namedtuple("FilestoreKind", ["name", "location"])
class CloudPlatform(models.AbstractModel):
_name = 'cloud.platform'
_description = 'cloud.platform'
_name = "cloud.platform"
_description = "cloud.platform"
@api.model
def _default_config(self):
return PlatformConfig(self._filestore_kinds()['db'])
return PlatformConfig(self._filestore_kinds()["db"])
@api.model
def _filestore_kinds(self):
return {
'db': FilestoreKind('db', 'local'),
'file': FilestoreKind('file', 'local'),
"db": FilestoreKind("db", "local"),
"file": FilestoreKind("file", "local"),
}
@api.model
@@ -53,33 +46,31 @@ class CloudPlatform(models.AbstractModel):
@api.model
def _config_by_server_env(self, platform_kind, environment):
configs_getter = getattr(
self,
'_config_by_server_env_for_%s' % platform_kind,
None
self, "_config_by_server_env_for_%s" % platform_kind, None
)
configs = configs_getter() if configs_getter else {}
return configs.get(environment) or self._default_config()
def _get_running_env(self):
environment_name = config['running_env']
if environment_name.startswith('labs'):
environment_name = config["running_env"]
if environment_name.startswith("labs"):
# We allow to have environments such as 'labs-logistics'
# or 'labs-finance', in order to have the matching ribbon.
environment_name = 'labs'
environment_name = "labs"
return environment_name
@api.model
def _install(self, platform_kind):
assert platform_kind in self._platform_kinds()
params = self.env['ir.config_parameter'].sudo()
params.set_param('cloud.platform.kind', platform_kind)
params = self.env["ir.config_parameter"].sudo()
params.set_param("cloud.platform.kind", platform_kind)
environment_name = self._get_running_env()
configs = self._config_by_server_env(platform_kind, environment_name)
params.set_param('ir_attachment.location', configs.filestore.name)
params.set_param("ir_attachment.location", configs.filestore.name)
self.check()
if configs.filestore.location == 'remote':
self.env['ir.attachment'].sudo().force_storage()
_logger.info('cloud platform configured for {}'.format(platform_kind))
if configs.filestore.location == "remote":
self.env["ir.attachment"].sudo().force_storage()
_logger.info("cloud platform configured for {}".format(platform_kind))
@api.model
def install(self):
@@ -91,39 +82,39 @@ class CloudPlatform(models.AbstractModel):
@api.model
def _check_redis(self, environment_name):
if environment_name in ('prod', 'integration', 'labs', 'test'):
assert is_true(os.environ.get('ODOO_SESSION_REDIS')), (
if environment_name in ("prod", "integration", "labs", "test"):
assert is_true(os.environ.get("ODOO_SESSION_REDIS")), (
"Redis must be activated on prod, integration, labs,"
" test instances. This is done by setting ODOO_SESSION_REDIS=1."
)
assert (os.environ.get('ODOO_SESSION_REDIS_HOST') or
os.environ.get('ODOO_SESSION_REDIS_SENTINEL_HOST') or
os.environ.get('ODOO_SESSION_REDIS_URL')), (
assert (
os.environ.get("ODOO_SESSION_REDIS_HOST")
or os.environ.get("ODOO_SESSION_REDIS_SENTINEL_HOST")
or os.environ.get("ODOO_SESSION_REDIS_URL")
), (
"ODOO_SESSION_REDIS_HOST or "
"ODOO_SESSION_REDIS_SENTINEL_HOST or "
"ODOO_SESSION_REDIS_URL "
"environment variable is required to connect on Redis"
)
assert os.environ.get('ODOO_SESSION_REDIS_PREFIX'), (
assert os.environ.get("ODOO_SESSION_REDIS_PREFIX"), (
"ODOO_SESSION_REDIS_PREFIX environment variable is required "
"to store sessions on Redis"
)
prefix = os.environ['ODOO_SESSION_REDIS_PREFIX']
assert re.match(r'^[a-z-0-9]+-odoo-[a-z-0-9]+$', prefix), (
prefix = os.environ["ODOO_SESSION_REDIS_PREFIX"]
assert re.match(r"^[a-z-0-9]+-odoo-[a-z-0-9]+$", prefix), (
"ODOO_SESSION_REDIS_PREFIX must match '<client>-odoo-<env>'"
", we got: '%s'" % (prefix,)
)
@api.model
def check(self):
if is_true(os.environ.get('ODOO_CLOUD_PLATFORM_UNSAFE')):
_logger.warning(
"cloud platform checks disabled, this is not safe"
)
if is_true(os.environ.get("ODOO_CLOUD_PLATFORM_UNSAFE")):
_logger.warning("cloud platform checks disabled, this is not safe")
return
params = self.env['ir.config_parameter'].sudo()
kind = params.get_param('cloud.platform.kind')
params = self.env["ir.config_parameter"].sudo()
kind = params.get_param("cloud.platform.kind")
if not kind:
_logger.warning(
"cloud platform not configured, you should "
+14 -14
View File
@@ -1,21 +1,21 @@
_MAP = {
'y': True,
'yes': True,
't': True,
'true': True,
'on': True,
'1': True,
'n': False,
'no': False,
'f': False,
'false': False,
'off': False,
'0': False
"y": True,
"yes": True,
"t": True,
"true": True,
"on": True,
"1": True,
"n": False,
"no": False,
"f": False,
"false": False,
"off": False,
"0": False,
}
def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError:
raise ValueError('"{}" is not a valid bool value'.format(value))
except KeyError as error:
raise ValueError('"{}" is not a valid bool value'.format(value)) from error
+1 -2
View File
@@ -1,3 +1,2 @@
def install(ctx):
ctx.env['cloud.platform'].install()
ctx.env["cloud.platform"].install()