blflashcommand/libs/bflb_configobj.py

54 lines
1.4 KiB
Python
Raw Normal View History

from libs.bflb_utils import printf
from configparser import ConfigParser
2023-04-20 18:45:21 +00:00
class ConfigObj:
cnf_infile = None
config = None
2023-04-20 18:45:21 +00:00
def __init__(self, file):
self.cfg_infile = file
self.config = ConfigParser()
self.config.read([file], 'UTF8')
2023-04-20 18:45:21 +00:00
def has_option(self, section, key):
return self.config.has_option(section, key)
2023-04-20 18:45:21 +00:00
def get(self, section, key):
return self.config.get(section, key)
2023-04-20 18:45:21 +00:00
def set(self, section, key, value):
return self.config.set(section, key, value)
2023-04-20 18:45:21 +00:00
class BFConfigParser:
cfg_infile = None
cfg_obj = None
2023-04-20 18:45:21 +00:00
def __init__(self, file=None):
self.cfg_infile = file
if file is not None:
self.cfg_obj = ConfigObj(self.cfg_infile)
2023-04-20 18:45:21 +00:00
def read(self, file=None):
printf('Reading configuration from file: %s' % file)
2023-04-20 18:45:21 +00:00
self.cfg_infile = file
if file is not None:
self.cfg_obj = ConfigObj(self.cfg_infile)
2023-04-20 18:45:21 +00:00
return self.cfg_obj
def has_option(self, section, key):
return self.cfg_obj.has_option(section, key)
2023-04-20 18:45:21 +00:00
def get(self, section, key):
ret = self.cfg_obj.get(section, key)
2023-04-20 18:45:21 +00:00
if ret == '""':
return ''
return ret
def set(self, section, key, value):
self.cfg_obj.set(section, key, str(value))
2023-04-20 18:45:21 +00:00
def write(self, file, mode):
pass # why would the flasher want to write the config file back?