From f379f702135669066f3788f24cb1467483105a5b Mon Sep 17 00:00:00 2001 From: nEEtdo0d Date: Sat, 22 Jan 2022 18:01:49 -0500 Subject: [PATCH] Add: redirect_utils to comprise any redirection funcs for ConfigUpdater Add: redirect research blueprints for Guild/MedalShop from old to new format due to module updates --- module/config/config_updater.py | 5 ++- module/redirect_utils/shop_filter.py | 47 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 module/redirect_utils/shop_filter.py diff --git a/module/config/config_updater.py b/module/config/config_updater.py index 8dcd3b86c..a18daf3c4 100644 --- a/module/config/config_updater.py +++ b/module/config/config_updater.py @@ -6,6 +6,7 @@ from cached_property import cached_property from module.base.timer import timer from module.config.utils import * from module.logger import logger +from module.redirect_utils.shop_filter import bp_redirect CONFIG_IMPORT = ''' import datetime @@ -346,6 +347,8 @@ class ConfigUpdater: ('OpsiDaily.OpsiDaily.BuySupply', 'OpsiShop.Scheduler.Enable'), ('OpsiDaily.Scheduler.Enable', 'OpsiDaily.OpsiDaily.DoMission'), ('OpsiShop.Scheduler.Enable', 'OpsiShop.OpsiShop.BuySupply'), + ('ShopOnce.GuildShop.Filter', 'ShopOnce.GuildShop.Filter', bp_redirect), + ('ShopOnce.MedalShop.Filter', 'ShopOnce.MedalShop.Filter', bp_redirect), ] @cached_property @@ -442,7 +445,7 @@ class ConfigUpdater: if __name__ == '__main__': """ Process the whole config generation. - + task.yaml -+----------------> menu.json argument.yaml -+-> args.json ---> config_generated.py override.yaml -+ | diff --git a/module/redirect_utils/shop_filter.py b/module/redirect_utils/shop_filter.py new file mode 100644 index 000000000..1b9c2aa4f --- /dev/null +++ b/module/redirect_utils/shop_filter.py @@ -0,0 +1,47 @@ +import re + +FILTER_REGEX = re.compile( + '(pr|dr)' + + '([1-4]' + '|neptune|monarch|ibuki|izumo|roon|saintlouis' + '|seattle|georgia|kitakaze|azuma|friedrich' + '|gascogne|champagne|cheshire|drake|mainz|odin' + '|anchorage|hakuryu|agir|august|marcopolo)?' + + '(bp)', + flags=re.IGNORECASE) + +NAME_TO_SERIES = { + 'neptune': 1, 'monarch': 1, 'ibuki': 1, 'izumo': 1, 'roon': 1, 'saintlouis': 1, + 'seattle': 2, 'georgia': 2, 'kitakaze': 2, 'gascogne': 2, 'azuma': 2, 'friedrich': 2, + 'cheshire': 3, 'mainz': 3, 'odin': 3, 'champagne': 3, + 'anchorage': 4, 'august': 4, 'marcopolo': 4, 'agir': 4, 'hakuryu': 4, + '1': 1, '2': 2, '3': 3, '4': 4, +} + +def bp_redirect(value): + """ + Redirects shop filter old format for research blueprints + to new format + PRBP = PR; PR1BP = PRS1; PROdinBP = PROdin/PROdinS3 + likewise for DR variants + """ + matches = re.findall(FILTER_REGEX, value) + if not matches: + return value + + for match in matches: + flat = ''.join(match) + if match[1]: + if match[1].isnumeric(): + value = re.sub(flat, f'{match[0]}S{NAME_TO_SERIES[match[1].lower()]}', value) + else: + value = re.sub(flat, f'{match[0]}{match[1]}S{NAME_TO_SERIES[match[1].lower()]}', value) + else: + value = re.sub(flat, match[0], value) + + return value + +if __name__ == '__main__': + print(ship_bp_redirect('PlateGeneralT1 > DRAgirBP > CatT3 > PROdinBP > Chip > PR1BP > PRBP')) \ No newline at end of file