mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Further fix files to conform with ⚫Black pylintrc
Mostly just breaking up strings and comments into new lines Some strings dont require 'f' but keeping in for readability with the rest of the concatinated string
This commit is contained in:
parent
2a512d7273
commit
09bba7fdb0
@ -417,7 +417,8 @@ class helpers_management:
|
|||||||
self.set_backup_config(server_id=server_id, excluded_dirs=excluded_dirs)
|
self.set_backup_config(server_id=server_id, excluded_dirs=excluded_dirs)
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Not adding {dir_to_add} to excluded directories - already in the excluded directory list for server ID {server_id}"
|
f"Not adding {dir_to_add} to excluded directories - "
|
||||||
|
f"already in the excluded directory list for server ID {server_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def del_excluded_backup_dir(self, server_id: int, dir_to_del: str):
|
def del_excluded_backup_dir(self, server_id: int, dir_to_del: str):
|
||||||
@ -428,7 +429,8 @@ class helpers_management:
|
|||||||
self.set_backup_config(server_id=server_id, excluded_dirs=excluded_dirs)
|
self.set_backup_config(server_id=server_id, excluded_dirs=excluded_dirs)
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Not removing {dir_to_del} from excluded directories - not in the excluded directory list for server ID {server_id}"
|
f"Not removing {dir_to_del} from excluded directories - "
|
||||||
|
f"not in the excluded directory list for server ID {server_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -297,7 +297,8 @@ class helper_users:
|
|||||||
else:
|
else:
|
||||||
user_id = user.user_id
|
user_id = user.user_id
|
||||||
|
|
||||||
# I just copied this code from get_user, it had those TODOs & comments made by mac - Lukas
|
# I just copied this code from get_user,
|
||||||
|
# it had those TODOs & comments made by mac - Lukas
|
||||||
|
|
||||||
roles_query = (
|
roles_query = (
|
||||||
User_Roles.select()
|
User_Roles.select()
|
||||||
|
@ -1,88 +1,92 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Translation:
|
class Translation:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.translations_path = os.path.join(helper.root_dir, "app", "translations")
|
self.translations_path = os.path.join(helper.root_dir, "app", "translations")
|
||||||
self.cached_translation = None
|
self.cached_translation = None
|
||||||
self.cached_translation_lang = None
|
self.cached_translation_lang = None
|
||||||
|
|
||||||
def get_language_file(self, language: str):
|
def get_language_file(self, language: str):
|
||||||
return os.path.join(self.translations_path, str(language) + ".json")
|
return os.path.join(self.translations_path, str(language) + ".json")
|
||||||
|
|
||||||
def translate(self, page, word, language):
|
def translate(self, page, word, language):
|
||||||
fallback_language = "en_EN"
|
fallback_language = "en_EN"
|
||||||
|
|
||||||
translated_word = self.translate_inner(page, word, language)
|
translated_word = self.translate_inner(page, word, language)
|
||||||
if translated_word is None:
|
if translated_word is None:
|
||||||
translated_word = self.translate_inner(page, word, fallback_language)
|
translated_word = self.translate_inner(page, word, fallback_language)
|
||||||
|
|
||||||
if translated_word:
|
if translated_word:
|
||||||
if isinstance(translated_word, dict):
|
if isinstance(translated_word, dict):
|
||||||
# JSON objects
|
# JSON objects
|
||||||
return json.dumps(translated_word)
|
return json.dumps(translated_word)
|
||||||
elif isinstance(translated_word, str):
|
elif isinstance(translated_word, str):
|
||||||
# Basic strings
|
# Basic strings
|
||||||
return translated_word
|
return translated_word
|
||||||
elif hasattr(translated_word, "__iter__"):
|
elif hasattr(translated_word, "__iter__"):
|
||||||
# Multiline strings
|
# Multiline strings
|
||||||
return "\n".join(translated_word)
|
return "\n".join(translated_word)
|
||||||
return "Error while getting translation"
|
return "Error while getting translation"
|
||||||
|
|
||||||
def translate_inner(self, page, word, language) -> t.Union[t.Any, None]:
|
def translate_inner(self, page, word, language) -> t.Union[t.Any, None]:
|
||||||
language_file = self.get_language_file(language)
|
language_file = self.get_language_file(language)
|
||||||
try:
|
try:
|
||||||
if not self.cached_translation:
|
if not self.cached_translation:
|
||||||
with open(language_file, "r", encoding="utf-8") as f:
|
with open(language_file, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
self.cached_translation = data
|
self.cached_translation = data
|
||||||
elif self.cached_translation_lang != language:
|
elif self.cached_translation_lang != language:
|
||||||
with open(language_file, "r", encoding="utf-8") as f:
|
with open(language_file, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
self.cached_translation = data
|
self.cached_translation = data
|
||||||
self.cached_translation_lang = language
|
self.cached_translation_lang = language
|
||||||
else:
|
else:
|
||||||
data = self.cached_translation
|
data = self.cached_translation
|
||||||
|
|
||||||
try:
|
try:
|
||||||
translated_page = data[page]
|
translated_page = data[page]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Translation File Error: page {page} does not exist for lang {language}"
|
f"Translation File Error: page {page} "
|
||||||
)
|
f"does not exist for lang {language}"
|
||||||
console.error(
|
)
|
||||||
f"Translation File Error: page {page} does not exist for lang {language}"
|
console.error(
|
||||||
)
|
f"Translation File Error: page {page} "
|
||||||
return None
|
f"does not exist for lang {language}"
|
||||||
|
)
|
||||||
try:
|
return None
|
||||||
translated_word = translated_page[word]
|
|
||||||
return translated_word
|
try:
|
||||||
except KeyError:
|
translated_word = translated_page[word]
|
||||||
logger.error(
|
return translated_word
|
||||||
f"Translation File Error: word {word} does not exist on page {page} for lang {language}"
|
except KeyError:
|
||||||
)
|
logger.error(
|
||||||
console.error(
|
f"Translation File Error: word {word} does not exist on page "
|
||||||
f"Translation File Error: word {word} does not exist on page {page} for lang {language}"
|
f"{page} for lang {language}"
|
||||||
)
|
)
|
||||||
return None
|
console.error(
|
||||||
|
f"Translation File Error: word {word} does not exist on page "
|
||||||
except Exception as e:
|
f"{page} for lang {language}"
|
||||||
logger.critical(
|
)
|
||||||
f"Translation File Error: Unable to read {language_file} due to {e}"
|
return None
|
||||||
)
|
|
||||||
console.critical(
|
except Exception as e:
|
||||||
f"Translation File Error: Unable to read {language_file} due to {e}"
|
logger.critical(
|
||||||
)
|
f"Translation File Error: Unable to read {language_file} due to {e}"
|
||||||
return None
|
)
|
||||||
|
console.critical(
|
||||||
|
f"Translation File Error: Unable to read {language_file} due to {e}"
|
||||||
translation = Translation()
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
translation = Translation()
|
||||||
|
20
main.py
20
main.py
@ -10,7 +10,8 @@ from app.classes.shared.helpers import helper
|
|||||||
|
|
||||||
if helper.checkRoot():
|
if helper.checkRoot():
|
||||||
console.critical(
|
console.critical(
|
||||||
"Root detected. Root/Admin access denied. Run Crafty again with non-elevated permissions."
|
"Root detected. Root/Admin access denied. "
|
||||||
|
"Run Crafty again with non-elevated permissions."
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
console.critical("Crafty shutting down. Root/Admin access denied.")
|
console.critical("Crafty shutting down. Root/Admin access denied.")
|
||||||
@ -103,8 +104,10 @@ if __name__ == "__main__":
|
|||||||
if fresh_install:
|
if fresh_install:
|
||||||
console.debug("Fresh install detected")
|
console.debug("Fresh install detected")
|
||||||
console.warning(
|
console.warning(
|
||||||
"We have detected a fresh install. Please be sure to forward Crafty's port, "
|
f"We have detected a fresh install. Please be sure to forward "
|
||||||
+ f"{helper.get_setting('https_port')}, through your router/firewall if you would like to be able to access Crafty remotely."
|
f"Crafty's port, {helper.get_setting('https_port')}, "
|
||||||
|
f"through your router/firewall if you would like to be able "
|
||||||
|
f"to access Crafty remotely."
|
||||||
)
|
)
|
||||||
installer.default_settings()
|
installer.default_settings()
|
||||||
else:
|
else:
|
||||||
@ -127,10 +130,12 @@ if __name__ == "__main__":
|
|||||||
# start stats logging
|
# start stats logging
|
||||||
tasks_manager.start_stats_recording()
|
tasks_manager.start_stats_recording()
|
||||||
|
|
||||||
# once the controller is up and stats are logging, we can kick off the scheduler officially
|
# once the controller is up and stats are logging, we can kick off
|
||||||
|
# the scheduler officially
|
||||||
tasks_manager.start_scheduler()
|
tasks_manager.start_scheduler()
|
||||||
|
|
||||||
# refresh our cache and schedule for every 12 hoursour cache refresh for serverjars.com
|
# refresh our cache and schedule for every 12 hoursour cache refresh
|
||||||
|
# for serverjars.com
|
||||||
tasks_manager.serverjar_cache_refresher()
|
tasks_manager.serverjar_cache_refresher()
|
||||||
|
|
||||||
logger.info("Checking Internet. This may take a minute.")
|
logger.info("Checking Internet. This may take a minute.")
|
||||||
@ -138,8 +143,9 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if not helper.check_internet():
|
if not helper.check_internet():
|
||||||
console.warning(
|
console.warning(
|
||||||
"We have detected the machine running Crafty has no connection to the internet. "
|
"We have detected the machine running Crafty has no "
|
||||||
+ "Client connections to the server may be limited."
|
"connection to the internet. Client connections to "
|
||||||
|
"the server may be limited."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not controller.check_system_user():
|
if not controller.check_system_user():
|
||||||
|
Loading…
Reference in New Issue
Block a user