Skip to content

Commit

Permalink
fine tune ini parsing and writing
Browse files Browse the repository at this point in the history
  • Loading branch information
tappi287 committed May 2, 2021
1 parent 021876f commit 8f0b7ee
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions rf2settings/rfactor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
import sys
from configparser import ConfigParser
from pathlib import Path, WindowsPath
import subprocess
Expand Down Expand Up @@ -61,7 +60,10 @@ def get_location(cls, dev: Optional[bool] = False):

class RfactorPlayer:
resolution_key = 'resolution_settings'
config_parser_args = {'inline_comment_prefixes': '//', 'default_section': 'COMPONENTS'}
config_parser_args = {'inline_comment_prefixes': ('//', ),
'comment_prefixes': ('#', ';', '//'),
'default_section': 'COMPONENTS',
}

class Options:
def __init__(self):
Expand Down Expand Up @@ -217,7 +219,7 @@ def _write_video_config(self, preset: BasePreset):
try:
# - Write config
with open(self.ini_file, 'w') as f:
self.ini_config.write(f)
self.ini_config.write(f, space_around_delimiters=False)

# - Restore first ini comment line
with open(self.ini_file, 'r') as f:
Expand All @@ -230,10 +232,6 @@ def _write_video_config(self, preset: BasePreset):
# - Remove trailing new line character
f_lines[-1] = f_lines[-1].rstrip('\n')

# - Remove spaced assign
for idx, line in enumerate(f_lines):
f_lines[idx] = line.replace(' = ', '=')

# - Write modified config
with open(self.ini_file, 'w') as f:
f.writelines(f_lines)
Expand Down Expand Up @@ -468,7 +466,7 @@ def run_config(self) -> bool:
return False

executable = self.location / "Bin64" / "rF Config.exe"
p = subprocess.Popen(executable, cwd=self.location, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
p = subprocess.Popen(executable.as_posix(), cwd=self.location, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
stdin=subprocess.PIPE)
out, errs = p.communicate()
if p.returncode != 0:
Expand Down

0 comments on commit 8f0b7ee

Please sign in to comment.