Skip to content

Commit

Permalink
Fix config file bugs making file and sections required (#13)
Browse files Browse the repository at this point in the history
Config file is not actually optional
    #11
  Tail section not existing in config file causes crash
    #12
  • Loading branch information
MadReasonable authored Jul 29, 2024
1 parent 53f8408 commit ff4e36d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions 42fdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class Config():
drefDefines:List[str] = []

def __init__(self, cliArgs:argparse.Namespace):
configFile = self.findConfigFile(cliArgs.config)
self.file = configparser.RawConfigParser()
self.file.read(configFile)
configFile = self.findConfigFile(cliArgs.config)
if configFile:
self.file.read(configFile)

defaults = self.file['Defaults'] if 'Defaults' in self.file else {}

Expand Down Expand Up @@ -68,22 +69,22 @@ def acftByTail(self, tailNumber:str):
return section

def tail(self, tailNumber:str):
tailConfig = {}
for section in self.file.sections():
if section.lower() == tailNumber.lower():
tailSection = self.file[section]

tailConfig = {}
for key in self.file[section]:
tailConfig[key] = numberOrString(tailSection[key])
break

if 'headingtrim' not in tailConfig:
tailConfig['headingtrim'] = 0
if 'pitchtrim' not in tailConfig:
tailConfig['pitchtrim'] = 0
if 'rolltrim' not in tailConfig:
tailConfig['rolltrim'] = 0
if 'headingtrim' not in tailConfig:
tailConfig['headingtrim'] = 0
if 'pitchtrim' not in tailConfig:
tailConfig['pitchtrim'] = 0
if 'rolltrim' not in tailConfig:
tailConfig['rolltrim'] = 0

return tailConfig
return tailConfig

def findConfigFile(self, cliPath:str):
if cliPath:
Expand Down

0 comments on commit ff4e36d

Please sign in to comment.