when no cfg file is there, create it
This commit is contained in:
10
cfg/linse-box2_5b2a64.cfg
Normal file
10
cfg/linse-box2_5b2a64.cfg
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[NETWORK]
|
||||||
|
; please refer to README.md for help
|
||||||
|
eth0=wan
|
||||||
|
eth1=192.168.2.2
|
||||||
|
eth2=192.168.3.3
|
||||||
|
eth3=192.168.127.254
|
||||||
|
|
||||||
|
[ROUTER]
|
||||||
|
; please refer to README.md for help
|
||||||
|
3001=192.168.127.254:3001
|
@ -475,6 +475,8 @@ def handle_config():
|
|||||||
cfgfile = BoxInfo.CFGPATH % (newhostname, box.id)
|
cfgfile = BoxInfo.CFGPATH % (newhostname, box.id)
|
||||||
with open(cfgfile, 'w') as f:
|
with open(cfgfile, 'w') as f:
|
||||||
f.write(template)
|
f.write(template)
|
||||||
|
config = box.read_config()
|
||||||
|
cfgfile = box.cfgfile
|
||||||
if box.hostname_changed or cfgfile != BoxInfo.CFGPATH % (newhostname, box.id):
|
if box.hostname_changed or cfgfile != BoxInfo.CFGPATH % (newhostname, box.id):
|
||||||
box.hostname_changed = True
|
box.hostname_changed = True
|
||||||
if cfgfile:
|
if cfgfile:
|
||||||
|
8
utils.py
8
utils.py
@ -56,10 +56,14 @@ class BoxInfo:
|
|||||||
|
|
||||||
def read_config(self, section=None):
|
def read_config(self, section=None):
|
||||||
cfgfiles = glob(self.CFGPATH % ('*', self.id))
|
cfgfiles = glob(self.CFGPATH % ('*', self.id))
|
||||||
if len(cfgfiles) != 1:
|
if len(cfgfiles) > 1:
|
||||||
raise ValueError('there must be one and only one single cfgfile %r' % cfgfiles)
|
raise ValueError('ambiguous cfgfile: %r' % cfgfiles)
|
||||||
|
if section and not cfgfiles:
|
||||||
|
raise ValueError('no cfg file found for %s' % self.id)
|
||||||
if cfgfiles:
|
if cfgfiles:
|
||||||
self.cfgfile = cfgfiles[0]
|
self.cfgfile = cfgfiles[0]
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read(self.cfgfile)
|
parser.read(self.cfgfile)
|
||||||
if section:
|
if section:
|
||||||
|
Reference in New Issue
Block a user