2019-12-08 22:43:49 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
|
class Model:
|
|
|
|
"""
|
|
|
|
Object representing a parsed Model String.
|
|
|
|
"""
|
|
|
|
|
2021-08-19 21:20:31 +02:00
|
|
|
def __init__(self, gamecode: str, dest: str, spec: str, rev: str, version: Optional[int]) -> None:
|
2019-12-08 22:43:49 +01:00
|
|
|
"""
|
|
|
|
Initialize a Model object.
|
|
|
|
|
|
|
|
Parameters:
|
2021-08-19 21:20:31 +02:00
|
|
|
gamecode - Game code (such as LDJ)
|
2019-12-08 22:43:49 +01:00
|
|
|
dest - Destination region for the game (such as J)
|
|
|
|
spec - Spec for the game (such as A)
|
|
|
|
rev - Revision of the game (such as A)
|
|
|
|
version - Integer representing version, usually in the form of YYYYMMDDXX where
|
|
|
|
YYYY is a year, MM is a month, DD is a day and XX is sub-day versioning.
|
|
|
|
"""
|
2021-08-19 21:20:31 +02:00
|
|
|
self.gamecode = gamecode
|
2019-12-08 22:43:49 +01:00
|
|
|
self.dest = dest
|
|
|
|
self.spec = spec
|
|
|
|
self.rev = rev
|
|
|
|
self.version = version
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def from_modelstring(model: str) -> 'Model':
|
|
|
|
"""
|
|
|
|
Parse a modelstring and return a Model
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
model - Modelstring in a form similar to "K39:J:B:A:2010122200". Note that
|
|
|
|
The last part (version number) may be left off.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A Model object.
|
|
|
|
"""
|
|
|
|
parts = model.split(':')
|
|
|
|
if len(parts) == 5:
|
2021-08-19 21:20:31 +02:00
|
|
|
gamecode, dest, spec, rev, version = parts
|
|
|
|
return Model(gamecode, dest, spec, rev, int(version))
|
2019-12-08 22:43:49 +01:00
|
|
|
elif len(parts) == 4:
|
2021-08-19 21:20:31 +02:00
|
|
|
gamecode, dest, spec, rev = parts
|
|
|
|
return Model(gamecode, dest, spec, rev, None)
|
2020-01-07 22:29:07 +01:00
|
|
|
raise Exception(f'Couldn\'t parse model {model}')
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
if self.version is None:
|
2021-08-19 21:20:31 +02:00
|
|
|
return f'{self.gamecode}:{self.dest}:{self.spec}:{self.rev}'
|
2019-12-08 22:43:49 +01:00
|
|
|
else:
|
2021-08-19 21:20:31 +02:00
|
|
|
return f'{self.gamecode}:{self.dest}:{self.spec}:{self.rev}:{self.version}'
|