Fix formatting to comply with Black

This commit is contained in:
Zedifus 2022-04-11 11:08:36 +01:00
parent 42ca4bb973
commit 19f2429a4c
24 changed files with 160 additions and 55 deletions

View File

@ -10,6 +10,7 @@ logger = logging.getLogger(__name__)
class Roles_Controller: class Roles_Controller:
def __init__(self, users_helper): def __init__(self, users_helper):
self.users_helper = users_helper self.users_helper = users_helper
@staticmethod @staticmethod
def get_all_roles(): def get_all_roles():
return helper_roles.get_all_roles() return helper_roles.get_all_roles()
@ -45,7 +46,9 @@ class Roles_Controller:
for server in added_servers: for server in added_servers:
Permissions_Servers.get_or_create(role_id, server, permissions_mask) Permissions_Servers.get_or_create(role_id, server, permissions_mask)
for server in base_data["servers"]: for server in base_data["servers"]:
Permissions_Servers.update_role_permission(role_id, server, permissions_mask) Permissions_Servers.update_role_permission(
role_id, server, permissions_mask
)
# TODO: This is horribly inefficient and we should be using bulk queries # TODO: This is horribly inefficient and we should be using bulk queries
# but im going for functionality at this point # but im going for functionality at this point
Permissions_Servers.delete_roles_permissions(role_id, removed_servers) Permissions_Servers.delete_roles_permissions(role_id, removed_servers)

View File

@ -11,6 +11,7 @@ from app.classes.models.server_permissions import Permissions_Servers
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class ServerJars: class ServerJars:
def __init__(self, helper): def __init__(self, helper):
self.helper = helper self.helper = helper
@ -177,7 +178,9 @@ class ServerJars:
try: try:
Servers_Controller.set_download(server_id) Servers_Controller.set_download(server_id)
for user in server_users: for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {}) self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {}
)
break break
except Exception as ex: except Exception as ex:
@ -195,7 +198,9 @@ class ServerJars:
user, "notification", "Executable download finished" user, "notification", "Executable download finished"
) )
time.sleep(3) time.sleep(3)
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {}) self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {}
)
return True return True
except Exception as e: except Exception as e:
logger.error(f"Unable to save jar to {path} due to error:{e}") logger.error(f"Unable to save jar to {path} due to error:{e}")
@ -206,6 +211,8 @@ class ServerJars:
user, "notification", "Executable download finished" user, "notification", "Executable download finished"
) )
time.sleep(3) time.sleep(3)
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {}) self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {}
)
return False return False

View File

@ -61,7 +61,9 @@ class Stats:
with p.oneshot(): with p.oneshot():
process_stats = { process_stats = {
"cpu_usage": real_cpu, "cpu_usage": real_cpu,
"memory_usage": Helpers.human_readable_file_size(p.memory_info()[0]), "memory_usage": Helpers.human_readable_file_size(
p.memory_info()[0]
),
"mem_percentage": round(p.memory_percent(), 0), "mem_percentage": round(p.memory_percent(), 0),
} }
return process_stats return process_stats

View File

@ -2,6 +2,7 @@ import peewee
database_proxy = peewee.DatabaseProxy() database_proxy = peewee.DatabaseProxy()
class BaseModel(peewee.Model): class BaseModel(peewee.Model):
class Meta: class Meta:
database = database_proxy database = database_proxy

View File

@ -181,9 +181,7 @@ class Permissions_Servers:
@staticmethod @staticmethod
def remove_roles_of_server(server_id): def remove_roles_of_server(server_id):
return ( return (
Role_Servers.delete() Role_Servers.delete().where(Role_Servers.server_id == server_id).execute()
.where(Role_Servers.server_id == server_id)
.execute()
) )
@staticmethod @staticmethod

View File

@ -112,4 +112,4 @@ class FileHelpers:
f" - Error was: {e}" f" - Error was: {e}"
) )
return True return True

View File

