Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
79d027d
Build(deps): Bump requests from 2.32.3 to 2.32.4 in /scripts (#112)
dependabot[bot] Dec 5, 2025
da57d6b
Ommit unused variable
HugoCLSC Dec 5, 2025
0ad16a1
Removed unused method
HugoCLSC Dec 5, 2025
fc58cc5
Remove unused imports
HugoCLSC Dec 5, 2025
0ac9933
Remove unused import, f-string without placeholders
HugoCLSC Dec 5, 2025
a43c0fa
Remove unused import
HugoCLSC Dec 5, 2025
f3bcf5e
Removed unused module
HugoCLSC Dec 5, 2025
e89e1c8
Removed f-string without placeholder
HugoCLSC Dec 5, 2025
f3c5327
Removed unused code on method
HugoCLSC Dec 5, 2025
2d31103
Removed placeholder file for new module
HugoCLSC Dec 5, 2025
294b91e
Removed assigned variable but never used
HugoCLSC Dec 5, 2025
824e689
Removed unused import
HugoCLSC Dec 5, 2025
ab290a1
Comment unused variable
HugoCLSC Dec 5, 2025
3721762
Removed unused code line
HugoCLSC Dec 5, 2025
9164414
Removed unused file
HugoCLSC Dec 5, 2025
59a5e97
Explicity re-raise with from
HugoCLSC Dec 5, 2025
4fe0e36
Removed unused code line
HugoCLSC Dec 5, 2025
2aff6e0
Refactor text box painting
HugoCLSC Dec 5, 2025
597c5fe
Removed unused import
HugoCLSC Dec 5, 2025
1e0d721
Removed unused code line
HugoCLSC Dec 5, 2025
4b67480
Removed unused module
HugoCLSC Dec 5, 2025
d0bbefe
Removed unused module placeholder
HugoCLSC Dec 5, 2025
cdc796c
Added docstrings
HugoCLSC Dec 5, 2025
5c3b6a8
Add docstrings to methods
HugoCLSC Dec 5, 2025
e7dd806
Add docstring to methods and class
HugoCLSC Dec 5, 2025
d9f3ed9
Add docstring to methods
HugoCLSC Dec 5, 2025
a18084d
Removed unused module
HugoCLSC Dec 5, 2025
dcbe2f8
Added docstrings
HugoCLSC Dec 5, 2025
4114d05
Added docstrings
HugoCLSC Dec 5, 2025
b5463ce
Added docstrings, deleted commented code
HugoCLSC Dec 5, 2025
5576e04
Added docstrings, deleted commented code
HugoCLSC Dec 5, 2025
04b38af
Added docstrings, deleted commented code
HugoCLSC Dec 5, 2025
e0059b1
Added docstrings, deleted commented code
HugoCLSC Dec 5, 2025
6d0e850
deleted commented code
HugoCLSC Dec 5, 2025
9b247bb
Added docstrings, deleted commented code
HugoCLSC Dec 5, 2025
7cf0152
Deleted code from unused window
HugoCLSC Dec 5, 2025
201a371
Added docstring to methods, deleted unused code
HugoCLSC Dec 5, 2025
242a862
Added docstring to methods, deleted unused code
HugoCLSC Dec 5, 2025
599259d
Add docsctring, delete commented code
HugoCLSC Dec 9, 2025
f54052b
Add docsctring
HugoCLSC Dec 9, 2025
d55f0d3
Add docsctring, delete unused code
HugoCLSC Dec 9, 2025
918bd1b
Add docstring, change method name
HugoCLSC Dec 9, 2025
fd1dd3f
Add docstring, change method name, delete unused code
HugoCLSC Dec 9, 2025
74215c4
Add docstring, delete unused code
HugoCLSC Dec 9, 2025
3370850
Add docstring, delete unused code, changed method name
HugoCLSC Dec 9, 2025
79eb3b9
Add docstring, changed method name
HugoCLSC Dec 9, 2025
aa32bc4
Add docstring, changed method name
HugoCLSC Dec 9, 2025
35846f0
Add docstring, changed method name
HugoCLSC Dec 9, 2025
b75050f
Add docstring, changed method name
HugoCLSC Dec 9, 2025
9063196
Add docstring, changed method name
HugoCLSC Dec 9, 2025
1c658d2
Formatting
HugoCLSC Dec 9, 2025
042bb26
Add docstring
HugoCLSC Dec 9, 2025
f9fe821
Add docstring, delete unused code, changed method name
HugoCLSC Dec 9, 2025
be39dde
Add docstring, delete unused code, changed method name
HugoCLSC Dec 9, 2025
dfade4f
Add docstring, changed method name
HugoCLSC Dec 9, 2025
3e07ecf
Add docstring, changed method name
HugoCLSC Dec 9, 2025
a952f1b
Add docstring, delete commented code, change method name
HugoCLSC Dec 9, 2025
1227592
Add docstring, delete commented code, change method name
HugoCLSC Dec 9, 2025
8bc628d
Let troubleshoot page decide where it wants to go
HugoCLSC Dec 9, 2025
88ef464
Add docstring, change method name
HugoCLSC Dec 9, 2025
c905b58
Add docstring, delete unused and untested code
HugoCLSC Dec 9, 2025
0430d9b
Add docstring
HugoCLSC Dec 9, 2025
2c034fe
Add docstring
HugoCLSC Dec 9, 2025
df29a99
Add docstring, delete unused code
HugoCLSC Dec 9, 2025
4daa850
Add docstring
HugoCLSC Dec 9, 2025
32a5a31
Add docstring
HugoCLSC Dec 9, 2025
4646f92
Add docstring
HugoCLSC Dec 9, 2025
4e373e7
Add docstring
HugoCLSC Dec 9, 2025
e93c381
Add docstring
HugoCLSC Dec 9, 2025
841afba
Add docstrings
HugoCLSC Dec 9, 2025
df99ae8
Add docstring, change method name
HugoCLSC Dec 9, 2025
8fb9e0b
Add docstring
HugoCLSC Dec 9, 2025
1cfa314
Add docstring, delete unused code
HugoCLSC Dec 9, 2025
1837e06
Add docstring, delete unused code
HugoCLSC Dec 9, 2025
a31cff0
Add docstring
HugoCLSC Dec 9, 2025
5df2a12
Change list item docstring
HugoCLSC Dec 9, 2025
8e92ead
Add docstring
HugoCLSC Dec 9, 2025
a3c8fe9
Add docstring
HugoCLSC Dec 9, 2025
0190bbc
Deleted unused module
HugoCLSC Dec 9, 2025
2cd5da1
Add docstring
HugoCLSC Dec 9, 2025
4ca7649
Deleted unused method
HugoCLSC Dec 9, 2025
232cd13
Merge branch 'dev' into refactor/tests-compliance
HugoCLSC Dec 9, 2025
9985fc8
Deleted unused code line
HugoCLSC Dec 9, 2025
bd2e4ab
Delete unused code line
HugoCLSC Dec 10, 2025
65ac6b2
Delete unused code line
HugoCLSC Dec 10, 2025
82b78e2
Security patch subprocess shell = True, security issue
HugoCLSC Dec 10, 2025
7a5951d
Remove argument from method
HugoCLSC Dec 10, 2025
772349c
Ruff formatting
HugoCLSC Dec 10, 2025
d04d975
Ruff formatting
HugoCLSC Dec 10, 2025
af4a690
Surpress Reviewed security issues
HugoCLSC Dec 10, 2025
78abe4b
Formatting
HugoCLSC Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions BlocksScreen/BlocksScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
RESET = "\033[0m"


def setup_working_dir(): ...


def setup_app_loggers():
ql = logger.create_logger(name="logs/BlocksScreen.log", level=logging.DEBUG)
"""Setup logger"""
_ = logger.create_logger(name="logs/BlocksScreen.log", level=logging.DEBUG)
_logger = logging.getLogger(name="logs/BlocksScreen.log")
_logger.info("============ BlocksScreen Initializing ============")


def show_splash(window: typing.Optional[QtWidgets.QWidget] = None):
"""Show splash screen on app initialization"""
logo = QtGui.QPixmap("BlocksScreen/BlocksScreen/lib/ui/resources/logoblocks.png")
splash = QtWidgets.QSplashScreen(pixmap=logo)
splash.setGeometry(QtCore.QRect(0, 0, 400, 200))
Expand Down
134 changes: 88 additions & 46 deletions BlocksScreen/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@


class Sentinel(enum.Enum):
"""Sentinel value to signify missing condition, absence of value"""

MISSING = object


class ConfigError(Exception):
"""Exception raised when Configfile errors exist"""

def __init__(self, msg) -> None:
super().__init__(msg)
self.msg = msg
Expand All @@ -59,24 +63,10 @@ def __init__(self, msg) -> None:
class BlocksScreenConfig:
config = configparser.ConfigParser(
allow_no_value=True,
# interpolation=configparser.ExtendedInterpolation(),
# delimiters=(":"),
# inline_comment_prefixes=("#"),
# comment_prefixes=("#", "#~#"),
# empty_lines_in_values=True,
)

update_pending: bool = False

_instance = None

# def __new__(
# cls, *args, **kwargs
# ) -> BlocksScreenConfig: # Singleton pattern
# if not cls._instance:
# cls._instance = super(BlocksScreenConfig, cls).__new__(cls)
# return cls._instance

def __init__(
self, configfile: typing.Union[str, pathlib.Path], section: str
) -> None:
Expand All @@ -93,24 +83,41 @@ def __contains__(self, key):
return key in self.config

def sections(self) -> typing.List[str]:
"""Returns list of all sections"""
return self.config.sections()

def get_section(
self, section: str, fallback: typing.Optional[T] = None
) -> BlocksScreenConfig:
"""Get configfile section"""
if not self.config.has_section(section):
raise configparser.NoSectionError(
f"No section with name: {section}"
)
raise configparser.NoSectionError(f"No section with name: {section}")
return BlocksScreenConfig(self.configfile, section)

def get_options(self) -> list:
"""Get section options"""
return self.config.options(self.section)

def has_section(self, section: str) -> bool:
"""Check if config file has a section

Args:
section (str): section name

Returns:
bool: true if section exists, false otherwise
"""
return bool(self.config.has_section(section))

def has_option(self, option: str) -> bool:
"""Check if section has a option

Args:
option (str): option name

Returns:
bool: true if section exists, false otherwise
"""
return bool(self.config.has_option(self.section, option))

def get(
Expand All @@ -119,26 +126,50 @@ def get(
parser: type = str,
default: typing.Union[Sentinel, str, T] = Sentinel.MISSING,
) -> typing.Union[Sentinel, str]:
"""Get option value

Args:
option (str): option name
parser (type, optional): bool, float, int. Defaults to str.
default (typing.Union[Sentinel, str, T], optional): Default value for specified option. Defaults to Sentinel.MISSING.

Returns:
typing.Union[Sentinel, str]: Requested option. Defaults to the specified default value
"""
return parser(
self.config.get(
section=self.section, option=option, fallback=default
)
self.config.get(section=self.section, option=option, fallback=default)
)

def getint(
self,
option: str,
default: typing.Union[Sentinel, int] = Sentinel.MISSING,
) -> typing.Union[Sentinel, int]:
return self.config.getint(
section=self.section, option=option, fallback=default
)
"""Get option value

Args:
option (str): option name
default (typing.Union[Sentinel, int], optional): Default value for specified option. Defaults to Sentinel.MISSING.

Returns:
typing.Union[Sentinel, int]: Requested option.
"""
return self.config.getint(section=self.section, option=option, fallback=default)

def getfloat(
self,
option: str,
default: typing.Union[Sentinel, float] = Sentinel.MISSING,
) -> typing.Union[Sentinel, float]:
"""Get the value for the specified option

Args:
option (str): option name
default (typing.Union[Sentinel, float], optional): Default value for specified option. Defaults to Sentinel.MISSING.

Returns:
typing.Union[Sentinel, float]: _description_
"""
return self.config.getfloat(
section=self.section, option=option, fallback=default
)
Expand All @@ -148,6 +179,15 @@ def getboolean(
option: str,
default: typing.Union[Sentinel, bool] = Sentinel.MISSING,
) -> typing.Union[Sentinel, bool]:
"""Get option value

Args:
option (str): option name
default (typing.Union[Sentinel, bool], optional): Default value for specified option. Defaults to Sentinel.MISSING.

Returns:
typing.Union[Sentinel, bool]: _description_
"""
return self.config.getboolean(
section=self.section, option=option, fallback=default
)
Expand All @@ -156,9 +196,7 @@ def _find_section_index(self, section: str) -> int:
try:
return self.raw_config.index("[" + section + "]")
except ValueError as e:
raise configparser.Error(
f'Section "{section}" does not exist: {e}'
)
raise configparser.Error(f'Section "{section}" does not exist: {e}')

def _find_section_limits(self, section: str) -> typing.Tuple:
try:
Expand Down Expand Up @@ -189,6 +227,14 @@ def _find_option_index(
)

def add_section(self, section: str) -> None:
"""Add a section to configuration file

Args:
section (str): section name

Raises:
configparser.DuplicateSectionError: Exception thrown when section is duplicated
"""
try:
with self.file_lock:
sec_string = f"[{section}]"
Expand All @@ -209,16 +255,21 @@ def add_section(self, section: str) -> None:
except configparser.DuplicateSectionError as e:
logging.error(f'Section "{section}" already exists. {e}')
except configparser.Error as e:
logging.error(
f'Unable to add "{section}" section to configuration: {e}'
)
logging.error(f'Unable to add "{section}" section to configuration: {e}')

def add_option(
self,
section: str,
option: str,
value: typing.Union[str, None] = None,
) -> None:
"""Add option with a value to a section

Args:
section (str): section name
option (str): option name
value (typing.Union[str, None], optional): value for the specified option. Defaults to None.
"""
try:
with self.file_lock:
section_start, section_end = self._find_section_limits(section)
Expand All @@ -239,13 +290,12 @@ def add_option(
)

def save_configuration(self) -> None:
"""Save teh configuration to file"""
try:
if not self.update_pending:
return
with self.file_lock:
self.configfile.write_text(
"\n".join(self.raw_config), encoding="utf-8"
)
self.configfile.write_text("\n".join(self.raw_config), encoding="utf-8")
sio = io.StringIO()
sio.writelines(self.raw_config)
self.config.write(sio)
Expand All @@ -257,13 +307,8 @@ def save_configuration(self) -> None:
finally:
self.update_pending = False

def _do_save(self, data) -> bool:
try:
return True
except Exception as e:
return False

def load_config(self):
"""Load configuration file"""
try:
self.raw_config.clear()
self.config.clear() # Reset configparser
Expand Down Expand Up @@ -330,20 +375,17 @@ def _parse_file(self) -> typing.Tuple[typing.List[str], typing.Dict]:


def get_configparser() -> BlocksScreenConfig:
"""Loads configuration from file and returns that configuration"""
wanted_target = os.path.join(DEFAULT_CONFIGFILE_PATH, "BlocksScreen.cfg")
fallback = os.path.join(WORKING_DIR, "BlocksScreen.cfg")
configfile = (
wanted_target
if check_file_on_path(DEFAULT_CONFIGFILE_PATH, "BlocksScreen.cfg")
else fallback
)
try:
config_object = BlocksScreenConfig(
configfile=configfile, section="server"
)
config_object.load_config()
if not config_object.has_section("server"):
raise ConfigError("Section [server] is missing from configuration")
except ConfigError:
config_object = BlocksScreenConfig(configfile=configfile, section="server")
config_object.load_config()
if not config_object.has_section("server"):
logging.error("Error loading configuration file for the application.")
raise ConfigError("Section [server] is missing from configuration")
return BlocksScreenConfig(configfile=configfile, section="server")
Loading
Loading