Skip to content

Commit

Permalink
allow no editor to be configured and not to load existing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinkens committed Jul 16, 2024
1 parent 1118be1 commit 809b423
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/backend/rule_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from src.config.config_manager import ConfigManager
from src.widgets.widget_base_tile import BaseTile
from src.logger import BroadErrorHandler

import logging
logger = logging.getLogger(__name__)
RuleConfig = Dict[str, List[str]]


Expand All @@ -20,9 +21,10 @@ def __init__(self):
def _loadRuleFile(self, filename_base):
if not self._loadedRules:
filename = f"{filename_base}.rules"
data_path = Path(ConfigManager.config()["data_path"])
data_path = ConfigManager.config()["data_path"]
if not data_path:
raise ValueError("No editor directory path known")
data_path = Path(data_path)

automapper_path = data_path.joinpath(Path("editor/automap"))
if not automapper_path.exists():
Expand All @@ -40,13 +42,17 @@ def _loadRuleFile(self, filename_base):
self._header = []
self._loadedRules = True

@BroadErrorHandler
@BroadErrorHandler(logger)
def loadRules(self, filename):
if not self._loadedRules:
filename = RuleManager._getFileBase(filename)
self._loadRuleFile(filename)
try:
self._loadRuleFile(filename)
except ValueError:
return False
return True

@BroadErrorHandler
@BroadErrorHandler(logger)
def saveRule(self, filename, rule_name):
filename = RuleManager._getFileBase(filename)
if not self._loadedRules:
Expand All @@ -57,7 +63,7 @@ def saveRule(self, filename, rule_name):

def getRules(self) -> List[str]:
if not self._loadedRules:
raise ValueError("Rules are not loaded yet")
return []
return list(self._config.keys())

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions src/config/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _checkConfig(self) -> bool:
return updated

def createConfig(self):
client_path = ""
data_path = ""
client_path = None
data_path = None
# noinspection PyBroadException
try:
client_path = StorageFinder.instance().getClientPath()
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/widget_mapper_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from src.config.config_manager import ConfigManager
from src.backend.map_generator import MapGenerator
from src.logger import BroadErrorHandler
import logging
logger = logging.getLogger(__name__)


class MapperGeneratorWidget(QWidget):
Expand Down Expand Up @@ -135,7 +137,7 @@ def ruleNameToggle(self):
self.existing_mapper.show()
self._updateGenerateButton()

@BroadErrorHandler
@BroadErrorHandler(logger)
def startDDNetCheck(self):
# TODO
# generate Map
Expand Down

0 comments on commit 809b423

Please sign in to comment.