@ -630,7 +630,10 @@ class Helpers:
sizes = [] sizes = []
for p in paths: for p in paths:
sizes.append( sizes.append(
{"path": p, "size": Helpers.human_readable_file_size(os.stat(p).st_size)} {
"path": p,
"size": Helpers.human_readable_file_size(os.stat(p).st_size),
}
) )
return sizes return sizes
@ -913,7 +916,9 @@ class Helpers:
def backup_select(self, path, user_id): def backup_select(self, path, user_id):
if user_id: if user_id:
self.websocket_helper.broadcast_user(user_id, "send_temp_path", {"path": path}) self.websocket_helper.broadcast_user(
user_id, "send_temp_path", {"path": path}
)
@staticmethod @staticmethod
def unzip_backup_archive(backup_path, zip_name): def unzip_backup_archive(backup_path, zip_name):

View File

@ -13,7 +13,6 @@ class import3:
self.console = self.helper.console self.console = self.helper.console
self.controller = controller self.controller = controller
def start_import(self): def start_import(self):
folder = os.path.normpath( folder = os.path.normpath(
input( input(
@ -26,7 +25,9 @@ class import3:
"Crafty cannot find the path you entered. " "Crafty cannot find the path you entered. "
"Does Crafty's user have permission to access it?" "Does Crafty's user have permission to access it?"
) )
self.console.info("Please run the import3 command again and enter a valid path.") self.console.info(
"Please run the import3 command again and enter a valid path."
)
else: else:
with open(os.path.join(folder, "users.json"), encoding="utf-8") as f: with open(os.path.join(folder, "users.json"), encoding="utf-8") as f:
user_json = json.loads(f.read()) user_json = json.loads(f.read())

View File

@ -7,6 +7,7 @@ import logging
import tempfile import tempfile
from typing import Union from typing import Union
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
from tzlocal import get_localzone from tzlocal import get_localzone
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@ -31,6 +32,7 @@ from app.classes.minecraft.stats import Stats
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Controller: class Controller:
def __init__(self, database, helper): def __init__(self, database, helper):
self.helper = helper self.helper = helper
@ -47,7 +49,9 @@ class Controller:
self.roles = Roles_Controller(self.users_helper) self.roles = Roles_Controller(self.users_helper)
self.server_perms = Server_Perms_Controller() self.server_perms = Server_Perms_Controller()
self.servers = Servers_Controller(self.servers_helper) self.servers = Servers_Controller(self.servers_helper)
self.users = Users_Controller(self.helper, self.users_helper, self.authentication) self.users = Users_Controller(
self.helper, self.users_helper, self.authentication
)
tz = get_localzone() tz = get_localzone()
self.support_scheduler = BackgroundScheduler(timezone=str(tz)) self.support_scheduler = BackgroundScheduler(timezone=str(tz))
self.support_scheduler.start() self.support_scheduler.start()
@ -103,7 +107,9 @@ class Controller:
# if the properties file isn't there, let's warn # if the properties file isn't there, let's warn
if not Helpers.check_file_exists(settings_file): if not Helpers.check_file_exists(settings_file):
logger.error(f"Unable to find {settings_file}. Skipping this server.") logger.error(f"Unable to find {settings_file}. Skipping this server.")
self.console.error(f"Unable to find {settings_file}. Skipping this server.") self.console.error(
f"Unable to find {settings_file}. Skipping this server."
)
continue continue
settings = ServerProps(settings_file) settings = ServerProps(settings_file)
@ -217,7 +223,9 @@ class Controller:
) )
tempZipStorage += ".zip" tempZipStorage += ".zip"
self.helper.websocket_helper.broadcast_user(exec_user["user_id"], "send_logs_bootbox", {}) self.helper.websocket_helper.broadcast_user(
exec_user["user_id"], "send_logs_bootbox", {}
)
self.users.set_support_path(exec_user["user_id"], tempZipStorage) self.users.set_support_path(exec_user["user_id"], tempZipStorage)
@ -717,10 +725,13 @@ class Controller:
old_bu_path = server_data["backup_path"] old_bu_path = server_data["backup_path"]
Server_Perms_Controller.backup_role_swap(old_server_id, new_server_id) Server_Perms_Controller.backup_role_swap(old_server_id, new_server_id)
if not Helpers.is_os_windows(): if not Helpers.is_os_windows():
backup_path = Helpers.validate_traversal(self.helper.backup_path, old_bu_path) backup_path = Helpers.validate_traversal(
self.helper.backup_path, old_bu_path
)
if Helpers.is_os_windows(): if Helpers.is_os_windows():
backup_path = Helpers.validate_traversal( backup_path = Helpers.validate_traversal(
Helpers.wtol_path(self.helper.backup_path), Helpers.wtol_path(old_bu_path) Helpers.wtol_path(self.helper.backup_path),
Helpers.wtol_path(old_bu_path),
) )
backup_path = Helpers.wtol_path(str(backup_path)) backup_path = Helpers.wtol_path(str(backup_path))
backup_path.replace(" ", "^ ") backup_path.replace(" ", "^ ")
@ -761,7 +772,9 @@ class Controller:
server_port, server_port,
) )
if not Helpers.check_file_exists(os.path.join(server_dir, "crafty_managed.txt")): if not Helpers.check_file_exists(
os.path.join(server_dir, "crafty_managed.txt")
):
try: try:
# place a file in the dir saying it's owned by crafty # place a file in the dir saying it's owned by crafty
with open( with open(
@ -794,7 +807,9 @@ class Controller:
server_name = server_data["server_name"] server_name = server_data["server_name"]
logger.info(f"Deleting Server: ID {server_id} | Name: {server_name} ") logger.info(f"Deleting Server: ID {server_id} | Name: {server_name} ")
self.console.info(f"Deleting Server: ID {server_id} | Name: {server_name} ") self.console.info(
f"Deleting Server: ID {server_id} | Name: {server_name} "
)
srv_obj = s["server_obj"] srv_obj = s["server_obj"]
running = srv_obj.check_running() running = srv_obj.check_running()

View File

@ -6,6 +6,7 @@ from app.classes.shared.helpers import Helpers
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class db_builder: class db_builder:
def __init__(self, database, helper, users_helper): def __init__(self, database, helper, users_helper):
self.database = database self.database = database

View File

@ -331,11 +331,15 @@ class MigrationManager(object):
""" """
if not os.path.exists(self.helper.migration_dir): if not os.path.exists(self.helper.migration_dir):
logger.warning( logger.warning(
"Migration directory: {} does not exist.".format(self.helper.migration_dir) "Migration directory: {} does not exist.".format(
self.helper.migration_dir
)
) )
os.makedirs(self.helper.migration_dir) os.makedirs(self.helper.migration_dir)
return sorted( return sorted(
f[:-3] for f in os.listdir(self.helper.migration_dir) if self.filemask.match(f) f[:-3]
for f in os.listdir(self.helper.migration_dir)
if self.filemask.match(f)
) )
@property @property
@ -419,7 +423,9 @@ class MigrationManager(object):
if Helpers.is_os_windows() and sys.version_info >= (3, 0): if Helpers.is_os_windows() and sys.version_info >= (3, 0):
# if system is windows - force utf-8 encoding # if system is windows - force utf-8 encoding
call_params["encoding"] = "utf-8" call_params["encoding"] = "utf-8"
with open(os.path.join(self.helper.migration_dir, name + ".py"), **call_params) as f: with open(
os.path.join(self.helper.migration_dir, name + ".py"), **call_params
) as f:
code = f.read() code = f.read()
scope = {} scope = {}
code = compile(code, "<string>", "exec", dont_inherit=True) code = compile(code, "<string>", "exec", dont_inherit=True)

View File

@ -9,6 +9,7 @@ import subprocess
import html import html
import tempfile import tempfile
import psutil import psutil
# TZLocal is set as a hidden import on win pipeline # TZLocal is set as a hidden import on win pipeline
from tzlocal import get_localzone from tzlocal import get_localzone
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@ -148,7 +149,9 @@ class Server:
delay = int(self.settings["auto_start_delay"]) delay = int(self.settings["auto_start_delay"])
logger.info(f"Scheduling server {self.name} to start in {delay} seconds") logger.info(f"Scheduling server {self.name} to start in {delay} seconds")
self.console.info(f"Scheduling server {self.name} to start in {delay} seconds") self.console.info(
f"Scheduling server {self.name} to start in {delay} seconds"
)
self.server_scheduler.add_job( self.server_scheduler.add_job(
self.run_scheduled_server, self.run_scheduled_server,
@ -216,7 +219,9 @@ class Server:
if not Helpers.check_path_exists(self.server_path): if not Helpers.check_path_exists(self.server_path):
logger.critical(f"Server path: {self.server_path} does not seem to exits") logger.critical(f"Server path: {self.server_path} does not seem to exits")
self.console.critical(f"Server path: {self.server_path} does not seem to exits") self.console.critical(
f"Server path: {self.server_path} does not seem to exits"
)
if not Helpers.check_writeable(self.server_path): if not Helpers.check_writeable(self.server_path):
logger.critical(f"Unable to write/access {self.server_path}") logger.critical(f"Unable to write/access {self.server_path}")
@ -255,7 +260,9 @@ class Server:
return False return False
logger.info(f"Launching Server {self.name} with command {self.server_command}") logger.info(f"Launching Server {self.name} with command {self.server_command}")
self.console.info(f"Launching Server {self.name} with command {self.server_command}") self.console.info(
f"Launching Server {self.name} with command {self.server_command}"
)
# Checks for eula. Creates one if none detected. # Checks for eula. Creates one if none detected.
# If EULA is detected and not set to true we offer to set it true. # If EULA is detected and not set to true we offer to set it true.
@ -450,11 +457,15 @@ class Server:
server_users = Permissions_Servers.get_server_user_list(self.server_id) server_users = Permissions_Servers.get_server_user_list(self.server_id)
for user in server_users: for user in server_users:
if user != user_id: if user != user_id:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {}) self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {}
)
else: else:
server_users = Permissions_Servers.get_server_user_list(self.server_id) server_users = Permissions_Servers.get_server_user_list(self.server_id)
for user in server_users: for user in server_users:
self.helper.websocket_helper.broadcast_user(user, "send_start_reload", {}) self.helper.websocket_helper.broadcast_user(
user, "send_start_reload", {}
)
else: else:
logger.warning( logger.warning(
f"Server PID {self.process.pid} died right after starting " f"Server PID {self.process.pid} died right after starting "
@ -485,7 +496,11 @@ class Server:
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(
user_id, user_id,
"send_start_error", "send_start_error",
{"error": self.helper.translation.translate("error", "internet", user_lang)}, {
"error": self.helper.translation.translate(
"error", "internet", user_lang
)
},
) )
def stop_crash_detection(self): def stop_crash_detection(self):
@ -998,7 +1013,9 @@ class Server:
"string": message, "string": message,
}, },
) )
self.helper.websocket_helper.broadcast_page("/panel/dashboard", "send_start_reload", {}) self.helper.websocket_helper.broadcast_page(
"/panel/dashboard", "send_start_reload", {}
)
backup_dir = os.path.join( backup_dir = os.path.join(
Helpers.get_os_understandable_path(self.settings["path"]), Helpers.get_os_understandable_path(self.settings["path"]),
"crafty_executable_backups", "crafty_executable_backups",

View File

@ -177,12 +177,16 @@ class TasksManager:
], ],
) )
except Exception as e: except Exception as e:
self.helper.console.error(f"Failed to schedule task with error: {e}.") self.helper.console.error(
f"Failed to schedule task with error: {e}."
)
self.helper.console.warning("Removing failed task from DB.") self.helper.console.warning("Removing failed task from DB.")
logger.error(f"Failed to schedule task with error: {e}.") logger.error(f"Failed to schedule task with error: {e}.")
logger.warning("Removing failed task from DB.") logger.warning("Removing failed task from DB.")
# remove items from DB if task fails to add to apscheduler # remove items from DB if task fails to add to apscheduler
self.controller.management_helper.delete_scheduled_task(schedule.schedule_id) self.controller.management_helper.delete_scheduled_task(
schedule.schedule_id
)
else: else:
if schedule.interval_type == "hours": if schedule.interval_type == "hours":
self.scheduler.add_job( self.scheduler.add_job(
@ -270,7 +274,9 @@ class TasksManager:
], ],
) )
except Exception as e: except Exception as e:
self.helper.console.error(f"Failed to schedule task with error: {e}.") self.helper.console.error(
f"Failed to schedule task with error: {e}."
)
self.helper.console.warning("Removing failed task from DB.") self.helper.console.warning("Removing failed task from DB.")
logger.error(f"Failed to schedule task with error: {e}.") logger.error(f"Failed to schedule task with error: {e}.")
logger.warning("Removing failed task from DB.") logger.warning("Removing failed task from DB.")
@ -381,7 +387,9 @@ class TasksManager:
], ],
) )
except Exception as e: except Exception as e:
self.helper.console.error(f"Failed to schedule task with error: {e}.") self.helper.console.error(
f"Failed to schedule task with error: {e}."
)
self.helper.console.info("Removing failed task from DB.") self.helper.console.info("Removing failed task from DB.")
self.controller.management_helper.delete_scheduled_task(sch_id) self.controller.management_helper.delete_scheduled_task(sch_id)
else: else:
@ -511,7 +519,10 @@ class TasksManager:
logger.info("Scheduling Serverjars.com cache refresh service every 12 hours") logger.info("Scheduling Serverjars.com cache refresh service every 12 hours")
self.scheduler.add_job( self.scheduler.add_job(
self.controller.server_jars.refresh_cache, "interval", hours=12, id="serverjars" self.controller.server_jars.refresh_cache,
"interval",
hours=12,
id="serverjars",
) )
def realtime(self): def realtime(self):

