Skip to content

Commit

Permalink
Use configparser correctly
Browse files Browse the repository at this point in the history
Misread the documentation, inheritance from the default section
should now work correctly
  • Loading branch information
TobleMiner committed Sep 7, 2020
1 parent a29e795 commit d459b7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ MulticastSiteAddress: ff05::2:1001
# Default domain to use
DefaultDomain: <domain code>
# Default domain type
DefaultDomainType: batadv
DomainType: batadv
# A domain
[<domain code>]
Expand Down Expand Up @@ -131,7 +131,7 @@ Port: 1001
MulticastLinkAddress: ff02::2:1001
MulticastSiteAddress: ff05::2:1001
# Default domain type
DefaultDomainType: batadv
DomainType: batadv
# IPv4 gateway option for ddhcpd
IPv4Gateway: 10.42.0.1
Expand Down Expand Up @@ -169,7 +169,7 @@ Port: 1001
MulticastLinkAddress: ff02::2:1001
MulticastSiteAddress: ff05::2:1001
# Default domain type
DefaultDomainType: batadv
DomainType: batadv
# First domain
[one]
Expand Down
22 changes: 7 additions & 15 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
class GlobalOptions():
''' Container class for global options
'''
def __init__(self, port, mcast_link, mcast_site, default_domain, default_domain_type, ipv4_gateway):
def __init__(self, port, default_domain):
self.port = port
self.mcast_link = mcast_link
self.mcast_site = mcast_site
self.default_domain = default_domain
self.default_domain_type = default_domain_type
self.ipv4_gateway = ipv4_gateway

class DomainOptions():
''' Base container class for per domain options
Expand All @@ -21,7 +17,7 @@ def from_parser(cls, section, parser, globals):
'''
from domain import DomainType

domain_type = parser.get(section, 'DomainType', fallback=globals.default_domain_type)
domain_type = parser.get(section, 'DomainType', fallback='simple')
# Get DomainOptions subclass for type and instantiate
return DomainType.get(domain_type.lower()).options(section, parser, globals)

Expand All @@ -32,9 +28,9 @@ def __init__(self, name, parser, globals):

self.name = name
self.interfaces = list(map(str.strip, parser.get(name, 'Interfaces', fallback='').split(',')))
self.mcast_link = parser.get(name, 'MulticastLinkAddress', fallback=globals.mcast_link)
self.mcast_site = parser.get(name, 'MulticastSiteAddress', fallback=globals.mcast_site)
self.ipv4_gateway = parser.get(name, 'IPv4Gateway', fallback=globals.ipv4_gateway)
self.mcast_link = parser.get(name, 'MulticastLinkAddress', fallback='ff02::2:1001')
self.mcast_site = parser.get(name, 'MulticastSiteAddress', fallback='ff05::2:1001')
self.ipv4_gateway = parser.get(name, 'IPv4Gateway', fallback=None)
self.domain_type = Domain

class BatmanDomainOptions(DomainOptions):
Expand Down Expand Up @@ -77,12 +73,8 @@ def _initialize_global_options(self, parser):
''' Set all global options
'''
self.globals = GlobalOptions(
parser.getint(None, 'Port', fallback=1001),
parser.get(None, 'MulticastLinkAddress', fallback='ff02::2:1001'),
parser.get(None, 'MulticastSiteAddress', fallback='ff05::2:1001'),
parser.get(None, 'DefaultDomain', fallback=None),
parser.get(None, 'DefaultDomainType', fallback='simple'),
parser.get(None, 'IPv4Gateway', fallback=None),
parser.getint('Defaults', 'Port', fallback=1001),
parser.get('Defaults', 'DefaultDomain', fallback=None)
)

def _initialize_domain_options(self, parser, domain):
Expand Down
4 changes: 2 additions & 2 deletions respondd.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MulticastSiteAddress: ff05::2:1001
DefaultDomain: ffki
# Default domain type
# optional
DefaultDomainType: batadv
DomainType: batadv
# Default ddhcpd IPv4 gateway address
# optional
IPv4Gateway: 10.116.128.8
Expand All @@ -24,7 +24,7 @@ IPv4Gateway: 10.116.128.8
# User your own domain name here
[ffki]
# This is a batman domain
# optional, mandatory if DefaultDomainType not set, default: @DefaultDomainType
# optional, mandatory if DomainType not set, default: @DomainType
# supported domain types are: simple, batadv
DomainType: batadv
# Batman interface
Expand Down

0 comments on commit d459b7c

Please sign in to comment.