mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 01:35:28 +01:00
Fixing Pylint issues
This commit is contained in:
parent
37bda32164
commit
8f5c688b72
@ -1,12 +1,8 @@
|
||||
from gettext import install
|
||||
from inspect import _void
|
||||
import os
|
||||
import logging
|
||||
from pydoc import Helper
|
||||
import time
|
||||
import json
|
||||
import typing as t
|
||||
from typing_extensions import Self
|
||||
|
||||
from app.classes.controllers.roles_controller import RolesController
|
||||
|
||||
@ -20,7 +16,6 @@ from app.classes.minecraft.server_props import ServerProps
|
||||
from app.classes.minecraft.stats import Stats
|
||||
|
||||
from app.classes.models.servers import HelperServers
|
||||
from app.classes.models.server_stats import HelperServerStats
|
||||
from app.classes.models.users import HelperUsers, ApiKeys
|
||||
from app.classes.models.server_permissions import (
|
||||
PermissionsServers,
|
||||
@ -133,11 +128,13 @@ class ServersController(metaclass=Singleton):
|
||||
# Servers Methods
|
||||
# **********************************************************************************
|
||||
|
||||
def get_server_instance_by_id(self, server_id):
|
||||
def get_server_instance_by_id(self, server_id: t.Union[str, int]) -> Server:
|
||||
for server in self.servers_list:
|
||||
if server["server_id"] == int(server_id):
|
||||
if int(server["server_id"]) == int(server_id):
|
||||
return server["server_obj"]
|
||||
return None
|
||||
|
||||
logger.warning(f"Unable to find server object for server id {server_id}")
|
||||
raise Exception(f"Unable to find server object for server id {server_id}")
|
||||
|
||||
def init_all_servers(self):
|
||||
|
||||
@ -228,7 +225,7 @@ class ServersController(metaclass=Singleton):
|
||||
return False
|
||||
|
||||
def refresh_server_settings(self, server_id: int):
|
||||
server_obj = self.get_server_obj(server_id)
|
||||
server_obj: Server = self.get_server_data_by_id(server_id)
|
||||
server_obj.reload_server_settings()
|
||||
|
||||
@staticmethod
|
||||
@ -362,14 +359,6 @@ class ServersController(metaclass=Singleton):
|
||||
else:
|
||||
svr.stop_crash_detection()
|
||||
|
||||
def get_server_obj(self, server_id: t.Union[str, int]) -> Server:
|
||||
for server in self.servers_list:
|
||||
if str(server["server_id"]) == str(server_id):
|
||||
return server["server_obj"]
|
||||
|
||||
logger.warning(f"Unable to find server object for server id {server_id}")
|
||||
raise Exception(f"Unable to find server object for server id {server_id}")
|
||||
|
||||
def get_server_obj_optional(
|
||||
self, server_id: t.Union[str, int]
|
||||
) -> t.Optional[Server]:
|
||||
@ -401,10 +390,9 @@ class ServersController(metaclass=Singleton):
|
||||
running_servers = []
|
||||
|
||||
# for each server
|
||||
for servers in self.servers_list:
|
||||
|
||||
for server in self.servers_list:
|
||||
# is the server running?
|
||||
srv_obj = servers["server_obj"]
|
||||
srv_obj: Server = server["server_obj"]
|
||||
running = srv_obj.check_running()
|
||||
# if so, let's add a dictionary to the list of running servers
|
||||
if running:
|
||||
@ -434,7 +422,7 @@ class ServersController(metaclass=Singleton):
|
||||
|
||||
def stop_server(self, server_id):
|
||||
# issue the stop command
|
||||
svr_obj = self.get_server_obj(server_id)
|
||||
svr_obj = self.get_server_instance_by_id(server_id)
|
||||
svr_obj.stop_threaded_server()
|
||||
|
||||
# **********************************************************************************
|
||||
|
@ -1,11 +1,6 @@
|
||||
import os
|
||||
import logging
|
||||
import datetime
|
||||
import typing as t
|
||||
|
||||
import typing as t
|
||||
|
||||
from peewee import DoesNotExist
|
||||
|
||||
from app.classes.models.servers import Servers, HelperServers
|
||||
from app.classes.shared.helpers import Helpers
|
||||
@ -138,7 +133,7 @@ class HelperServerStats:
|
||||
server_data.append(
|
||||
{
|
||||
"server_data": server,
|
||||
"stats": stats,
|
||||
"stats": DatabaseShortcuts.get_data_obj(latest),
|
||||
"user_command_permission": True,
|
||||
}
|
||||
)
|
||||
|
@ -5,7 +5,6 @@ import shutil
|
||||
import time
|
||||
import logging
|
||||
import tempfile
|
||||
import typing as t
|
||||
from peewee import DoesNotExist
|
||||
|
||||
# TZLocal is set as a hidden import on win pipeline
|
||||
@ -832,7 +831,7 @@ class Controller:
|
||||
running = srv_obj.check_running()
|
||||
|
||||
if running:
|
||||
self.stop_server(server_id)
|
||||
self.servers.stop_server(server_id)
|
||||
if files:
|
||||
try:
|
||||
FileHelpers.del_dirs(
|
||||
|
@ -86,7 +86,9 @@ class TasksManager:
|
||||
commands = HelpersManagement.get_unactioned_commands()
|
||||
for cmd in commands:
|
||||
try:
|
||||
svr = self.controller.servers.get_server_obj(cmd.server_id)
|
||||
svr = self.controller.servers.get_server_instance_by_id(
|
||||
cmd.server_id
|
||||
)
|
||||
except:
|
||||
logger.error(
|
||||
"Server value requested does not exist! "
|
||||
|
@ -286,7 +286,7 @@ class AjaxHandler(BaseHandler):
|
||||
logger.warning("Server ID not found in send_command ajax call")
|
||||
Console.warning("Server ID not found in send_command ajax call")
|
||||
|
||||
srv_obj = self.controller.servers.get_server_obj(server_id)
|
||||
srv_obj = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
|
||||
if command == srv_obj.settings["stop_command"]:
|
||||
logger.info(
|
||||
@ -334,7 +334,7 @@ class AjaxHandler(BaseHandler):
|
||||
logger.error("Server ID is none. Canceling backup!")
|
||||
return
|
||||
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
self.controller.management.add_to_audit_log_raw(
|
||||
self.controller.users.get_user_by_id(exec_user["user_id"])["username"],
|
||||
exec_user["user_id"],
|
||||
@ -356,7 +356,7 @@ class AjaxHandler(BaseHandler):
|
||||
self.redirect("/panel/error?error=Unauthorized access to Commands")
|
||||
return
|
||||
server_id = self.get_argument("id", None)
|
||||
svr = self.controller.servers.get_server_obj(server_id)
|
||||
svr = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
try:
|
||||
svr.kill()
|
||||
time.sleep(5)
|
||||
@ -369,7 +369,7 @@ class AjaxHandler(BaseHandler):
|
||||
return
|
||||
elif page == "eula":
|
||||
server_id = self.get_argument("id", None)
|
||||
svr = self.controller.servers.get_server_obj(server_id)
|
||||
svr = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
svr.agree_eula(exec_user["user_id"])
|
||||
|
||||
elif page == "restore_backup":
|
||||
|
@ -161,7 +161,7 @@ class SendCommand(ApiHandler):
|
||||
command = self.get_argument("command", default=None, strip=True)
|
||||
server_id = self.get_argument("id")
|
||||
if command:
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
if server.check_running:
|
||||
server.send_command(command)
|
||||
self.return_response(200, {"run": True})
|
||||
@ -198,7 +198,7 @@ class ServerBackup(ApiHandler):
|
||||
self.access_denied(user)
|
||||
return
|
||||
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
|
||||
server.backup_server()
|
||||
|
||||
@ -232,7 +232,7 @@ class StartServer(ApiHandler):
|
||||
self.access_denied("unknown")
|
||||
return
|
||||
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
|
||||
if not server.check_running():
|
||||
self.controller.management.send_command(
|
||||
@ -270,7 +270,7 @@ class StopServer(ApiHandler):
|
||||
self.access_denied(user)
|
||||
return
|
||||
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
|
||||
if server.check_running():
|
||||
self.controller.management.send_command(
|
||||
|
@ -497,7 +497,7 @@ class PanelHandler(BaseHandler):
|
||||
"schedules",
|
||||
]
|
||||
|
||||
server = self.controller.servers.get_server_obj(server_id)
|
||||
server = self.controller.servers.get_server_instance_by_id(server_id)
|
||||
# server_data isn't needed since the server_stats also pulls server data
|
||||
page_data["server_data"] = self.controller.servers.get_server_data_by_id(
|
||||
server_id
|
||||
@ -645,10 +645,14 @@ class PanelHandler(BaseHandler):
|
||||
page_data[
|
||||
"exclusions"
|
||||
] = self.controller.management.get_excluded_backup_dirs(server_id)
|
||||
page_data["backing_up"] = self.controller.servers.get_server_obj(
|
||||
page_data[
|
||||
"backing_up"
|
||||
] = self.controller.servers.get_server_instance_by_id(
|
||||
server_id
|
||||
).is_backingup
|
||||
page_data["backup_stats"] = self.controller.servers.get_server_obj(
|
||||
page_data[
|
||||
"backup_stats"
|
||||
] = self.controller.servers.get_server_instance_by_id(
|
||||
server_id
|
||||
).send_backup_status()
|
||||
# makes it so relative path is the only thing shown
|
||||
|
Loading…
x
Reference in New Issue
Block a user