View File

@ -9,7 +9,9 @@ logger = logging.getLogger(__name__)
class Translation: class Translation:
def __init__(self, helper): def __init__(self, helper):
self.helper = helper self.helper = helper
self.translations_path = os.path.join(self.helper.root_dir, "app", "translations") self.translations_path = os.path.join(
self.helper.root_dir, "app", "translations"
)
self.cached_translation = None self.cached_translation = None
self.cached_translation_lang = None self.cached_translation_lang = None

View File

@ -283,7 +283,9 @@ class AjaxHandler(BaseHandler):
if server_id is None: if server_id is None:
logger.warning("Server ID not found in send_command ajax call") logger.warning("Server ID not found in send_command ajax call")
self.helper.console.warning("Server ID not found in send_command ajax call") self.helper.console.warning(
"Server ID not found in send_command ajax call"
)
srv_obj = self.controller.get_server_obj(server_id) srv_obj = self.controller.get_server_obj(server_id)
@ -430,7 +432,11 @@ class AjaxHandler(BaseHandler):
self.helper.websocket_helper.broadcast_user( self.helper.websocket_helper.broadcast_user(
user_id, user_id,
"send_start_error", "send_start_error",
{"error": self.helper.translation.translate("error", "no-file", user_lang)}, {
"error": self.helper.translation.translate(
"error", "no-file", user_lang
)
},
) )
return return
@ -496,12 +502,15 @@ class AjaxHandler(BaseHandler):
) )
) or not Helpers.check_file_exists(os.path.abspath(file_path)): ) or not Helpers.check_file_exists(os.path.abspath(file_path)):
logger.warning(f"Invalid path in del_backup ajax call ({file_path})") logger.warning(f"Invalid path in del_backup ajax call ({file_path})")
self.helper.console.warning(f"Invalid path in del_backup ajax call ({file_path})") self.helper.console.warning(
f"Invalid path in del_backup ajax call ({file_path})"
)
return return
# Delete the file # Delete the file
if Helpers.validate_traversal( if Helpers.validate_traversal(
Helpers.get_os_understandable_path(server_info["backup_path"]), file_path Helpers.get_os_understandable_path(server_info["backup_path"]),
file_path,
): ):
os.remove(file_path) os.remove(file_path)

View File

@ -7,6 +7,7 @@ from app.classes.models.users import ApiKeys
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class BaseHandler(tornado.web.RequestHandler): class BaseHandler(tornado.web.RequestHandler):
nobleach = {bool, type(None)} nobleach = {bool, type(None)}

View File

@ -8,9 +8,10 @@ from app.classes.models.server_permissions import Enum_Permissions_Server
from app.classes.shared.helpers import Helpers from app.classes.shared.helpers import Helpers
from app.classes.shared.file_helpers import FileHelpers from app.classes.shared.file_helpers import FileHelpers
from app.classes.web.base_handler import BaseHandler from app.classes.web.base_handler import BaseHandler
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class FileHandler(BaseHandler): class FileHandler(BaseHandler):
def render_page(self, template, page_data): def render_page(self, template, page_data):
self.render( self.render(
@ -256,7 +257,9 @@ class FileHandler(BaseHandler):
self.get_body_argument("file_path", default=None, strip=True) self.get_body_argument("file_path", default=None, strip=True)
) )
self.helper.self.helper.console.warning(f"Delete {file_path} for server {server_id}") self.helper.self.helper.console.warning(
f"Delete {file_path} for server {server_id}"
)
if not self.check_server_id(server_id, "del_file"): if not self.check_server_id(server_id, "del_file"):
return return
@ -303,7 +306,9 @@ class FileHandler(BaseHandler):
Helpers.get_os_understandable_path(server_info["path"]), dir_path Helpers.get_os_understandable_path(server_info["path"]), dir_path
) or not Helpers.check_path_exists(os.path.abspath(dir_path)): ) or not Helpers.check_path_exists(os.path.abspath(dir_path)):
logger.warning(f"Invalid path in del_file file ajax call ({dir_path})") logger.warning(f"Invalid path in del_file file ajax call ({dir_path})")
self.helper.console.warning(f"Invalid path in del_file file ajax call ({dir_path})") self.helper.console.warning(
f"Invalid path in del_file file ajax call ({dir_path})"
)
return return
# Delete the directory # Delete the directory
@ -389,7 +394,9 @@ class FileHandler(BaseHandler):
if item_path is None or new_item_name is None: if item_path is None or new_item_name is None:
logger.warning("Invalid path(s) in rename_file file ajax call") logger.warning("Invalid path(s) in rename_file file ajax call")
self.helper.console.warning("Invalid path(s) in rename_file file ajax call") self.helper.console.warning(
"Invalid path(s) in rename_file file ajax call"
)
return return
if not Helpers.in_path( if not Helpers.in_path(
@ -465,7 +472,9 @@ class FileHandler(BaseHandler):
if item_path is None or new_item_name is None: if item_path is None or new_item_name is None:
logger.warning("Invalid path(s) in rename_file file ajax call") logger.warning("Invalid path(s) in rename_file file ajax call")
self.helper.console.warning("Invalid path(s) in rename_file file ajax call") self.helper.console.warning(
"Invalid path(s) in rename_file file ajax call"
)
return return
if not Helpers.in_path( if not Helpers.in_path(

View File

@ -335,7 +335,9 @@ class PanelHandler(BaseHandler):
template = "public/error.html" template = "public/error.html"
elif page == "credits": elif page == "credits":
with open(self.helper.credits_cache, encoding="utf-8") as credits_default_local: with open(
self.helper.credits_cache, encoding="utf-8"
) as credits_default_local:
try: try:
remote = requests.get( remote = requests.get(
"https://craftycontrol.com/credits", allow_redirects=True "https://craftycontrol.com/credits", allow_redirects=True
@ -1311,7 +1313,9 @@ class PanelHandler(BaseHandler):
): ):
server_obj.path = server_path server_obj.path = server_path
server_obj.log_path = log_path server_obj.log_path = log_path
if Helpers.validate_traversal(self.helper.get_servers_root_dir(), executable): if Helpers.validate_traversal(
self.helper.get_servers_root_dir(), executable
):
server_obj.executable = executable server_obj.executable = executable
server_obj.execution_command = execution_command server_obj.execution_command = execution_command
server_obj.server_ip = server_ip server_obj.server_ip = server_ip
@ -1889,7 +1893,9 @@ class PanelHandler(BaseHandler):
) )
self.write( self.write(
self.controller.authentication.generate(key.user_id.user_id, {"token_id": key.token_id}) self.controller.authentication.generate(
key.user_id.user_id, {"token_id": key.token_id}
)
) )
self.finish() self.finish()

View File

@ -19,7 +19,9 @@ class PublicHandler(BaseHandler):
if user_id is not None: if user_id is not None:
self.set_cookie( self.set_cookie(
"token", self.controller.authentication.generate(user_id), expires_days=int(expire_days) "token",
self.controller.authentication.generate(user_id),
expires_days=int(expire_days),
) )
else: else:
self.clear_cookie("token") self.clear_cookie("token")

View File

@ -203,7 +203,9 @@ class ServerHandler(BaseHandler):
os.path.join(self.helper.servers_dir, new_server_uuid) os.path.join(self.helper.servers_dir, new_server_uuid)
): ):
new_server_uuid = Helpers.create_uuid() new_server_uuid = Helpers.create_uuid()
new_server_path = os.path.join(self.helper.servers_dir, new_server_uuid) new_server_path = os.path.join(
self.helper.servers_dir, new_server_uuid
)
# copy the old server # copy the old server
FileHelpers.copy_dir(server_data.get("path"), new_server_path) FileHelpers.copy_dir(server_data.get("path"), new_server_path)

