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