mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 01:52:07 +02:00
18.0 vanilla
This commit is contained in:
parent
d72e748793
commit
0a7ae8db93
337 changed files with 399651 additions and 232598 deletions
|
|
@ -0,0 +1,76 @@
|
|||
import re
|
||||
|
||||
|
||||
def upgrade(file_manager):
|
||||
""" Use double quote for redacted text and single quote for strings. """
|
||||
# Don't use this script in production, it is broken and only serve
|
||||
# as an example.
|
||||
|
||||
# List all the files that might need to be upgraded, here we list
|
||||
# all python models.
|
||||
files = [
|
||||
file for file in file_manager
|
||||
if 'models' in file.path.parts
|
||||
if file.path.suffix == '.py'
|
||||
if file.path.name != '__init__.py'
|
||||
]
|
||||
|
||||
# Early return if case there are no file, so we don't compile
|
||||
# regexps for nothing.
|
||||
if not files:
|
||||
return
|
||||
|
||||
# Python Regexp 101
|
||||
#
|
||||
# re.VERBOSE ignores all spaces inside the regexp so it is possible
|
||||
# to indent it, it also allows for comments at the end of each line.
|
||||
# to actually expect a space you have to escape it: "\ "
|
||||
#
|
||||
# a* vs a*? the first is greedy and the second is lazy, the first is
|
||||
# gonna match as most "a" as possible, the second will stop as soon
|
||||
# as possible. Lazy quantifiers are MUCH faster than greedy one.
|
||||
#
|
||||
# (?P<x>) it is your regular group, but you can access it via its
|
||||
# name "x": match = re.match(...); match.group('x'). Much better
|
||||
# than using numeric groups.
|
||||
#
|
||||
# (?:) it is a non-capturing group, for when you need a group inside
|
||||
# the regexp but you don't need to remember what was matched inside.
|
||||
# They are faster than regular (capturing) groups.
|
||||
|
||||
# Assume that all redacted text:
|
||||
# - Start with a upper case
|
||||
# - Have multiples words
|
||||
# - End with a dot
|
||||
# This assumption is wrong for many cases, don't use this script!
|
||||
redacted_text_re = re.compile(r"""
|
||||
' # Opening single quote
|
||||
(?P<text>
|
||||
[A-Z][^'\s]*?\ # First word
|
||||
(?:[^'\s]*?\ )* # All middle words
|
||||
[^'\s]*?\. # Final word
|
||||
)
|
||||
' # Closing single quote
|
||||
""", re.VERBOSE)
|
||||
|
||||
# Assume that all strings:
|
||||
# - Are fully lowercase
|
||||
# - Have a single word
|
||||
# - Have no ponctuation
|
||||
# This assumption is wrong for many cases, don't use this script!
|
||||
strings_re = re.compile(r'"(?P<string>[a-z]+)"')
|
||||
|
||||
# Iterate over all the files and run the regexps
|
||||
for fileno, file in enumerate(files, start=1):
|
||||
# load the content
|
||||
content = file.content
|
||||
|
||||
# do the operations
|
||||
content = redacted_text_re.sub(r'"\g<text>"', content)
|
||||
content = strings_re.sub(r"'\g<string>'", content)
|
||||
|
||||
# write back the file, if nothing changed nothing is written
|
||||
# file.content = content # uncomment this line to test the script
|
||||
|
||||
# have the progress bar to actually show the progression
|
||||
file_manager.print_progress(fileno, len(files))
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
import re
|
||||
|
||||
|
||||
def upgrade(file_manager):
|
||||
files = [file for file in file_manager if file.path.suffix in ('.xml', '.js', '.py')]
|
||||
if not files:
|
||||
return
|
||||
|
||||
reg_tree_to_list_xml_mode = re.compile(r"""(<field[^>]* name=["'](view_mode|name|binding_view_types)["'][^>]*>([^<>]+,)?\s*)tree(\s*(,[^<>]+)?</field>)""")
|
||||
reg_tree_to_list_tag = re.compile(r'(\n(?:[^:\n]|:(?!//))+)([<,/])tree([ \n\r,>/])')
|
||||
reg_tree_to_list_xpath = re.compile(r"""(<xpath[^>]* expr=['"])([^<>]*/)?tree(/|[\['"])""")
|
||||
reg_tree_to_list_ref = re.compile(r'tree_view_ref')
|
||||
reg_tree_to_list_mode = re.compile(r"""(mode=['"][^'"]*)tree([^'"]*['"])""")
|
||||
reg_tree_to_list_view_mode = re.compile(r"""(['"]view_mode['"][^'":=]*[:=].*['"]([^'"]+,)?\s*)tree(\s*(,[^'"]+)?['"])""")
|
||||
reg_tree_to_list_view = re.compile(r"""(['"]views['"][^'":]*[:=].*['"])tree(['"])""")
|
||||
reg_tree_to_list_string = re.compile(r"""([ '">)])tree( [vV]iews?[ '"<.)])""")
|
||||
reg_tree_to_list_String = re.compile(r"""([ '">)])Tree( [vV]iews?[ '"<.)])""")
|
||||
reg_tree_to_list_env_ref = re.compile(r"""(self\.env\.ref\(.*['"])tree(['"])""")
|
||||
|
||||
for fileno, file in enumerate(files, start=1):
|
||||
content = file.content
|
||||
content = content.replace(' tree view ', ' list view ')
|
||||
content = reg_tree_to_list_xml_mode.sub(r'\1list\4', content)
|
||||
content = reg_tree_to_list_tag.sub(r'\1\2list\3', content)
|
||||
content = reg_tree_to_list_xpath.sub(r'\1\2list\3', content)
|
||||
content = reg_tree_to_list_ref.sub('list_view_ref', content)
|
||||
content = reg_tree_to_list_mode.sub(r'\1list\2', content)
|
||||
content = reg_tree_to_list_view_mode.sub(r'\1list\3', content)
|
||||
content = reg_tree_to_list_view.sub(r'\1list\2', content)
|
||||
content = reg_tree_to_list_string.sub(r'\1list\2', content)
|
||||
content = reg_tree_to_list_String.sub(r'\1List\2', content)
|
||||
content = reg_tree_to_list_env_ref.sub(r'\1list\2', content)
|
||||
file.content = content
|
||||
|
||||
file_manager.print_progress(fileno, len(files))
|
||||
Loading…
Add table
Add a link
Reference in a new issue