Improve setting migration method matching

Avoid executing a migrations for settings with similar but
shorter names.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-12-04 23:05:50 -04:00
parent 5070a4fcd6
commit aa3495ff18
4 changed files with 73 additions and 11 deletions
+14 -10
View File
@@ -5,6 +5,7 @@ import hashlib
from importlib import import_module
import logging
import os
import re
import sys
import yaml
@@ -122,12 +123,13 @@ class Namespace(object):
class NamespaceMigration(object):
@staticmethod
def get_method_name(setting):
return setting.global_name.lower()
def __init__(self, namespace):
self.namespace = namespace
def get_method_name(self, setting):
return setting.global_name.lower()
def get_method_name_full(self, setting, version):
return '{}_{}'.format(
self.get_method_name(setting=setting),
@@ -136,18 +138,20 @@ class NamespaceMigration(object):
def migrate(self, setting):
if self.namespace.get_config_version() != self.namespace.version:
method_name = self.get_method_name(setting=setting)
setting_method_name = NamespaceMigration.get_method_name(
setting=setting
)
# Get methods for this setting
setting_methods = [
method for method in dir(self) if method.startswith(
method_name
)
]
pattern = r'{}_\d{{4}}'.format(setting_method_name)
setting_methods = re.findall(
pattern=pattern, string='\n'.join(dir(self))
)
# Get order of execution of setting methods
versions = [
method.replace(
'{}_'.format(method_name), ''
'{}_'.format(setting_method_name), ''
) for method in setting_methods
]
try: