Skip to content

Commit

Permalink
Fixes to TOML and minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Nov 18, 2023
1 parent fbe7743 commit 5d11ca2
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 906 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tests/*/__pycache__/
temp/
/notebooks
/logs/*
/src/joystick_diagrams/logs*

# IDE
*.code-workspace
Expand Down
2 changes: 1 addition & 1 deletion config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NoBindText = No Bind
[Logging]
EnableLogging = 1
# 1 = Minimum, 3 = Full Debug
LogLevel = 1
LogLevel = 3

[BROWSER]
OpenTemplatesInBrowser = 0
Expand Down
884 changes: 77 additions & 807 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ authors = ["Robert Cox"]

[tool.poetry.dependencies]
python = "^3.11"
PyQt5 = "^5.15.6"
PyQt5 = "^5.15.10"
ply = "^3.11"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
pytest-qt = "^4.0.2"
pytest-cov = "^3.0.0"
black = "^21.10b0"
pytest = "^7.2.0"
pytest-qt = "^4.2.0"
pytest-cov = "^4.0.0"
black = "^23.0.0"
pre-commit = "^2.15.0"
coveralls = "^3.3.0"
pylint = "^2.11.1"
cx-Freeze = "^6.8.0"
ipykernel = "^6.5.0"
pylint = "^3.0.0"
cx-Freeze = "^6.15.0"

[tool.poetry.scripts]
build-exe = "build:setup"
Expand Down Expand Up @@ -49,7 +48,7 @@ exclude_lines = [

[tool.black]
line-length = 120
target-version = ['py37']
target-version = ['py311']
include = '\.pyi?$'
exclude = '''
(
Expand Down
53 changes: 31 additions & 22 deletions src/joystick_diagrams/adaptors/dcs_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import re
from pathlib import Path
import logging
from shutil import ExecError
from ply import lex, yacc
#import joystick_diagrams.adaptors.dcs_world_lex # pylint: disable=unused-import
#import joystick_diagrams.adaptors.dcs_world_parse # pylint: disable=unused-import

import joystick_diagrams.adaptors.dcs_world_lex # pylint: disable=unused-import
import joystick_diagrams.adaptors.dcs_world_yacc # pylint: disable=unused-import
import joystick_diagrams.adaptors.joystick_diagram_interface as jdi

_logger = logging.getLogger(__name__)

EASY_MODES = "_easy"


class DCSWorldParser(jdi.JDinterface):
def __init__(self, path, easy_modes=True):
jdi.JDinterface.__init__(self)
Expand All @@ -27,7 +28,7 @@ def __init__(self, path, easy_modes=True):
self.profile_devices = None
self.fq_path = None

def __validate_base_directory(self):
def __validate_base_directory(self) -> list:
"""validate the base directory structure, make sure there are files."""
if "Config" in os.listdir(self.path):
try:
Expand All @@ -37,21 +38,21 @@ def __validate_base_directory(self):
else:
raise FileNotFoundError("DCS: No Config Folder found in DCS Folder.")

def __validate_profiles(self):
def __validate_profiles(self) -> list:
"""
Validate Profiles Routine
"""
if len(self.base_directory) > 0:
valid_items = []
for item in self.base_directory:
valid = self.__validate_profile(item)
if valid:
valid_items.append(item)
else:
_logger.info("DCS: Profile {} has no joystick directory files".format(item))
else:
if len(self.base_directory) == 0:
raise FileExistsError("DCS: No profiles exist in Input directory!")

valid_items = list()
for item in self.base_directory:
valid = self.__validate_profile(item)
if valid:
valid_items.append(item)
else:
_logger.info("DCS: Profile {} has no joystick directory files".format(item))

return valid_items

def __validate_profile(self, item):
Expand Down Expand Up @@ -83,7 +84,6 @@ def convert_button_format(self, button) -> str:
split = button.split("_")

match len(split):

case 2:
if len(split) == 2:
if split[1][0:3] == "BTN":
Expand All @@ -96,15 +96,20 @@ def convert_button_format(self, button) -> str:
return split[1]
## Add default case / better handling
case 4:
return "{button}_{pov}_{dir}".format(button=split[1].replace("BTN", "POV"), pov=split[2][3], dir=split[3])
return "{button}_{pov}_{dir}".format(
button=split[1].replace("BTN", "POV"), pov=split[2][3], dir=split[3]
)

def process_profiles(self, profile_list=None) -> dict:
def process_profiles(self, profile_list: list = None) -> dict:
if isinstance(profile_list, list) and len(profile_list) > 0:
self.profiles_to_process = profile_list
else:
self.profiles_to_process = self.get_validated_profiles()

assert len(self.profiles_to_process) != 0, "DCS: There are no valid profiles to process"
assert (
len(self.profiles_to_process) != 0
), "DCS: There are no valid profiles to process" ## Replace with exception type

for profile in self.profiles_to_process:
self.fq_path = os.path.join(self.path, "Config", "Input", profile, "joystick")
self.profile_devices = os.listdir(os.path.join(self.fq_path))
Expand All @@ -113,12 +118,16 @@ def process_profiles(self, profile_list=None) -> dict:
self.joystick_listing.update({item[:-48]: item})
for joystick_device, joystick_file in self.joystick_listing.items():
if os.path.isdir(os.path.join(self.fq_path, joystick_file)):
print("Skipping as Folder")
_logger.info("Skipping as Folder")
else:
try:
self.file = Path(os.path.join(self.fq_path, joystick_file)).read_text(encoding="utf-8")
self.file = self.file.replace("local diff = ", "") ## CLEAN UP
self.file = self.file.replace("return diff", "") ## CLEAN UP
self.file = (
Path(os.path.join(self.fq_path, joystick_file))
.read_text(encoding="utf-8")
.replace("local diff = ", "")
.replace("return diff", "")
)

except FileNotFoundError:
raise FileExistsError(
"DCS: File {} no longer found - It has been moved/deleted from directory".format(
Expand Down
41 changes: 33 additions & 8 deletions src/joystick_diagrams/adaptors/dcs_world_lex.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
# dcs_world_lex.py. This file automatically created by PLY (version 3.11). Don't edit!
_tabversion = '3.10'
_lextokens = set(('COMMA', 'DOUBLE_VAL', 'EQUALS', 'FALSE', 'LBRACE', 'LCURLY', 'NUMBER', 'RBRACE', 'RCURLY', 'STRING', 'TRUE'))
_lexreflags = 96
_lexliterals = ''
_lexstateinfo = {'INITIAL': 'inclusive'}
_lexstatere = {'INITIAL': [('(?P<t_DOUBLE_VAL>(\\+|\\-)?[0-9]+\\.[0-9]+)|(?P<t_NUMBER>[0-9]+)|(?P<t_STRING>\\"[\\w|\\/|\\(|\\)|\\-|\\:|\\+|\\,|\\&|\\.|\\\'|\\<|\\>|\\s]+\\" )|(?P<t_TRUE>(true))|(?P<t_FALSE>(false))|(?P<t_LCURLY>\\{)|(?P<t_RCURLY>\\})|(?P<t_LBRACE>\\[)|(?P<t_RBRACE>\\])|(?P<t_COMMA>\\,)|(?P<t_EQUALS>\\=)', [None, ('t_DOUBLE_VAL', 'DOUBLE_VAL'), None, ('t_NUMBER', 'NUMBER'), ('t_STRING', 'STRING'), ('t_TRUE', 'TRUE'), None, ('t_FALSE', 'FALSE'), None, (None, 'LCURLY'), (None, 'RCURLY'), (None, 'LBRACE'), (None, 'RBRACE'), (None, 'COMMA'), (None, 'EQUALS')])]}
_lexstateignore = {'INITIAL': ' \t\n'}
_lexstateerrorf = {'INITIAL': 't_error'}
_tabversion = "3.10"
_lextokens = set(
("COMMA", "DOUBLE_VAL", "EQUALS", "FALSE", "LBRACE", "LCURLY", "NUMBER", "RBRACE", "RCURLY", "STRING", "TRUE")
)
_lexreflags = 96
_lexliterals = ""
_lexstateinfo = {"INITIAL": "inclusive"}
_lexstatere = {
"INITIAL": [
(
'(?P<t_DOUBLE_VAL>(\\+|\\-)?[0-9]+\\.[0-9]+)|(?P<t_NUMBER>[0-9]+)|(?P<t_STRING>\\"[\\w|\\/|\\(|\\)|\\-|\\:|\\+|\\,|\\&|\\.|\\\'|\\<|\\>|\\s]+\\" )|(?P<t_TRUE>(true))|(?P<t_FALSE>(false))|(?P<t_LCURLY>\\{)|(?P<t_RCURLY>\\})|(?P<t_LBRACE>\\[)|(?P<t_RBRACE>\\])|(?P<t_COMMA>\\,)|(?P<t_EQUALS>\\=)',
[
None,
("t_DOUBLE_VAL", "DOUBLE_VAL"),
None,
("t_NUMBER", "NUMBER"),
("t_STRING", "STRING"),
("t_TRUE", "TRUE"),
None,
("t_FALSE", "FALSE"),
None,
(None, "LCURLY"),
(None, "RCURLY"),
(None, "LBRACE"),
(None, "RBRACE"),
(None, "COMMA"),
(None, "EQUALS"),
],
)
]
}
_lexstateignore = {"INITIAL": " \t\n"}
_lexstateerrorf = {"INITIAL": "t_error"}
_lexstateeoff = {}
Loading

0 comments on commit 5d11ca2

Please sign in to comment.