mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-23 00:24:09 +00:00
Added migration for config
This commit is contained in:
parent
065d67c90c
commit
cab2d86481
|
@ -1,5 +1,12 @@
|
|||
import json, sys, logging
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
global settings
|
||||
|
||||
|
||||
def load_settings():
|
||||
global settings
|
||||
try: # load settings
|
||||
with open("settings.json", encoding="utf8") as sfile:
|
||||
settings = json.load(sfile)
|
||||
|
@ -10,7 +17,6 @@ try: # load settings
|
|||
except FileNotFoundError:
|
||||
logging.critical("No config file could be found. Please make sure settings.json is in the directory.")
|
||||
sys.exit(1)
|
||||
|
||||
# Set the cooldown to 15 seconds if it's a wiki farm like Fandom or Gamepedia and the cooldown is even lower than that.
|
||||
# Look, it's unreasonable to have even higher refresh rate than that, seriously. Setting it even lower can cause issues
|
||||
# for all users of the script for high usage of farm's servers. So please, do not remove this code unless you absolutely
|
||||
|
@ -20,3 +26,8 @@ if any(("fandom.com" in settings["wiki_url"], "gamepedia.com" in settings["wiki_
|
|||
settings["cooldown"] = 15
|
||||
if settings["fandom_discussions"]["cooldown"] < 15:
|
||||
settings["fandom_discussions"]["cooldown"] = 15
|
||||
|
||||
|
||||
load_settings()
|
||||
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
from src.configloader import settings
|
||||
import logging
|
||||
|
||||
from src.migrations.utils import return_example_file
|
||||
|
||||
logger = logging.getLogger("rcgcdw.migrations.1.13.1.1")
|
||||
base_file = return_example_file()
|
||||
new_settings = settings.copy()
|
||||
|
||||
|
||||
def run():
|
||||
if "event_appearance" not in settings:
|
||||
try:
|
||||
settings["event_appearance"] = {}
|
||||
struct = settings['appearance']['embed']
|
||||
for key, value in struct.items():
|
||||
settings["event_appearance"][key] = value
|
||||
settings["event_appearance"][key]["emoji"] = base_file["event_appearance"]
|
||||
except KeyError:
|
||||
logger.error("Failed to migrate appearance embed.")
|
||||
else: # Don't do migrations
|
||||
return
|
||||
|
46
src/migrations/11311.py
Normal file
46
src/migrations/11311.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from src.configloader import settings, load_settings
|
||||
import logging
|
||||
import shutil
|
||||
import time
|
||||
import json
|
||||
import sys
|
||||
|
||||
from src.migrations.utils import return_example_file
|
||||
|
||||
logger = logging.getLogger("rcgcdw.migrations.1.13.1.1")
|
||||
base_file = return_example_file()
|
||||
new_settings = settings.copy()
|
||||
|
||||
def run():
|
||||
global base_file
|
||||
if "event_appearance" not in settings:
|
||||
logger.info("Running migration 1.13.1.1")
|
||||
if "event_appearance" not in base_file: # if local base file is outdated, download from repo
|
||||
base_file = return_example_file(force=True)
|
||||
try:
|
||||
struct = settings['appearance']['embed']
|
||||
new_settings["event_appearance"] = {}
|
||||
keys = []
|
||||
for key, value in struct.items():
|
||||
if key not in ("show_edit_changes", "show_footer", "embed_images"):
|
||||
new_settings["event_appearance"][key] = value
|
||||
try:
|
||||
new_settings["event_appearance"][key]["emoji"] = base_file["event_appearance"][key]["emoji"]
|
||||
except KeyError:
|
||||
new_settings["event_appearance"][key]["emoji"] = ""
|
||||
keys.append(key)
|
||||
for item in keys:
|
||||
del new_settings['appearance']['embed'][item]
|
||||
except KeyError:
|
||||
logger.exception("Failed to migrate appearance embed.")
|
||||
sys.exit(1)
|
||||
shutil.copy("settings.json", "settings.json.{}.bak".format(int(time.time())))
|
||||
with open("settings.json", "w") as new_write:
|
||||
new_write.write(json.dumps(new_settings, indent=4))
|
||||
load_settings()
|
||||
logger.info("Migration 1.13.1.1 has been successful.")
|
||||
else:
|
||||
logger.debug("Ignoring migration 1.13.1.1")
|
||||
|
||||
|
||||
run()
|
|
@ -0,0 +1 @@
|
|||
__all__ = ["11311"]
|
|
@ -5,8 +5,10 @@ import json
|
|||
discussion_logger = logging.getLogger("rcgcdw.migrations.utils")
|
||||
|
||||
|
||||
def return_example_file() -> dict:
|
||||
def return_example_file(force=False) -> dict:
|
||||
try:
|
||||
if force:
|
||||
raise FileNotFoundError
|
||||
with open('settings.json.example', 'r') as example_file:
|
||||
return json.loads(example_file.read())
|
||||
except FileNotFoundError:
|
||||
|
|
|
@ -46,7 +46,7 @@ TESTING = True if "--test" in sys.argv else False # debug mode, pipeline testin
|
|||
logging.config.dictConfig(settings["logging"])
|
||||
logger = logging.getLogger("rcgcdw")
|
||||
logger.debug("Current settings: {settings}".format(settings=settings))
|
||||
|
||||
from src.migrations import * # migrations after logging
|
||||
storage = datafile
|
||||
|
||||
# Remove previous data holding file if exists and limitfetch allows
|
||||
|
|
Loading…
Reference in a new issue