-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get exdschema implemented for some base name setting
- Loading branch information
Showing
6 changed files
with
200 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
def get_definition(schema: dict[str, str]) -> dict[str, str]: | ||
if 'type' in schema: | ||
if schema['type'] == 'array': | ||
return RepeatDefinition(schema) | ||
return Definition(schema) | ||
|
||
|
||
class Definition: | ||
def __init__(self, obj: dict[str, str]) -> None: | ||
self.name = obj['name'] | ||
|
||
def __repr__(self) -> str: | ||
return self.name | ||
|
||
|
||
class RepeatDefinition(Definition): | ||
def __init__(self, obj: dict[str, str]) -> None: | ||
super().__init__(obj) | ||
self.obj = obj | ||
self.count = obj['count'] | ||
self.inner_defs = [] | ||
self.process_inner() | ||
|
||
def process_inner(self): | ||
if 'fields' in self.obj: | ||
for field in self.obj['fields']: | ||
if 'name' in field: | ||
self.inner_defs.append(get_definition(field)) | ||
else: | ||
self.inner_defs.append(Definition({'name': ""})) | ||
if self.inner_defs == []: | ||
self.inner_defs.append(Definition({'name': ""})) | ||
|
||
def flatten(self, extern: str) -> list[Definition]: | ||
defs = [] | ||
extern = extern + self.name | ||
for i in range(0, int(self.count)): | ||
for inner in self.inner_defs: | ||
if isinstance(inner, RepeatDefinition): | ||
defs.extend(inner.flatten(extern + i.__str__())) | ||
else: | ||
defs.append(Definition({'name': extern + i.__str__() + inner.name})) | ||
return defs | ||
|
||
def __repr__(self) -> str: | ||
return f'{self.flatten("")}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from urllib.request import urlopen, Request | ||
from urllib.error import HTTPError, URLError | ||
from json import loads | ||
from luminapie.game_data import SemanticVersion | ||
from luminapie.definitions import Definition, RepeatDefinition, get_definition | ||
from typing import Union | ||
from yaml import load, Loader | ||
from zipfile import ZipFile | ||
from tempfile import TemporaryFile | ||
|
||
EXDSchemaFields = dict[str, Union[str, list[str], 'EXDSchemaFields']] | ||
|
||
|
||
def get_url(url: str, supress: bool = False) -> bytes | None: | ||
req = Request(url) | ||
try: | ||
resp = urlopen(req) | ||
return resp.read() | ||
except HTTPError as e: | ||
if not supress: | ||
print('HTTP Error code: ', e.code, ' for url: ', url) | ||
return None | ||
except URLError as e: | ||
if not supress: | ||
print('HTTP Reason: ', e.reason, ' for url: ', url) | ||
return None | ||
|
||
|
||
def get_latest_schema() -> dict[SemanticVersion, str]: | ||
json = loads(get_url('https://api.github.com/repos/xivdev/EXDSchema/releases/latest')) | ||
assetsJson = json['assets'] | ||
assets = {} | ||
for asset in assetsJson: | ||
version = SemanticVersion(*(int(x) for x in asset['name'].split('.')[0:5])) | ||
assets[version] = asset['browser_download_url'] | ||
assets = dict(sorted(assets.items())) | ||
return assets | ||
|
||
|
||
def get_latest_schema_url(ver: SemanticVersion) -> str: | ||
latest_release = get_latest_schema() | ||
# check if the current version can be retrieved | ||
if ver in latest_release: | ||
return latest_release[ver] | ||
# grab the version before the current version if it can't be retrieved | ||
for version in latest_release: | ||
if version < ver: | ||
return latest_release[version] | ||
|
||
|
||
def get_definitions(schema: SemanticVersion) -> dict[str, list[Definition]]: | ||
exd_schema_map = {} | ||
with TemporaryFile() as f: | ||
f.write(get_url(get_latest_schema_url(schema), True)) | ||
f.seek(0) | ||
schema_zip = ZipFile(f) | ||
|
||
for file in schema_zip.namelist(): | ||
if file.endswith('.yml'): | ||
schema_yml = load(schema_zip.read(file), Loader=Loader) | ||
exd_schema_map[file.rsplit('.', 1)[0].rsplit('/', 1)[1]] = schema_yml['fields'] | ||
|
||
defs_map = {} | ||
for exd in exd_schema_map: | ||
defs = [] | ||
for field in exd_schema_map[exd]: | ||
defin = get_definition(field) | ||
if isinstance(defin, RepeatDefinition): | ||
defs.extend(defin.flatten("")) | ||
else: | ||
defs.append(defin) | ||
defs_map[exd] = defs | ||
return defs_map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import os | ||
import json | ||
from luminapie.game_data import GameData, ParsedFileName | ||
from luminapie.excel import ExcelListFile | ||
from luminapie.excel import ExcelListFile, ExcelHeaderFile | ||
from luminapie.exdschema import get_definitions | ||
|
||
|
||
def main(): | ||
f = open(os.path.join(os.getenv('APPDATA'), 'XIVLauncher', 'launcherConfigV3.json'), 'r') | ||
config = json.load(f) | ||
f.close() | ||
# game_data = GameData(os.path.join(config['GamePath'], 'game')) | ||
game_data = GameData("C:\\Users\\magnu\\Downloads\\ffxiv-dawntrail-bench\\game") | ||
game_data = GameData(os.path.join(config['GamePath'], 'game')) | ||
exd_map = ExcelListFile(game_data.get_file(ParsedFileName('exd/root.exl'))).dict | ||
|
||
exd_headers: dict[int, tuple[dict[int, tuple[str, str]], int]] = {} | ||
|
||
exd_schema = get_definitions(game_data.repositories[0].version) | ||
|
||
for key in exd_map: | ||
print(key, exd_map[key]) | ||
print(f'Parsing schema for {exd_map[key]}') | ||
exd_headers[key] = ExcelHeaderFile(game_data.get_file(ParsedFileName(f'exd/{exd_map[key]}.exh'))).map_names( | ||
exd_schema[exd_map[key]] | ||
) | ||
|
||
print(exd_headers) | ||
|
||
|
||
main() |