Update the date format in the statefile
This commit is contained in:
parent
0e80937092
commit
145907a0df
2 changed files with 40 additions and 9 deletions
|
@ -26,7 +26,7 @@ class _Key():
|
||||||
UPPER_THRESHOLD = "upper_threshold"
|
UPPER_THRESHOLD = "upper_threshold"
|
||||||
|
|
||||||
# Removed
|
# Removed
|
||||||
OWNERS = "owners"
|
_OWNERS = "owners"
|
||||||
|
|
||||||
|
|
||||||
_SCHEMA = Schema(
|
_SCHEMA = Schema(
|
||||||
|
@ -54,7 +54,7 @@ _SCHEMA = Schema(
|
||||||
def _migrate_to_v1(d: dict):
|
def _migrate_to_v1(d: dict):
|
||||||
# Owners moved to History in v1
|
# Owners moved to History in v1
|
||||||
# Note: owners will be required to be re-added to the state.json
|
# Note: owners will be required to be re-added to the state.json
|
||||||
owners = d.pop(_Key.OWNERS)
|
owners = d.pop(_Key._OWNERS)
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Migration removed owners from config, these must be re-added to the state.json")
|
"Migration removed owners from config, these must be re-added to the state.json")
|
||||||
logger.warn("Owners: %s", owners)
|
logger.warn("Owners: %s", owners)
|
||||||
|
|
45
py/state.py
45
py/state.py
|
@ -13,18 +13,48 @@ logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
# Warning: Changing any of the below needs proper thought to ensure backwards compatibility
|
# Warning: Changing any of the below needs proper thought to ensure backwards compatibility
|
||||||
_VERSION = 1
|
_VERSION = 2
|
||||||
|
|
||||||
|
|
||||||
def _migrate_to_v1(d: dict):
|
def _migrate_to_v1(d: dict):
|
||||||
logger.info("Renaming %s to %s", _Key.MATCHEES, _Key.USERS)
|
"""v1 simply renamed matchees to users"""
|
||||||
d[_Key.USERS] = d[_Key.MATCHEES]
|
logger.info("Renaming %s to %s", _Key._MATCHEES, _Key.USERS)
|
||||||
del d[_Key.MATCHEES]
|
d[_Key.USERS] = d[_Key._MATCHEES]
|
||||||
|
del d[_Key._MATCHEES]
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_to_v2(d: dict):
|
||||||
|
"""v2 swapped the date over to a less silly format"""
|
||||||
|
logger.info("Fixing up date format from %s to %s",
|
||||||
|
_TIME_FORMAT_OLD, _TIME_FORMAT)
|
||||||
|
|
||||||
|
def old_to_new_ts(ts: str) -> str:
|
||||||
|
return datetime.strftime(datetime.strptime(ts, _TIME_FORMAT_OLD), _TIME_FORMAT)
|
||||||
|
|
||||||
|
# Adjust all the history keys
|
||||||
|
d[_Key.HISTORY] = {
|
||||||
|
old_to_new_ts(ts): entry
|
||||||
|
for ts, entry in d[_Key.HISTORY].items()
|
||||||
|
}
|
||||||
|
# Adjust all the user parts
|
||||||
|
for user in d[_Key.USERS].values():
|
||||||
|
# Update the match dates
|
||||||
|
matches = user.get(_Key.MATCHES, {})
|
||||||
|
for id, ts in matches.items():
|
||||||
|
matches[id] = old_to_new_ts(ts)
|
||||||
|
|
||||||
|
# Update any reactivation dates
|
||||||
|
channels = user.get(_Key.CHANNELS, {})
|
||||||
|
for id, channel in channels.items():
|
||||||
|
old_ts = channel.get(_Key.REACTIVATE, None)
|
||||||
|
if old_ts:
|
||||||
|
channel[_Key.REACTIVATE] = old_to_new_ts(old_ts)
|
||||||
|
|
||||||
|
|
||||||
# Set of migration functions to apply
|
# Set of migration functions to apply
|
||||||
_MIGRATIONS = [
|
_MIGRATIONS = [
|
||||||
_migrate_to_v1
|
_migrate_to_v1,
|
||||||
|
_migrate_to_v2
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,10 +78,11 @@ class _Key(str):
|
||||||
VERSION = "version"
|
VERSION = "version"
|
||||||
|
|
||||||
# Unused
|
# Unused
|
||||||
MATCHEES = "matchees"
|
_MATCHEES = "matchees"
|
||||||
|
|
||||||
|
|
||||||
_TIME_FORMAT = "%a %b %d %H:%M:%S %Y"
|
_TIME_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
|
||||||
|
_TIME_FORMAT_OLD = "%a %b %d %H:%M:%S %Y"
|
||||||
|
|
||||||
|
|
||||||
_SCHEMA = Schema(
|
_SCHEMA = Schema(
|
||||||
|
|
Loading…
Add table
Reference in a new issue