View File

@ -9,7 +9,9 @@ class StatusHandler(BaseHandler):
def get(self): def get(self):
page_data = {} page_data = {}
page_data["lang"] = self.helper.get_setting("language") page_data["lang"] = self.helper.get_setting("language")
page_data["lang_page"] = self.helper.getLangPage(self.helper.get_setting("language")) page_data["lang_page"] = self.helper.getLangPage(
self.helper.get_setting("language")
)
page_data["servers"] = self.controller.servers.get_all_servers_stats() page_data["servers"] = self.controller.servers.get_all_servers_stats()
running = 0 running = 0
for srv in page_data["servers"]: for srv in page_data["servers"]:

View File

@ -18,7 +18,11 @@ class UploadHandler(BaseHandler):
# noinspection PyAttributeOutsideInit # noinspection PyAttributeOutsideInit
def initialize( def initialize(
self, helper: Helpers = None, controller: Controller = None, tasks_manager=None, translator=None self,
helper: Helpers = None,
controller: Controller = None,
tasks_manager=None,
translator=None,
): ):
self.helper = helper self.helper = helper
self.controller = controller self.controller = controller

View File

@ -17,7 +17,9 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
translator = None translator = None
io_loop = None io_loop = None
def initialize(self, helper=None, controller=None, tasks_manager=None, translator=None): def initialize(
self, helper=None, controller=None, tasks_manager=None, translator=None
):
self.helper = helper self.helper = helper
self.controller = controller self.controller = controller
self.tasks_manager = tasks_manager self.tasks_manager = tasks_manager

View File

@ -106,8 +106,7 @@ if __name__ == "__main__":
# start the database # start the database
database = peewee.SqliteDatabase( database = peewee.SqliteDatabase(
helper.db_path, helper.db_path, pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
) )
database_proxy.initialize(database) database_proxy.initialize(database)