From 219cae9a8284bbde39ad878210597e5afaa632d1 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 31 Mar 2024 17:57:49 +0300 Subject: [PATCH] version parser --- TODO.md | 1 + utils/version-parser/.gitignore | 1 + utils/version-parser/parser.py | 30 +++++++++++++++++++++++++++++ utils/version-parser/pyproject.toml | 3 +++ 4 files changed, 35 insertions(+) create mode 100644 utils/version-parser/.gitignore create mode 100755 utils/version-parser/parser.py create mode 100644 utils/version-parser/pyproject.toml diff --git a/TODO.md b/TODO.md index 09db01c..c01f01a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,5 @@ # TODO - [x] assets downloader +- [x] library parser - [ ] library downloader diff --git a/utils/version-parser/.gitignore b/utils/version-parser/.gitignore new file mode 100644 index 0000000..a6c57f5 --- /dev/null +++ b/utils/version-parser/.gitignore @@ -0,0 +1 @@ +*.json diff --git a/utils/version-parser/parser.py b/utils/version-parser/parser.py new file mode 100755 index 0000000..dd9aa12 --- /dev/null +++ b/utils/version-parser/parser.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import sys +import json + +TYPE = 'linux' +# TYPE='windows' +# TYPE='macos' + +if __name__ == '__main__': + if len(sys.argv) < 2: + print('add file') + exit(-1) + else: + version_file = sys.argv[1] + + with open(version_file, 'r') as f: + a = json.loads(f.read()) + + print('Game ID: {0}'.format(a['id'])) + print('Main class: {0}'.format(a['mainClass'])) + print('Assets index: {0}'.format(a['assetIndex']['id'])) + + for library in a['libraries']: + if 'rules' in library: + if 'os' in library['rules'][0]: + if TYPE == library['rules'][0]['os']['name']: + print(library['downloads']['artifact']['path']) + else: + print(library['downloads']['artifact']['path']) diff --git a/utils/version-parser/pyproject.toml b/utils/version-parser/pyproject.toml new file mode 100644 index 0000000..cb70edc --- /dev/null +++ b/utils/version-parser/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +skip-string-normalization = true +line-length = 100