configparser: strip double quotes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import configparser
|
||||
from configparser import ConfigParser
|
||||
import datetime
|
||||
import glob
|
||||
import os
|
||||
@@ -16,11 +16,20 @@ THISRUN = os.path.expanduser('~/BirdNET-Pi/scripts/thisrun.txt')
|
||||
ANALYZING_NOW = os.path.expanduser('~/BirdNET-Pi/analyzing_now.txt')
|
||||
|
||||
|
||||
class PHPConfigParser(ConfigParser):
|
||||
def get(self, section, option, *, raw=False, vars=None, fallback=None):
|
||||
value = super().get(section, option, raw=raw, vars=vars, fallback=fallback)
|
||||
if raw:
|
||||
return value
|
||||
else:
|
||||
return value.strip('"')
|
||||
|
||||
|
||||
def _load_settings(settings_path='/etc/birdnet/birdnet.conf', force_reload=False):
|
||||
global _settings
|
||||
if _settings is None or force_reload:
|
||||
with open(settings_path) as f:
|
||||
parser = configparser.ConfigParser()
|
||||
parser = PHPConfigParser()
|
||||
# preserve case
|
||||
parser.optionxform = lambda option: option
|
||||
lines = chain(("[top]",), f)
|
||||
@@ -37,8 +46,8 @@ def get_settings(settings_path='/etc/birdnet/birdnet.conf', force_reload=False):
|
||||
def write_settings(file_name=THISRUN):
|
||||
settings = _load_settings()
|
||||
with open(file_name, 'w') as configfile:
|
||||
for key, value in settings.items():
|
||||
configfile.write(f'{key}={value}\n')
|
||||
for key in settings.keys():
|
||||
configfile.write(f'{key}={settings.get(key, raw=True)}\n')
|
||||
os.chmod(file_name, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user