mirror of
https://github.com/Jylpah/blitz-tools.git
synced 2026-10-21 10:17:05 +02:00
Workaround for Python 3.8 Asyncio issues with Win 10
This commit is contained in:
1 parent
a706903b18
commit
7cfdd872c8
4 files changed
+73
-8
No files matched your search
+30
-3
@@ -486,6 +486,14 @@ class PlayerHistogram():
|
||||
return None
|
||||
|
||||
|
||||
class ErrorCatchingArgumentParser(argparse.ArgumentParser):
|
||||
def exit(self, status=0, message=None):
|
||||
if status:
|
||||
if message != None:
|
||||
raise UserWarning(message)
|
||||
else:
|
||||
raise UserWarning()
|
||||
|
||||
## main() -------------------------------------------------------------
|
||||
|
||||
async def main(argv):
|
||||
@@ -517,6 +525,7 @@ async def main(argv):
|
||||
DB_CERT = None
|
||||
DB_CA = None
|
||||
|
||||
try:
|
||||
## Read config
|
||||
if os.path.isfile(FILE_CONFIG):
|
||||
config = configparser.ConfigParser()
|
||||
@@ -557,8 +566,8 @@ async def main(argv):
|
||||
except configparser.NoSectionError as err:
|
||||
bu.error(exception=err)
|
||||
|
||||
parser = ErrorCatchingArgumentParser(description='Analyze Blitz replay JSONs from WoTinspector.com')
|
||||
|
||||
parser = argparse.ArgumentParser(description='Analyze Blitz replay JSONs from WoTinspector.com')
|
||||
parser.add_argument('--output', default='plain', choices=['json', 'plain', 'db'], help='Select output mode: JSON, plain text or database')
|
||||
parser.add_argument('-id', dest='account_id', type=int, default=WG_ID, help='WG account_id to analyze')
|
||||
parser.add_argument('-a', '--account', type=str, default=None, help='WG account nameto analyze. Format: ACCOUNT_NAME@SERVER')
|
||||
@@ -577,7 +586,11 @@ async def main(argv):
|
||||
parser.add_argument('-s', '--silent', action='store_true', default=False, help='Silent mode')
|
||||
parser.add_argument('files', metavar='FILE1 [FILE2 ...]', type=str, nargs='+', help='Files/dirs to read. Use \'-\' for STDIN, "db:" for database')
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
except Exception as err:
|
||||
raise
|
||||
|
||||
bu.set_log_level(args.silent, args.verbose, args.debug)
|
||||
bu.set_progress_step(250) # Set the frequency of the progress dots.
|
||||
|
||||
@@ -654,10 +667,15 @@ async def main(argv):
|
||||
bu.debug('Finished. Cleaning up..................')
|
||||
except Exception as err:
|
||||
bu.error(exception=err)
|
||||
except UserWarning as err:
|
||||
bu.verbose(str(err))
|
||||
pass
|
||||
except Exception as err:
|
||||
bu.error(exception=err)
|
||||
finally:
|
||||
## Need to close the aiohttp.session since Python destructors do not support async methods...
|
||||
await wg.close()
|
||||
await wi.close()
|
||||
if wg != None: await wg.close()
|
||||
if wi != None: await wi.close()
|
||||
return None
|
||||
|
||||
def process_player_dist(results: list, player_stats: dict, stat_id_map: dict):
|
||||
@@ -1383,4 +1401,13 @@ def get_stat_id_player(stat_id_str: str) -> str:
|
||||
|
||||
### main()
|
||||
if __name__ == "__main__":
|
||||
# To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
|
||||
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
|
||||
try:
|
||||
from asyncio import WindowsSelectorEventLoopPolicy
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(main(sys.argv[1:]), debug=False)
|
||||
+15
-2
@@ -23,11 +23,16 @@ async def main(argv):
|
||||
os.chdir(os.path.dirname(sys.argv[0]))
|
||||
|
||||
## Read config
|
||||
BLITZAPP_FOLDER = '.'
|
||||
try:
|
||||
if os.path.isfile(FILE_CONFIG):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(FILE_CONFIG)
|
||||
|
||||
configOptions = config['EXTRACT_TANKOPEDIA']
|
||||
BLITZAPP_FOLDER = configOptions.get('blitz_app_dir', '.')
|
||||
BLITZAPP_FOLDER = configOptions.get('blitz_app_dir', BLITZAPP_FOLDER)
|
||||
except:
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(description='Extract Tankopedia data from Blitz game files')
|
||||
parser.add_argument('blitz_app_base', type=str, nargs='?', metavar="BLITZAPP_FOLDER", default=BLITZAPP_FOLDER, help='Base dir of the Blitz App files')
|
||||
@@ -186,6 +191,14 @@ async def get_tank_type(tagstr : str):
|
||||
|
||||
### main()
|
||||
if __name__ == "__main__":
|
||||
|
||||
# To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
|
||||
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
|
||||
try:
|
||||
from asyncio import WindowsSelectorEventLoopPolicy
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
#asyncio.run(main(sys.argv[1:]), debug=True)
|
||||
asyncio.run(main(sys.argv[1:]))
|
||||
+19
-3
@@ -2,7 +2,15 @@
|
||||
|
||||
# Get Tankpedia from WoTinspector.com
|
||||
|
||||
import sys, argparse, json, os, inspect, aiohttp, asyncio, re, logging
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import inspect
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import re
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import blitzutils as bu
|
||||
from blitzutils import WG
|
||||
@@ -64,12 +72,20 @@ async def main(argv):
|
||||
bu.set_log_level(args.silent, args.verbose, args.debug)
|
||||
|
||||
wi = WoTinspector()
|
||||
|
||||
await wi.get_tankopedia(args.outfile)
|
||||
|
||||
await wi.close()
|
||||
|
||||
|
||||
### main()
|
||||
# main()
|
||||
if __name__ == "__main__":
|
||||
# To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
|
||||
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
|
||||
try:
|
||||
from asyncio import WindowsSelectorEventLoopPolicy
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(main(sys.argv[1:]), debug=False)
|
||||
@@ -241,4 +241,13 @@ def getTitle(replayfile: str, title: str, i : int) -> str:
|
||||
|
||||
### main() -------------------------------------------
|
||||
if __name__ == "__main__":
|
||||
# To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
|
||||
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
|
||||
try:
|
||||
from asyncio import WindowsSelectorEventLoopPolicy
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(main(sys.argv[1:]), debug=False)
|
||||
Reference in new issue
Block a user