mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Audio] Do less strict matching for java version (#2035)
* [Audio] Do less strict matching for java version Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * [Audio] Fix java version bounds to account for Oracle's bullshit Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
parent
ce031cf7bd
commit
0cf54ec9c2
@ -1,9 +1,11 @@
|
|||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import asyncio
|
import asyncio
|
||||||
from subprocess import Popen, DEVNULL, PIPE
|
import asyncio.subprocess
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
from subprocess import Popen, DEVNULL
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
_JavaVersion = Tuple[int, int]
|
_JavaVersion = Tuple[int, int]
|
||||||
@ -45,23 +47,42 @@ async def has_java(loop) -> Tuple[bool, Optional[_JavaVersion]]:
|
|||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
version = await get_java_version(loop)
|
version = await get_java_version(loop)
|
||||||
return version >= (1, 8), version
|
return (2, 0) > version >= (1, 8) or version >= (8, 0), version
|
||||||
|
|
||||||
|
|
||||||
async def get_java_version(loop) -> _JavaVersion:
|
async def get_java_version(loop) -> _JavaVersion:
|
||||||
"""
|
"""
|
||||||
This assumes we've already checked that java exists.
|
This assumes we've already checked that java exists.
|
||||||
"""
|
"""
|
||||||
proc = Popen(shlex.split("java -version", posix=os.name == "posix"), stdout=PIPE, stderr=PIPE)
|
_proc: asyncio.subprocess.Process = await asyncio.create_subprocess_exec(
|
||||||
_, err = proc.communicate()
|
"java",
|
||||||
|
"-version",
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
loop=loop,
|
||||||
|
)
|
||||||
|
# java -version outputs to stderr
|
||||||
|
_, err = await _proc.communicate()
|
||||||
|
|
||||||
version_info = str(err, encoding="utf-8")
|
version_info: str = err.decode("utf-8")
|
||||||
|
# We expect the output to look something like:
|
||||||
|
# $ java -version
|
||||||
|
# ...
|
||||||
|
# ... version "MAJOR.MINOR.PATCH[_BUILD]" ...
|
||||||
|
# ...
|
||||||
|
# We only care about the major and minor parts though.
|
||||||
|
version_line_re = re.compile(r'version "(?P<major>\d+).(?P<minor>\d+).\d+(?:_\d+)?"')
|
||||||
|
|
||||||
version_line = version_info.split("\n")[0]
|
lines = version_info.splitlines()
|
||||||
version_start = version_line.find('"')
|
for line in lines:
|
||||||
version_string = version_line[version_start + 1 : -1]
|
match = version_line_re.search(line)
|
||||||
major, minor = version_string.split(".")[:2]
|
if match:
|
||||||
return int(major), int(minor)
|
return int(match["major"]), int(match["minor"])
|
||||||
|
|
||||||
|
raise RuntimeError(
|
||||||
|
"The output of `java -version` was unexpected. Please report this issue on Red's "
|
||||||
|
"issue tracker."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def start_lavalink_server(loop):
|
async def start_lavalink_server(loop):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user