Move config.py
parent
5d86b17a01
commit
610c3bb01d
14
Dockerfile
14
Dockerfile
|
@ -7,13 +7,17 @@ WORKDIR /usr/src/app
|
|||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Prepare MC server
|
||||
COPY server.jar ./
|
||||
RUN java -jar server.jar --nogui
|
||||
# # Prepare MC server
|
||||
# COPY server.jar ./
|
||||
# RUN java -jar server.jar --nogui
|
||||
|
||||
COPY . .
|
||||
COPY src/ ./src/
|
||||
COPY main.py ./
|
||||
|
||||
COPY LICENSE.md ./
|
||||
COPY config.yaml ./
|
||||
|
||||
# Buffer Python's stdout for debugging during runtime
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
CMD ["python", "main.py", "java", "-Xmx1024M", "-Xms1024M", "-jar", "server.jar", "nogui"]
|
||||
CMD ["python", "main.py"]
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import src.mc_wrapper as mc_wrapper
|
||||
import src.mxclient as matrix_client
|
||||
|
||||
import asyncio
|
||||
|
||||
# Start the Minecraft process
|
||||
asyncio.run(matrix_client.start())
|
|
@ -3,7 +3,7 @@
|
|||
correct configuration.
|
||||
"""
|
||||
|
||||
import config
|
||||
import src.config as config
|
||||
|
||||
def write_eula():
|
||||
"""
|
||||
|
|
|
@ -1,62 +1,62 @@
|
|||
"""
|
||||
This module loads and parses the config.yaml file.
|
||||
"""
|
||||
|
||||
from typing import Any, List, Optional
|
||||
import yaml
|
||||
|
||||
with open('config.yaml', 'r') as open_file:
|
||||
SETTINGS = yaml.load(open_file)
|
||||
|
||||
def at(keys : List[str]) -> Optional[Any]:
|
||||
"""
|
||||
Potentially get a value. If it doesn't exist, return None.
|
||||
"""
|
||||
return at_value(keys, SETTINGS)
|
||||
|
||||
def at_value(keys : List[str], value : Any) -> Optional[Any]:
|
||||
try:
|
||||
head, tail = keys[0], keys[1:]
|
||||
except IndexError:
|
||||
return value
|
||||
else:
|
||||
try:
|
||||
new_value = value[head]
|
||||
except TypeError:
|
||||
return None
|
||||
except KeyError:
|
||||
return None
|
||||
else:
|
||||
return at_value(tail, new_value)
|
||||
|
||||
# EULA
|
||||
EULA = at(['config', 'eula']) or False
|
||||
|
||||
# Minecraft bridge credentials
|
||||
MATRIX_HOMESERVER = at(['matrix', 'homeserver']) or "https://matrix.example.org/"
|
||||
MATRIX_USERNAME = at(['matrix', 'username']) or "@alice:example.org"
|
||||
MATRIX_PASSWORD = at(['matrix', 'password']) or "bridge_password"
|
||||
|
||||
# Matrix bridge room
|
||||
MATRIX_ROOM = at(['matrix', 'room_id']) or "!channel_id:example.org"
|
||||
|
||||
SERVER_IP = at(['matrix', 'server_address']) or 'unknown ip'
|
||||
|
||||
MATRIX_ADMINS = at(['matrix', 'mc-admins']) or []
|
||||
|
||||
try:
|
||||
RAM_SIZE = int(at(['config', 'ram']))
|
||||
except TypeError:
|
||||
RAM_SIZE = 1024
|
||||
except ValueError:
|
||||
RAM_SIZE = 1024
|
||||
|
||||
SERVER_JAR_LOCATION = at(['config', 'server_jar']) or 'server.jar'
|
||||
|
||||
RUN_COMMAND = [
|
||||
'java',
|
||||
f'-Xmx{RAM_SIZE}M',
|
||||
f'-Xms{RAM_SIZE}M',
|
||||
'-jar', SERVER_JAR_LOCATION,
|
||||
'nogui'
|
||||
]
|
||||
"""
|
||||
This module loads and parses the config.yaml file.
|
||||
"""
|
||||
|
||||
from typing import Any, List, Optional
|
||||
import yaml
|
||||
|
||||
with open('config.yaml', 'r') as open_file:
|
||||
SETTINGS = yaml.load(open_file)
|
||||
|
||||
def at(keys : List[str]) -> Optional[Any]:
|
||||
"""
|
||||
Potentially get a value. If it doesn't exist, return None.
|
||||
"""
|
||||
return at_value(keys, SETTINGS)
|
||||
|
||||
def at_value(keys : List[str], value : Any) -> Optional[Any]:
|
||||
try:
|
||||
head, tail = keys[0], keys[1:]
|
||||
except IndexError:
|
||||
return value
|
||||
else:
|
||||
try:
|
||||
new_value = value[head]
|
||||
except TypeError:
|
||||
return None
|
||||
except KeyError:
|
||||
return None
|
||||
else:
|
||||
return at_value(tail, new_value)
|
||||
|
||||
# EULA
|
||||
EULA = at(['config', 'eula']) or False
|
||||
|
||||
# Minecraft bridge credentials
|
||||
MATRIX_HOMESERVER = at(['matrix', 'homeserver']) or "https://matrix.example.org/"
|
||||
MATRIX_USERNAME = at(['matrix', 'username']) or "@alice:example.org"
|
||||
MATRIX_PASSWORD = at(['matrix', 'password']) or "bridge_password"
|
||||
|
||||
# Matrix bridge room
|
||||
MATRIX_ROOM = at(['matrix', 'room_id']) or "!channel_id:example.org"
|
||||
|
||||
SERVER_IP = at(['matrix', 'server_address']) or 'unknown ip'
|
||||
|
||||
MATRIX_ADMINS = at(['matrix', 'mc-admins']) or []
|
||||
|
||||
try:
|
||||
RAM_SIZE = int(at(['config', 'ram']))
|
||||
except TypeError:
|
||||
RAM_SIZE = 1024
|
||||
except ValueError:
|
||||
RAM_SIZE = 1024
|
||||
|
||||
SERVER_JAR_LOCATION = at(['config', 'server_jar']) or 'server.jar'
|
||||
|
||||
RUN_COMMAND = [
|
||||
'java',
|
||||
f'-Xmx{RAM_SIZE}M',
|
||||
f'-Xms{RAM_SIZE}M',
|
||||
'-jar', SERVER_JAR_LOCATION,
|
||||
'nogui'
|
||||
]
|
|
@ -11,7 +11,7 @@ import asyncio
|
|||
import json
|
||||
import re
|
||||
from src.nbsr import NonBlockingStreamReader as NBSR
|
||||
import config
|
||||
import src.config as config
|
||||
import src.build_server as build
|
||||
|
||||
# Write the appropriate files
|
||||
|
|
|
@ -5,7 +5,7 @@ import re
|
|||
from nio import AsyncClient, MatrixRoom, RoomMessageText
|
||||
import src.mc_wrapper as mc_wrapper
|
||||
|
||||
import config
|
||||
import src.config as config
|
||||
|
||||
STARTUP_TIME = time.time()
|
||||
|
||||
|
@ -57,4 +57,5 @@ async def start():
|
|||
mc_wrapper.start(client, config.MATRIX_ROOM)
|
||||
)
|
||||
|
||||
asyncio.run(start())
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(start())
|
||||
|
|
Loading…
Reference in New Issue