From 429b8c535d2ac00b4fd90a6b3580282bf9873cfc Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Mon, 14 Jan 2019 18:20:17 +0000 Subject: [PATCH] publish muk_branding - 12.0 --- muk_branding/__manifest__.py | 2 +- muk_branding/tools/debrand.py | 187 +++++++++++++++++----------------- 2 files changed, 95 insertions(+), 94 deletions(-) diff --git a/muk_branding/__manifest__.py b/muk_branding/__manifest__.py index 1724ad6..a0b6fb5 100644 --- a/muk_branding/__manifest__.py +++ b/muk_branding/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Branding", "summary": """Branding Features""", - "version": "12.0.1.0.1", + "version": "12.0.1.0.2", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_branding/tools/debrand.py b/muk_branding/tools/debrand.py index bc441b0..b822334 100644 --- a/muk_branding/tools/debrand.py +++ b/muk_branding/tools/debrand.py @@ -1,93 +1,94 @@ -################################################################################### -# -# Copyright (C) 2018 MuK IT GmbH -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -################################################################################### - -import re -import uuid -import chardet - -from itertools import chain -from lxml.etree import tostring -from lxml.html import fromstring - -from odoo.tools import ustr - -from odoo.addons.muk_utils.tools.utils import safe_execute - -def debrand_documentation(text, value, expression): - text = re.sub( - r'https://www.{0}.com/documentation/'.format(expression), - '{0}/documentation/'.format(value), text, flags=re.IGNORECASE - ) - text = re.sub( - r'https://www.{0}.com/page/docs/'.format(expression), - '{0}/page/docs/'.format(value), text, flags=re.IGNORECASE - ) - return text - -def debrand_link(text, value, expression): - return re.sub( - r'\b{0}.com\b'.format(expression), - value, text, flags=re.IGNORECASE - ) - -def debrand_text(text, value, expression): - cases = { - expression: uuid.uuid4().hex, - expression.upper(): uuid.uuid4().hex, - expression.lower(): uuid.uuid4().hex, - expression.capitalize(): uuid.uuid4().hex, - } - def init_no_debranding(match): - text = match.group() - for key in cases: - text = re.sub(r'\b{0}\b'.format(key), cases[key], text) - return text - def post_no_debranding(text): - for key in cases: - text = text.replace(cases[key], key) - return text - if isinstance(value, dict): - text = safe_execute(text, debrand_documentation, text, value.get('documentation'), expression) - text = safe_execute(text, debrand_link, text, value.get('website'), expression) - text = re.sub( - r'<.*class=".*no_debranding.*".*>.*(\b{0}\b).*<.*>'.format(expression), - init_no_debranding, text, flags=re.IGNORECASE - ) - text = re.sub( - r'\b(?. +# +################################################################################### + +import re +import uuid +import chardet + +from itertools import chain +from lxml.etree import tostring +from lxml.html import fromstring + +from odoo.tools import ustr + +from odoo.addons.muk_utils.tools.utils import safe_execute + +def debrand_documentation(text, value, expression): + text = re.sub( + r'https://www.{0}.com/documentation/'.format(expression), + '{0}/documentation/'.format(value), text, flags=re.IGNORECASE + ) + text = re.sub( + r'https://www.{0}.com/page/docs/'.format(expression), + '{0}/page/docs/'.format(value), text, flags=re.IGNORECASE + ) + return text + +def debrand_link(text, value, expression): + text = re.sub( + r'(http(s)?:\/\/)?(www.)?{0}.com'.format(expression), + value, text, flags=re.IGNORECASE + ) + return text + +def debrand_text(text, value, expression): + cases = { + expression: uuid.uuid4().hex, + expression.upper(): uuid.uuid4().hex, + expression.lower(): uuid.uuid4().hex, + expression.capitalize(): uuid.uuid4().hex, + } + def init_no_debranding(match): + text = match.group() + for key in cases: + text = re.sub(r'\b{0}\b'.format(key), cases[key], text) + return text + def post_no_debranding(text): + for key in cases: + text = text.replace(cases[key], key) + return text + if isinstance(value, dict): + text = safe_execute(text, debrand_documentation, text, value.get('documentation'), expression) + text = safe_execute(text, debrand_link, text, value.get('website'), expression) + text = re.sub( + r'<.*class=".*no_debranding.*".*>.*(\b{0}\b).*<.*>'.format(expression), + init_no_debranding, text, flags=re.IGNORECASE + ) + text = re.sub( + r'\b(?